cURL未正确下载图像 [英] cURL not properly downloading images

查看:114
本文介绍了cURL未正确下载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到cURL的问题。我正在下载图像并将其保存到文件夹。 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()是一个Drupal函数(此函数是Drupal模块的一部分,并为每个需要下载的文件调用) Drupal文件下载目录的路径我通过各种测试确认:

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 应该是什么

b) fopen()打开正确的文件

c) curl_exec 在执行后会返回 true

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

错在这里。

推荐答案

TIA,

Benjy

解决方案

你不会在Drupal curl模块中使用curl库仿真。你是?这不总是工作。确保您已安装了真正的PHP curl库。

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.

这篇关于cURL未正确下载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆