您的位置:首页 > 编程语言 > PHP开发

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

2017-11-20 14:02 190 查看
<?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);

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: