Laravel 本地:fopen 权限被拒绝
Laravel local: fopen Permission denied
我需要帮助来修复这个错误:
fopen(/Subckt.txt): failed to open stream: Permission denied
- 我正在使用 Laravel
- 我在本地网站上使用 cmd 和 php
artisan 服务命令
- 我发现了一些可能的 chmod 解决方案,但由于我使用的是本地主机,所以我认为它行不通
- 该网站是 运行 一个 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);
杰森刘易斯
继续阅读 file_get_contents()。该错误是不言自明的。您将资源传递给 file_get_contents(),而不是字符串。你需要这样称呼它:
$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
。在 windows 上,我不知道...希望我能帮到一些人。
我需要帮助来修复这个错误:
fopen(/Subckt.txt): failed to open stream: Permission denied
- 我正在使用 Laravel
- 我在本地网站上使用 cmd 和 php artisan 服务命令
- 我发现了一些可能的 chmod 解决方案,但由于我使用的是本地主机,所以我认为它行不通
- 该网站是 运行 一个 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);
杰森刘易斯
继续阅读 file_get_contents()。该错误是不言自明的。您将资源传递给 file_get_contents(),而不是字符串。你需要这样称呼它:
$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
。在 windows 上,我不知道...希望我能帮到一些人。