Home  >  Article  >  php教程  >  getimagesize

getimagesize

WBOY
WBOYOriginal
2016-06-06 20:08:53891browse

看到这个标题,你是不是会觉得很无聊?事实上,我是想表达另外的意思。从php5.2开始,很多操作都是支持streamwrapper的功能的,所以当有一个需求:从网上下载一张图片,存到本地,并使用正确的后缀名,就需要用到getimagesize了。 $data = file_get_contents

 看到这个标题,你是不是会觉得很无聊?事实上,我是想表达另外的意思。从php5.2开始,很多操作都是支持streamwrapper的功能的,所以当有一个需求:从网上下载一张图片,存到本地,并使用正确的后缀名,就需要用到getimagesize了。

    $data = file_get_contents($url);  
    file_put_contents('xxx',$data);  
    $imageinfo = getimagesize(xxx);  
    $extension = func($imageinfo); //获取文件属性  
    rename('xxx','xxx.???');  

以前的逻辑可以是这样。但现在可以简化一下

    $data  = file_get_contents($url);  
    $imageinfo = getimagesize('data:image/;base64,'.base64_encode($data));  
    $extension = func($imageinfo); //获取文件属性  
    file_put_contents('xxx.'.$extension , $data);  
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