How to save php network pictures to local

爱喝马黛茶的安东尼
Release: 2023-02-25 07:28:01
Original
4188 people have browsed it

How to save php network pictures to local

PHP Get network pictures and save them in a local directory Ideas:

Related recommendations: "php Getting Started Tutorial"

Code As follows:

function file_exists_S3($url)
{
    $state = @file_get_contents($url,0,null,0,1);//获取网络资源的字符内容
    if($state){
        $filename = date("dMYHis").'.jpg';//文件名称生成
        ob_start();//打开输出
        readfile($url);//输出图片文件
        $img = ob_get_contents();//得到浏览器输出
        ob_end_clean();//清除输出并关闭
        $size = strlen($img);//得到图片大小
        $fp2 = @fopen($filename, "a");
        fwrite($fp2, $img);//向当前目录写入图片文件,并重新命名
        fclose($fp2);
        return 1;
    }
    else{
        return 0;
    }
}
Copy after login

Call:

var_dump(file_exists_S3('http://images2015.cnblogs.com/blog/1156899/201705/1156899-20170518182731010-1445627236.png'));
Copy after login

The above is the detailed content of How to save php network pictures to local. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!