簡體   English   中英

PHP,需要使用cURL的幫助,因為allow_url_fopen已禁用

[英]PHP, need help using cURL as allow_url_fopen is disabled

我需要協助。 我剛接觸cURL。 我得到了一個腳本,該腳本可以從wordpress博客(使用喜p XML解析器)創建供稿。 我也有一個圖像調整大小腳本來為我調整圖像大小。 它可以在本地運行,但是因為我的網絡托管已禁用allow_url_fopen(),所以我被告知我需要使用cURL,但是我什么都無法工作。

這是我嘗試使cURL工作之前的代碼:

<?php


$url = $_GET['imagesrc'];


// Set a maximum height and width
$width = 200;
$height = 200;

// Content type


// Get new dimensions
list($width_orig, $height_orig) = getimagesize($url);

$ratio_orig = $width_orig/$height_orig;

if ($width/$height > $ratio_orig) {
   $width = $height*$ratio_orig;
} else {
   $height = $width/$ratio_orig;
}

// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($url);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

// Output
header('Content-Type: image/jpeg');
return(imagejpeg($image_p, null, 100));

?>

將圖像文件下載到本地計算機,然后在imagecreatefromjpeg($filePointer);使用它imagecreatefromjpeg($filePointer); 下載文件的代碼如下。

/**
 * Initialize the cURL session
 */
 $ch = curl_init();

 /**
 * Set the URL of the page or file to download.
 */
 curl_setopt($ch, CURLOPT_URL, ‘your_URL’);

 /**
 * Create a new file
 */
 $fp = fopen(‘img.jpg’, ‘w’);

 /**
 * Ask cURL to write the contents to a file
 */
 curl_setopt($ch, CURLOPT_FILE, $fp);

 /**
 * Execute the cURL session
 */
 curl_exec ($ch);

 /**
 * Close cURL session and file
 */
 curl_close ($ch);
 fclose($fp);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM