Php 如何对当前文件夹之外的目录使用file_exists函数?

Php 如何对当前文件夹之外的目录使用file_exists函数?,php,Php,我正在尝试使用当前文件目录之外的目录的file\u exists检查图像文件(.jpg)是否存在 文件系统图 Image Directory Websites -> GetaShoe -> 190 -> Image file websites/WEBSITE1/190/123.jpg Current Directory Websites -> Shoesgb -> current directory websites/WEBSITE2/currentpage.p

我正在尝试使用当前文件目录之外的目录的
file\u exists
检查图像文件(.jpg)是否存在

文件系统图

Image Directory
Websites -> GetaShoe -> 190 -> Image file 
websites/WEBSITE1/190/123.jpg

Current Directory
Websites -> Shoesgb -> current directory
websites/WEBSITE2/currentpage.php
那么,当使用当前目录中的
file\u exists
时,如何检查映像目录中是否存在文件

我尝试了以下方法:

<?php

     $filename = '/GetAShoe/190/123.jpg';

     if (file_exists($filename)) { echo 'Found'; } else { echo 'Not Found'; }

?>

这不起作用,因为在包含1000个图像的目录中根本找不到图像

是否有人能就引用外部文件路径的正确方式提供建议


谢谢

尝试使用映像目录的相对路径名<代码>/从计算机根目录开始。正如Marc所说:
。/GetAShoe
可能会起作用。

解决方案是使用绝对文件路径,我使用
\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu

因此,正确的路径是:

<?php 

$filename = "/root/26/987654321/htdocs/websites/WEBSITE/190/$info[product_id].jpg"; 

if (file_exists($filename)) { echo 'Found'; } else { echo 'Not Found'; }

?>


注意:由于安全原因,实际文件路径已被更改,上面提供的路径仅用于说明目的

/GetAShoe
正在寻找与
C:\GetAShoe
等效的代码。您可能想要更像
。/GetAShoe
。PHP对站点的文档根不了解,也不关心站点的文档根。它只看到服务器的文件系统。/在linux系统上是根文件夹,./是当前文件夹,./是当前文件夹上方的一个文件夹。您应该使用完整路径(/home/user/www/somedir/190/123.jpg)或相对根,如@MarcBposted@JimL-感谢您提供有关完整路径的提示。@通常首选aphextwix相对路径。我建议试着检查DIR(echo或dump),看看您是否在您认为您所在的DIR中。您可能需要访问两个目录,而不是一个目录。