doubi8383 2014-12-18 07:59
浏览 12

如何检查图像是否存在于另一台服务器上? [重复]

This question already has an answer here:

How i will check that a particular image with given path exists on another server or not? I have the following code in which i used file get contents but that is taking so long time and due to that sometimes jquery stops working.

function is_file_url_exists($url) 
{
    if (@file_get_contents($url, 0, NULL, 0, 1)) 
    {
        return 1;
    }
    return 0;           
}
</div>
  • 写回答

1条回答 默认 最新

  • down100009 2014-12-18 08:03
    关注

    Why dont you use php bbuiltin function file_exists?

    if (file_exists($url)) {   
       return 1;                     
    }
    else
       return 0;
    

    Or You can also use:

    $file = 'http://www.domain.com/somefile.jpg';
    $file_headers = @get_headers($file);
    if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
       $exists = false;
    }
    else {
       $exists = true;
    }
    

    Source: http://php.net/manual/en/function.file-exists.php

    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大