Search code examples
phplaravelfopenpermission-denied

Laravel local: fopen Permission denied


I need help to fix this error:

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

  • I'm using Laravel
  • I working on the website locally by using the cmd with the php artisan serve command
  • I've found some potential solution with chmod but since I'm using localhost I dont think it works
  • The website is running a php code to do modification to a txt file. Then I saving it to another file. On the root folder.
  • The whole website folder is stated as readonly, I can't modify that. (Im using windows 7, when I uncheck the box it gets always rechecked. But I managed to remove the read only from the text files(Subckt.txt and \npn.lib).
  • I tried my code without laravel in a php and html file and it works.

Here is my partial code:

// 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);

Solution

  • By JasonLewis

    Read up on file_get_contents(). The error is self explanatory. You passed a resource to file_get_contents(), not a string. You need to call it like:

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

    I found my answer there: https://forums.phpfreaks.com/topic/117829-solved-file-get-contents-help/