PHP判断一个文件是否能够被打开

<?php

// 需求:因为系统涉及大量的文档知识库,用户可以在线进行查看。为了验证文档是否正常打开。先需要从数据库取出路径和文件名,判断是否可以从对应的路径下打开文件。
header("Content-Type: text/html; charset=utf8");
$con = mysql_connect("数据库地址","用户名","密码");
if (!$con)
{
echo 'Could not connect: ' . mysql_error();
}
else{

mysql_select_db("数据库", $con);//输入选择的数据库
mysql_query("set names utf8");
$pathone=mysql_query("select Path,Name from file");
echo mysql_num_rows($pathone);
while($tmpRow = mysql_fetch_array($pathone))
{

$url = "https://www.test.com/test/".$tmpRow['fPath']."/".$tmpRow['fName'];
$headers = @get_headers($url);
if($headers[0] == 'HTTP/1.1 404 Not Found')
{
echo "URL not Exists".$url.'</br>';
}
else
{
echo "URL Exists".'</br>';
}
}
}
mysql_close($con);


?>

原文地址:https://www.cnblogs.com/benpao1314/p/7865988.html