简体   繁体   中英

Write big file from web into local directory with CURLOPT_BUFFERSIZE

There is a big iso file on the web from which i want to write it into my local directory with CURLOPT_BUFFERSIZE as 102400 bytes,so i wrote the following code to do the job.

<?php
$url="http://gensho.acc.umu.se/debian-cd/8.0.0/i386/iso-cd/debian-8.0.0-i386-lxde-CD-1.iso";
$ch=curl_init();
$a_opt=array(
            CURLOPT_URL => $url,
            CURLOPT_HEADER => 0,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_BINARYTRANSFER => 1,
            CURLOPT_BUFFERSIZE => 102400
        );
curl_setopt_array($ch,$a_opt);
$str=curl_exec($ch);
$f=fopen('/tmp/debian.iso','w');
fwrite($f,$str)
?>

Maybe there are some bugs in it,but no error ouput,i can't download the target iso file,how to fix it?

Try to set TIMEOUT and CONNECTTIMEOUT options. Try to debug you code using var_dump($str) ; and

curl_error($ch);

Reading of How to partially download a remote file with cURL? might be useful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM