Unable to open file in PHP

I am trying to open a file with PHP for write access:

$myFile = "all.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); 

My browser spits back:

cannot open file

I tried chmod -R 777 the folder where this PHP file is located, as well as where $ myFile (text file) is located. What else could be the problem?

As a result, a permission error appears when I turn on the error report. When I do ls -la all.txt , I get -rwx------ 1 Myname staff 0 Nov 8 15:11 all.txt

+4
source share
1 answer

If the script is run from a different directory, try opening the file from the full URI .

Example:

 $myFile = '/path/to/myFile.txt'; if (!file_exists($myFile)) { print 'File not found'; } else if(!$fh = fopen($myFile, 'w')) { print 'Can\'t open file'; } else { print 'Success open file'; } 
+5
source

Source: https://habr.com/ru/post/1444923/


All Articles