没有图片增加默认图片,有图片路径,但是没有图片文件解决方案

  • 内容
  • 评论
  • 相关
<?php
//没有图片增加默认图片,有图片路径,但是没有图片文件解决方案
$imgurl="https://www.wlphp.com/content/templates/FLY/img/1logo.png";
$imgurl="http://www.xsydcyydy.com/UpLoadFiles/shopStore/Logo/2016/12/shopStoreLogo20161226112348505013.jpg";
$imgurl="http://www.xsydcyydy.com/Content/images/logo.png";
$imgurl="";
print_r(get_file_header_info($imgurl));
        
//业务层        
if(get_file_header_info($imgurl)['download_content_length']!="-1" && get_file_header_info($imgurl)['download_content_length']!="0"){
    echo "有图片";
}else {
   echo "无图片";
}

//函数
function get_file_header_info($url) {  
        $curl = curl_init();  
        curl_setopt($curl, CURLOPT_URL, $url); //设置URL  
        curl_setopt($curl, CURLOPT_HEADER, 1); //获取Header  
        curl_setopt($curl, CURLOPT_NOBODY, true); //Body就不要了吧,我们只是需要Head  
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //数据存到成字符串吧,别给我直接输出到屏幕了  
        $data = curl_exec($curl); //开始执行啦~  
        $return = curl_getinfo($curl); //我知道HTTPSTAT码哦~  
        curl_close($curl); //用完记得关掉他  
        return $return;  
}



返回的结果1:

Array
(
    [url] => https://www.wlphp.com/content/templates/FLY/img/1logo.png
    [content_type] => text/html; charset=iso-8859-1
    [http_code] => 404
    [header_size] => 165
    [request_size] => 88
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.277952
    [namelookup_time] => 0.034191
    [connect_time] => 0.058239
    [pretransfer_time] => 0.25233
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => -1
    [upload_content_length] => 0
    [starttransfer_time] => 0.277896
    [redirect_time] => 0
    [certinfo] => Array
        (
        )

    [primary_ip] => 47.94.158.11
    [redirect_url] =>
)
无图片


返回结果2:

Array
(
    [url] => https://www.wlphp.com/content/templates/FLY/img/logo.png
    [content_type] => image/png
    [http_code] => 200
    [header_size] => 255
    [request_size] => 87
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.25494
    [namelookup_time] => 0.006586
    [connect_time] => 0.031986
    [pretransfer_time] => 0.228346
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => 2716
    [upload_content_length] => 0
    [starttransfer_time] => 0.254905
    [redirect_time] => 0
    [certinfo] => Array
        (
        )

    [primary_ip] => 47.94.158.11
    [redirect_url] =>
)
有图片


注意:

download_content_length 没有图片文件的时候,有的时候是-1,有的时候是0。

http_code不准确,不能作为参考。


 

本文标签:

版权声明:若无特殊注明,本文皆为《菜鸟站长》原创,转载请保留文章出处。

本文链接:没有图片增加默认图片,有图片路径,但是没有图片文件解决方案 - http://wlphp.com/?post=179

发表评论

电子邮件地址不会被公开。 必填项已用*标注