我一直在尝试开发代码,检查另一个网站上是否存在PDF文件。为了测试目的,我在网上找到了一个随机的PDF文件:
http://www.tutorialspoint.com/php/php_tutorial.pdf
我将尝试以下代码,但两种方法都无法正常工作:方法一:
$path1 = 'http://www.tutorialspoint.com/php/php_tutorial.pdf';
if (file_exists($path1))
{
echo "found!";
}
else
{
echo "not found";
}
//RESULT: not found
方法二:
function UR_exists($url){
$headers=get_headers($url);
return stripos($headers[0],"200 OK")?true:false;
}
if(UR_exists('http://www.tutorialspoint.com/php/php_tutorial.pdf'))
echo "This page exists";
else
echo "This page does not exist";
//RESULT: This page does not exist
页面在两种情况下都能正常执行,但结果总是文件不存在,我知道它存在。我做错了什么?