【问题标题】:Laravel local: fopen Permission deniedLaravel 本地:fopen 权限被拒绝
【发布时间】:2018-01-23 19:51:46
【问题描述】:

我需要帮助来解决这个错误:

fopen(/Subckt.txt):打开流失败:权限被拒绝

  • 我正在使用 Laravel
  • 我在本地使用 cmd 和 php 在网站上工作 工匠服务命令
  • 我用 chmod 找到了一些潜在的解决方案,但由于我使用的是 localhost,我认为它不起作用
  • 网站正在运行 php 代码来修改 txt 文件。然后我将它保存到另一个文件中。在根文件夹中。
  • 整个网站文件夹被声明为只读,我无法修改。 (我使用的是 Windows 7,当我取消选中该框时,它总是会重新选中。但我设法从文本文件(Subckt.txt 和 \npn.lib)中删除了只读。
  • 我在 php 和 html 文件中尝试了没有 laravel 的代码,它可以工作。

这是我的部分代码:

// Load the output file
$outputFile = fopen("\Subckt.txt", "w") or die("Unable to open file!"); 

// Load the input file into string
$inputFile = "\npn.lib";

// Put the input file in a string variable
$inputFileContent = file_get_contents($inputFile);

【问题讨论】:

  • 检查您的base pathfopen 函数似乎试图从文件系统的根目录加载文件,这肯定会发生权限冲突。
  • 在:$inputFile = "\npn.lib"; \n 被视为一个新行...
  • $inputFileContent = file_get_contents("C:\Users\username\Desktop\model\\testnpn.lib");而不是 2 行
  • 我已将 txt 和 lib 文件传输到桌面。现在可以使用了

标签: php laravel fopen permission-denied


【解决方案1】:

您是否对运行 php 脚本的用户拥有文件的写入权限?谁是您尝试fopen 的文件的所有者?也许是 www-data 用户试图运行 php 脚本试图打开文件,但如果文件不属于 www-data 组或没有全局写入权限,它将与 php 的权限冲突。如果您使用的是 linux,请尝试使用此 chown -R www-data:www-data /path/to/the/project/folder。如果chown 方法不起作用,请尝试使用chmod -R 775 /path/to/the/file。在 Windows 上,我不知道......我希望我能帮助一些人。

【讨论】:

    【解决方案2】:

    杰森刘易斯

    阅读file_get_contents()。该错误是不言自明的。您将资源传递给 file_get_contents(),而不是字符串。你需要这样称呼它:

        $contents = file_get_contents("textdoc.txt");
    

    我在那里找到了答案:https://forums.phpfreaks.com/topic/117829-solved-file-get-contents-help/

    【讨论】:

      猜你喜欢
      • 2011-08-01
      • 1970-01-01
      • 2020-09-30
      • 2011-11-10
      • 1970-01-01
      • 2019-05-02
      • 1970-01-01
      • 2015-12-03
      • 2019-11-20
      相关资源
      最近更新 更多