How to download images to local in PHP?
阿神
阿神 2017-06-21 10:10:36
0
3
863

The result of this question on Baidu seems to be one and then copied and pasted in various ways
Upload the image to the server

function dlfile($file_url, $save_to)
{
    $in=    fopen($file_url, "rb");
    $out=   fopen($save_to, "wb");
    while ($chunk = fread($in,8192))
    {
        fwrite($out, $chunk, 8192);
    }
    fclose($in);
    fclose($out);
}
阿神
阿神

闭关修行中......

reply all(3)
三叔

It can be simpler like this

$url = "http://xxxxx";
$save_file = "xxx.xx";
file_put_contents($save_file, file_get_contents($url));
大家讲道理

I just happened to write an article: /a/11...

刘奇

fopen or file_get_contents are simple, but they do not support many features, such as connection timeout and other operations. In actual operation, the script may block for a long time until the PHP timeout setting is reached. If the concurrency is high, it may even bring down the server. Currently, curl is basically used instead

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template