【问题标题】:Check exist file with php用 php 检查存在的文件
【发布时间】:2016-06-29 02:27:02
【问题描述】:

我想用 php 或 yii2 检查存在的文件

filesizeis_filefile_exists 不起作用!

filesize 错误是:filesize(): stat failed for....
is_filefile_exists 返回 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>

。 . . .

【问题讨论】:

  • index.php 是您服务器上的实际文件夹名称吗?
  • 可能您必须授予存储文件的 DIR 权限。请尝试一下。
  • 使用 echo Yii::getAlias('@web').'/directoryName/ImageName';

标签: php yii2


【解决方案1】:

试试这个

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

来源:link

【讨论】:

    【解决方案2】:

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

    $filename = '/path/to/foo.txt';
    
    if (file_exists($filename)) {
        echo "The file $filename exists";
    } else {
        echo "The file $filename does not exist";
    }
    

    如果您无法做到这一点,那么问题与您的许可有关。尝试检查桌面或其他允许目录中的文件。

    希望这会有所帮助。

    【讨论】:

    【解决方案3】:

    在你的路径中你不需要 index.php 而只需要路径

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

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

    如果你想使用相对(相对于当前路径)路径,你可以使用这个:

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

    【讨论】:

      【解决方案4】:

      如果您正在检查文件是否存在于服务器中,您只需提供绝对路径,我使用 \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";
              }
      

      【讨论】:

        【解决方案5】:
        $url = 'http://www.example.com'; // or file path
        $headers = get_headers($url, 1);
        print_r($headers);               // $headers[0] will get the status
        

        【讨论】:

          猜你喜欢
          • 2012-10-27
          • 2023-01-02
          • 2023-04-04
          • 1970-01-01
          • 2018-10-22
          • 1970-01-01
          • 2011-05-14
          • 1970-01-01
          • 2016-01-27
          相关资源
          最近更新 更多