Laravel地方:FOPEN权限被拒绝
问题描述:
我需要帮助解决这个错误:Laravel地方:FOPEN权限被拒绝
fopen(/Subckt.txt): failed to open stream: Permission denied
- 我使用Laravel
- 我工作的网站在本地使用CMD与PHP 工匠服务命令
- 我发现了一些与chmod的潜在解决方案,但由于我使用本地主机,我不认为它的工作
- 该网站正在运行一个PHP代码来修改一个txt文件。然后我将它保存到另一个文件。在根文件夹中。
- 整个网站文件夹被声明为只读,我无法修改该文件夹。 (我使用Windows 7,当我取消选中它总是重新检查框,但我设法删除只读文本文件(Subckt.txt和\ npn.lib)
- 我试着我的代码没有laravel在。PHP和HTML文件,它的工作原理
这里是我的部分代码:。
// 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);
答
通过JasonLewis
上file_get_contents()阅读了该错误是自我解释你通过了资源的file_get_contents (),而不是一个字符串,你需要cal l在想:
$contents = file_get_contents("textdoc.txt");
,我发现我的答案有:https://forums.phpfreaks.com/topic/117829-solved-file-get-contents-help/
答
你有上运行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
。在窗户上,我不知道...我希望我可以帮助一些。
检查你的'基路径'。 'fopen'函数似乎试图从文件系统的根目录加载文件,这肯定会产生权限冲突。 – Ohgodwhy
In:$ inputFile =“\ npn.lib”; \ n被认为是新行... – Mark
$ inputFileContent = file_get_contents(“C:\ Users \ username \ Desktop \ model \\ testnpn.lib”);而不是2行 – Mark