-1

when I run my page on my local host it does not create the file. I have given read and write permissions to the folder site. i have used system and exec functions and when i run the page via the terminal it creates a file but via my browser it doesnt.

$my_file = '/var/www/site/file.txt';
$handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file); 
Meryvn
  • 65
  • 3
  • 12

2 Answers2

1

The following commands will correctly apply permissions to the directory.

cd /var/www/site
sudo chmod 664 *
sudo find . -type d -exec chmod 755 {} \;

If the error persists, please post any PHP errors that are thrown.

Dean
  • 5,884
  • 2
  • 18
  • 24
0

Did you try with a relative adresse?

$my_file = 'site/file.txt';
OwNAkS
  • 271
  • 1
  • 3
  • 10
  • Is threw back this error. `Cannot open file: logstash/file.txt` – Meryvn Jan 18 '13 at 13:32
  • 1
    fopen in 'w' mode wont create a file..in 'w+' mode it'll create a file. check link http://php.net/manual/en/function.fopen.php#refsect1-function.fopen-parameters – Priya Jan 18 '13 at 13:53
  • it creates the file but it only in set it to read. I have used to chmod 777. `chmod("/var/www/site/file.txt", 777); $handle = fopen($my_file, 'w+') or die('Cannot open file: '.$my_file); ` and the site folder has `drwxrwxrwx` permissions set. – Meryvn Jan 21 '13 at 06:31