用php检查exist文件

用php检查exist文件,php,yii2,Php,Yii2,我想用php或yii2检查exist文件 filesize和is\u文件和file\u存在不工作 filesize错误是:filesize():stat失败,原因是…… 是文件并且文件_存在返回false 这是我的代码: $fileI = $urlBase . "$home/../siteImage/$logo"; $fileI是: http://localhost/iicitySite/web/index.php/../siteImage/parvaz.png $home是: $hom

我想用php或yii2检查exist文件

filesize
is\u文件
file\u存在
不工作

filesize
错误是:
filesize():stat失败,原因是……

是文件
并且
文件_存在
返回false

这是我的代码:

 $fileI = $urlBase . "$home/../siteImage/$logo";
$fileI是:

http://localhost/iicitySite/web/index.php/../siteImage/parvaz.png
$home是:

 $home -> /iicitySite/web/index.php
这是视图中的正确图像:

      echo "



        <div class='col-lg-12 col-xs-12 col-sm-12 col-md-12 forsatItem'>
            <div class='backItem'>
                <div class='rightM col-lg-4'>
                    <div class='imgForsat'>
                        <img src='$home/../siteImage/$logo' alt=''/>
                    </div>
echo”
。 . .
.

我已经检查并验证了以下代码,它工作正常

$filename = '/path/to/foo.txt';

if (file_exists($filename)) {
    echo "The file $filename exists";
} else {
    echo "The file $filename does not exist";
}
如果您无法执行此操作,请使用您的权限解决此问题。请尝试检查桌面或其他允许的目录中的文件

希望这有帮助。

试试这个

$url = 'http://www.example.com';//or file path
$headers = get_headers($url, 1);
print_r($headers);//$headers[0] u will get the status

来源:

在路径中,不需要index.php,只需要路径

您可以使用此选项获取绝对(包括http在内的整个url)url:

如果要使用相对(相对于当前路径)路径,则可以使用以下选项:

 echo Url::to('@web/siteImage/parvaz.png', true);images/logo.png
 // http://codematrics.com/web/siteImage/parvaz.png

如果要检查服务器中是否存在文件,只需给出绝对路径,我将使用\Yii::getAlias(“@webroot”)获取绝对路径,并从控制器执行此操作

这是我进入网络浏览器的结果

绝对路径:/home/hostinguser/public_html/files/temppdf/benja.pdf 文件/home/hostinguser/public_html/files/temppdf/benja.pdf存在

        $pathFile = \Yii::getAlias('@webroot') .'/files/temppdf/' . 'benja.pdf'; 
        echo "<br>Absolute Path:" . $pathFile;
        if (file_exists($pathFile)) {
            echo "<br>The File $pathFile Exists";
        } else {
            echo "<br>The File $pathFile Do Not Exist";
        }
$pathFile=\Yii::getAlias('@webroot')。/files/tempfd/'.'benja.pdf';
echo“
绝对路径:”.$pathFile; 如果(文件_存在($pathFile)){ echo“
文件$pathFile存在”; }否则{ echo“
文件$pathFile不存在”; }
index.php是您服务器上的实际文件夹名称吗?可能您必须授予文件存储目录的权限。请尝试。使用echo
Yii::getAlias('@web')。/directoryName/ImageName';
$filename='';如果(文件存在($filename)){echo“文件$filename存在”}其他{echo“文件$filename不存在”;}die();不工作!文件不存在,但当我使用url浏览器检查时,此链接有图像
$url = 'http://www.example.com'; // or file path
$headers = get_headers($url, 1);
print_r($headers);               // $headers[0] will get the status
        $pathFile = \Yii::getAlias('@webroot') .'/files/temppdf/' . 'benja.pdf'; 
        echo "<br>Absolute Path:" . $pathFile;
        if (file_exists($pathFile)) {
            echo "<br>The File $pathFile Exists";
        } else {
            echo "<br>The File $pathFile Do Not Exist";
        }