doudouba4520 2014-08-24 08:29
浏览 87

php函数file_get_contents()只获取几KB的远程文件

Hello i want to download remote zip, which is about 8 MB big. I wrote simple script

set_time_limit(0);
$zip = file_get_contents('http://web.tld/folder/download/getfile.do?filename=file.zip&_lang=Lang');
file_put_contents('zip_files/file.zip',$zip);

it works but stored file is not 8 MB but only 52 KB.

Its same if i use

set_time_limit(0);

$url  = 'http://web.tld/folder/download/getfile.do?filename=file.zip&_lang=Lang';
$path = 'zip_files/file.zip';

/* get and save remote data without exceeding php memory limit */
$fp = fopen($path, 'w');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
$data = curl_exec($ch);
curl_close($ch);
fclose($fp);

so maybe i have to use some stream option ?! Thank you

ps: i tried Snoopy library (http://sourceforge.net/projects/snoopy/) and its also same, only 52KB :P

include "libs/Snoopy-2.0/Snoopy.class.php";
$snoopy = new Snoopy;

$snoopy->submit($url);
print $snoopy->results;
  • 写回答

1条回答 默认 最新

  • doutu4335 2014-08-24 08:33
    关注

    Look inside saved file (use any text editor) it's possible to see not zip, just a page with wrong URL or something.

    评论

报告相同问题?

悬赏问题

  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题