【问题标题】:How to check image exists on another server or not? [duplicate]如何检查图像是否存在于另一台服务器上? [复制]
【发布时间】:2015-02-16 22:52:24
【问题描述】:

我将如何检查具有给定路径的特定图像是否存在于另一台服务器上?我有以下代码,其中我使用了文件获取内容,但这需要很长时间,因此有时 jquery 会停止工作。

function is_file_url_exists($url) 
{
    if (@file_get_contents($url, 0, NULL, 0, 1)) 
    {
        return 1;
    }
    return 0;           
}

【问题讨论】:

    标签: php


    【解决方案1】:

    为什么不使用 php bbuiltin 函数 file_exists?

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

    或者你也可以使用:

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

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

    【讨论】:

    • 这适用于检查同一台服务器..我认为这不适用于不同的服务器..
    • 你为什么这么认为,TECHNOMAN?
    • 因为我测试了你的代码但没有运行..
    • 此外,此页面上给出的解决方案也不起作用。stackoverflow.com/questions/2280394/… ....它总是给出值 1
    猜你喜欢
    • 2015-04-14
    • 2013-04-30
    • 1970-01-01
    • 2013-08-05
    • 2013-09-21
    • 1970-01-01
    • 2012-03-05
    • 1970-01-01
    • 2014-06-27
    相关资源
    最近更新 更多