Laravel local:fopen Permission denied

时间:2017-08-15 19:54:22

标签: php laravel fopen permission-denied

我需要帮助才能解决此错误:

  

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

  • 我正在使用Laravel
  • 我通过使用带有php的cmd在本地工作 工匠服务指令
  • 我找到了一些使用chmod的潜在解决方案,但由于我使用localhost,我认为它不起作用
  • 网站正在运行php代码来修改txt文件。然后我将它保存到另一个文件。在根文件夹上。
  • 整个网站文件夹都是readonly,我无法修改。 (我使用的是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);

2 个答案:

答案 0 :(得分:0)

对于运行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上,我不知道......我希望我可以帮助一些。

答案 1 :(得分:-1)

作者:JasonLewis

阅读file_get_contents()。错误是自我解释的。您将资源传递给file_get_contents(),而不是字符串。您需要将其称为:

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

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