php 检查文件是否与url一起存在

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 检查文件是否与url一起存在相关的知识,希望对你有一定的参考价值。

/** https://stackoverflow.com/questions/1363925/check-whether-image-exists-on-remote-url
**/

function checkRemoteFile($url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    // don't download content
    curl_setopt($ch, CURLOPT_NOBODY, 1);
    curl_setopt($ch, CURLOPT_FAILONERROR, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    $result = curl_exec($ch);
    curl_close($ch);
    if($result !== FALSE)
    {
        return true;
    }
    else
    {
        return false;
    }
}

以上是关于php 检查文件是否与url一起存在的主要内容,如果未能解决你的问题,请参考以下文章

Ajax 如何与 PHP 一起工作?

如何通过 PHP 检查 URL 是不是存在?

Android 使用其 URL 检查文件是不是存在于远程服务器中

Nginx try_files配置重定向检查旧URL?

如果 URL 已存在于数据库中,如何使用 PHP 检查?

无法在 php 中检查 file_exist 的外部 url [重复]