Home > Backend Development > PHP Tutorial > How to save network images in php (code)

How to save network images in php (code)

不言
Release: 2023-04-03 20:54:01
Original
8413 people have browsed it

The content of this article is about how to save network images (code) in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

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

Note: $filename can be rewritten to the path you need

Related recommendations:

Code implementation of vertical merging & horizontal merging of two-dimensional arrays in php

Solution to float to int distortion in PHP

The above is the detailed content of How to save network images in php (code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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