[英]function file_exists not working in php
我一直在尝试查找目录中是否存在file_exist。 如果不是,我想使用其他图像。 但是当我使用file_exists函数时,它总是返回false。
我使用的代码是
while($r=mysql_fetch_row($res))
{
if(!file_exists('http://localhost/dropbox/lib/admin/'.$r[5]))
{
$file='http://localhost/dropbox/lib/admin/images/noimage.gif';
}
else
$file='http://localhost/dropbox/lib/admin/'.$r[5];}
但是,即使文件退出,该函数也始终返回false。 我通过使用
<img src="<?php echo 'http://localhost/dropbox/lib/admin/'.$r[5]; ?>" />
这样可以正确显示图像。
请有人帮我
file_exists
使用文件系统路径 ,而不是URL。 您可以在浏览器中使用URL来通过网络上的Web浏览器和Web服务器访问PHP脚本。 尽管PHP脚本本身可以访问本地文件系统并使用它,但它不会通过网络堆栈来访问文件。
因此,请使用诸如file_exists('C:\\\\foo\\\\bar\\\\dropbox\\\\lib\\\\admin\\\\' ...)
。
file_exists
不支持使用HTTP的地址(您可以看到此信息,因为stat
不包括在HTTP支持的包装器列表中 )。 如file_exists
文档所述,可以使用某些包装程序(例如FTP)检查远程文件,但是无法通过HTTP进行检查,因此file_exists
将始终返回false。
假设此文件位于本地计算机上(这是localhost
建议的,则需要使用本地文件路径进行访问。很难猜测这可能对您有什么用,但看起来像/var/www/dropbox...
file_exists()
检查本地文件系统中是否存在文件。 您正在传递一个URL。 将其更改为您的保管箱目录的本地路径,它应该可以工作:
if(file_exists('/path/to/your/dropbox'))
函数file_exists
仅可用于PHP中stat()
函数支持的URL协议。
当前,此包装器不支持http
协议。
您正在将URL传递给file_exists函数,这是错误的参数。 而不是通过您的本地路径。
要了解有关file_exist()函数的更多信息,请阅读此php手册:
您正在将URL传递给file_exists函数,这是错误的。 而不是传递文件夹的本地路径。
while($r=mysql_fetch_row($res))
{
if(!file_exists('/dropbox/lib/admin/'.$r[5]))
{
$file='/dropbox/lib/admin/images/noimage.gif';
}
else
$file='/dropbox/lib/admin/'.$r[5];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.