我一直试图在目录中找到一个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]; ?>" />这将正确地显示图像。
,谁来帮帮我,
发布于 2012-07-09 09:55:23
您正在将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];
}发布于 2012-07-09 09:16:18
file_exists使用文件系统路径,而不是URL。在浏览器中使用URL通过网络浏览器和web服务器访问PHP脚本。PHP脚本本身可以访问本地文件系统,并使用它,它不会通过网络堆栈访问文件。
所以使用类似于file_exists('C:\\foo\\bar\\dropbox\\lib\\admin\\' ...)的东西。
发布于 2012-07-09 09:16:55
file_exists不支持使用HTTP的地址(您可以看到这一点,因为stat不包含在HTTP支持的包装器列表中)。正如file_exists文档所述,远程文件可以使用一些包装器(如FTP )进行检查,但在HTTP上是不可能的,因此file_exists总是返回false。
假设这个文件位于本地机器上(这是由localhost建议的),您将需要使用本地文件路径访问它。很难猜测这对您来说可能是什么,但它可能看起来像/var/www/dropbox...。
https://stackoverflow.com/questions/11392074
复制相似问题