donte1234567 2010-01-27 22:17
浏览 90
已采纳

cURL没有正确下载图像

I'm having a problem with cURL. I am downloading images and saving them to a folder. The file that cURL creates has the right filesize, which makes me think that the headers are being read properly. But, when I open the file up in my browser or in any picture-viewing application, only a tiny bit at the top appears to actually have been written. My code:

function _vancore_curl_savefile($url) {
  $url = str_replace("\"", "", $url);
  $basename = basename($url);
  $basename = str_replace("%20", "_", $basename);
  $var = file_directory_path() . "/van/" . $basename;
  $uvar = "files/van/" . $basename;
  $handle = fopen($var, "w");
  $curl = curl_init($url);
  curl_setopt($curl, CURLOPT_FILE, $handle);
  $result = curl_exec($curl);
  $result2 = $result;
  curl_close($curl);
  fclose($handle);
  return $uvar;
}

file_directory_path() is a Drupal function (this function is part of a Drupal module and called for each file that needs to be downloaded) that returns the path to the Drupal file download directory. I have confirmed through various tests that:

a) $url is what it should be
b) fopen() is opening the right file
c) curl_exec() is returning true after it is executed

I am very confused about what is going wrong here. Anyone have any thoughts?

TIA,
Benjy

  • 写回答

4条回答 默认 最新

  • dragon7713 2010-01-28 19:55
    关注

    You don't happen to be using the curl library "emulation" in the Drupal curl module. Are you? That doesn't always work. Make sure you have the real PHP curl library installed.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘