【问题标题】:php file error. silly small problemphp 文件错误。愚蠢的小问题
【发布时间】:2010-04-15 17:56:08
【问题描述】:

使用 xampp 在桌面上可以正常工作,但是当我将其上传到我的虚拟主机时,它就不行了。文件 x.csv 在同一个目录中

$csv_file = "x.csv";

$handle = fopen(($csv_file), "r");

我得到的错误是-

fopen(x.csv): failed to open stream: No such file or directory in /var/www/html/x/admin/import_one.php on line 12

我哪里错了?

【问题讨论】:

    标签: php file fopen


    【解决方案1】:

    检查您是否具有 x.csv 的读取权限 也试试

    $handle = fopen(dirname(__FILE__) . DIRECTORY_SEPARATOR . $csv_file, 'r'); 
    (可能你的 cwd 不在同一个目录中)

    【讨论】:

    • FILE 是什么? csv 文件的文件名?还是 import_one.php?
    • __FILE__ 是一个magic constant,它总是解析为当前文件的路径,所以dirname(__FILE__) 表示“当前脚本的目录”。
    【解决方案2】:

    Linux 区分大小写,Windows 不区分。

    确保您的文件名为 x.csv 而不是 X.csvx.CSV

    【讨论】:

      【解决方案3】:

      如有疑问,请使用绝对文件路径。

      $path = '/path/dir/something/';
      $file = 'x.csv';
      
      $fp = fopen($path . $file, 'r');
      if ($fp)
      { 
          // do some amazing stuff here.
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-08-24
        • 1970-01-01
        • 1970-01-01
        • 2015-07-11
        • 1970-01-01
        • 2020-08-27
        • 1970-01-01
        • 2011-06-09
        相关资源
        最近更新 更多