Laravel 本地:fopen 权限被拒绝

Laravel local: fopen Permission denied

我需要帮助来修复这个错误:

fopen(/Subckt.txt): failed to open stream: Permission denied

这是我的部分代码:

// 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 上,我不知道...希望我能帮到一些人。