php - 如何从url检查文件是否存在

标签 php file curl fsockopen file-exists

我需要检查远程服务器上是否存在特定文件。使用 is_file()file_exists() 不起作用。有什么想法可以快速轻松地做到这一点吗?

最佳答案

您不需要 CURL... 只是想检查文件是否存在的开销太大...

使用 PHP's get_header .

$headers=get_headers($url);

然后检查 $result[0] 是否包含 200 OK(这意味着文件在那里)

一个检查 URL 是否有效的函数可能是这样的:

function UR_exists($url){
   $headers=get_headers($url);
   return stripos($headers[0],"200 OK")?true:false;
}

/* You can test a URL like this (sample) */
if(UR_exists("http://www.amazingjokes.com/"))
   echo "This page exists";
else
   echo "This page does not exist";

关于php - 如何从url检查文件是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7684771/

相关文章:

php - 在 PHP 中仅连接一次 MySQL

javascript - jquery验证后的ajax请求

.htaccess - curl:提供apache .htaccess文件的用户名和密码

python - 使用Python获取DNS解析时间和响应时间

php - 无法在 CentOS 7 上安装 phpMyAdmin

php - mysql_connect 超时

C++ 简单条件记录

perl - 使用简单文件实现锁

file - Visio 坐标格式

phpcurl 获取代理