search
HomeBackend DevelopmentPHP ProblemHow to save php network pictures to local

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;
    }
}

Call:

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

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!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function