g_p_java Posted January 30, 2009 Share Posted January 30, 2009 Hello , i have the following code $newfile="/home/newfile.txt"; $file = fopen ($newfile, "a"); $output = $ip." ".$newString . "\n"; fwrite($file, $output); fclose ($file); Well, in order for the code to run , the file newfile.txt shall exist from the beginning in my root directory. If there is no file named newfile.txt, the php cannot create it at that time but it outputs : Warning: fopen(/home/newfile.txt) [function.fopen]: failed to open stream: Permission denied in /home/index.php on line 70 What shall i do? The program runs only if the file exists. Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/143124-how-to-create-a-filefunctionfopen-failed-to-open-stream-permission-denied/ Share on other sites More sharing options...
Schlo_50 Posted January 30, 2009 Share Posted January 30, 2009 Don't you need to changes the folder permissions through FTP? Link to comment https://forums.phpfreaks.com/topic/143124-how-to-create-a-filefunctionfopen-failed-to-open-stream-permission-denied/#findComment-750603 Share on other sites More sharing options...
g_p_java Posted January 30, 2009 Author Share Posted January 30, 2009 Don't you need to changes the folder permissions through FTP? Hm...i'm using Unix, I haven't thought of it, cause when the file already exists the fopen works fine, do you know what shall i do in order to change the folder permissions? Well, there is a command named chmod but i know how to use it only when a folder already exists e.g. chmod 755 php_folder but i don't know generally how i can do that Do you have any idea? Thanks! Link to comment https://forums.phpfreaks.com/topic/143124-how-to-create-a-filefunctionfopen-failed-to-open-stream-permission-denied/#findComment-750707 Share on other sites More sharing options...
g_p_java Posted January 30, 2009 Author Share Posted January 30, 2009 Don't you need to changes the folder permissions through FTP? Well you were right, i fixed the permissions and i can write now! Thanks! Link to comment https://forums.phpfreaks.com/topic/143124-how-to-create-a-filefunctionfopen-failed-to-open-stream-permission-denied/#findComment-750731 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.