【问题标题】:PHP, need help using cURL as allow_url_fopen is disabledPHP,使用 cURL 需要帮助,因为 allow_url_fopen 已禁用
【发布时间】:2012-01-30 22:39:26
【问题描述】:

我需要一些帮助。我对 cURL 很陌生。我得到了一个可以从 wordpress 博客(使用 magpie 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));

?>

【问题讨论】:

    标签: php curl feed image-resizing


    【解决方案1】:

    下载图像文件到本地机器,然后在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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-22
      • 2014-08-24
      • 2015-07-13
      • 2012-06-03
      • 1970-01-01
      • 2015-11-11
      • 2011-05-31
      相关资源
      最近更新 更多