2012-01-30 69 views
0

我需要一些幫助。我非常喜歡cURL。我得到了一個腳本,可以從wordpress博客(使用magpie XML解析器)創建一個feed。我還有一個圖像調整大小腳本來爲我調整圖像大小。它在本地工作,但因爲我的虛擬主機有allow_url_fopen()禁用我已被告知我需要使用cURL,但我不能得到任何工作。PHP,需要幫助使用cURL allow_url_fopen被禁用

這裏的代碼之前,我試圖讓捲曲工作:

<?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)); 

?> 

回答

0

下載映像文件下載到本地機器,然後用它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);