【问题标题】:file_get_contents function not workingfile_get_contents 功能不起作用
【发布时间】:2010-07-15 09:35:26
【问题描述】:

file_get_contents() 函数有一些问题,当我尝试读取 URL 时它无法正常工作

http://google.com

可以访问,但是当我尝试访问“classes/connect_temp.txt”之类的任何文件时,它无法访问。

这是我使用的一些代码

$file_path =realpath('./')."/classes/connect_temp.txt";
    $temp_cont = file_get_contents($file_path);
    if(empty($temp_cont)){$temp_cont=$this->dbSetings;}

我应该在代码中更改什么或应该检查哪些配置设置。

请帮我解决这个问题

【问题讨论】:

  • 您是否收到任何 PHP 错误?可能该文件不存在,或者您无权读取它。
  • 或者您绝对肯定 $file_path 包含正确的路径?
  • 我 100% 确定 $file_path 包含正确的路径并且它没有给出任何错误
  • 是什么让您说该文件“不可访问”? $temp_cont 总是空的吗?里面有废话吗?文件 connect_temp.txt 中有什么?
  • 我的意思是 $temp_cont 总是空的。并且 connect_temp.txt 有连接模板

标签: php file url file-get-contents


【解决方案1】:

使用display_errors 和/或error_reporting 启用错误报告。

【讨论】:

    【解决方案2】:

    用途:

    echo $file_path;
    

    检查代码真正试图读取的文件。

    【讨论】:

      【解决方案3】:

      也许试试curl
      样品..

      $ch = curl_init("path-to-the-file");
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      $output = curl_exec($ch);      
      curl_close($ch);
      echo $output;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-08-30
        • 2013-06-30
        • 2014-11-16
        • 2015-03-12
        • 2023-03-19
        • 1970-01-01
        相关资源
        最近更新 更多