PHP-文件_不存在';即使目录中存在文件,也无法工作
我正在尝试验证目录中是否存在该文件。当我使用此代码时,它起作用-显示图像:PHP-文件_不存在';即使目录中存在文件,也无法工作,php,file,find,file-exists,Php,File,Find,File Exists,我正在尝试验证目录中是否存在该文件。当我使用此代码时,它起作用-显示图像: <?php $imgId=0; $filename='../uploadedimages/project-'.$item->id.'-'.$imgId; echo "<img src='".$filename."' ></img>"; ?> 当我将相同的代码与file_exists函数一起使用时,它不起作用: <?php $imgId
<?php
$imgId=0;
$filename='../uploadedimages/project-'.$item->id.'-'.$imgId;
echo "<img src='".$filename."' ></img>";
?>
当我将相同的代码与file_exists函数一起使用时,它不起作用:
<?php
$imgId=0;
$filename='../uploadedimages/project-'.$item->id.'-'.$imgId;
if (file_exists($filename)) {
echo "<img src='".$filename."' ></img>";
}
?>
我的问题很简单:WTF???你可以使用:
$\u服务器['DOCUMENT\u ROOT']
来知道你在哪里
然后试着这样做:
$filename=$_SERVER['DOCUMENT_ROOT'].'uploadedimages/project-'.$item->id.'-'.$imgId;
但首先需要确保路径存在。在linux服务器上,尝试将文件访问权限更改为755,然后再使用文件存在功能
chmod 755 filename.ext您的documentroot与服务器documentroot不同。。。因此
file\u exists()
使用脚本所在的文件夹作为参考目录。加载
会从您的Web服务器的根目录引用它。文件\u存在需要文件系统路径。旁注:
您不需要该路径。对于服务器来说,计算相对路径也是一件痛苦的事情(请阅读“WTF”手册;)<代码>$filename='/var/user/you/httpdocs/uploadedimages/project…