SharkBait Posted October 20, 2006 Share Posted October 20, 2006 I am having issues.I use the following:[code]<?php$filename = "testfile.txt";if(!$handle = fopen($filename, 'a+')) { echo "Cannot open file";}?>[/code]Now I get an Permission Denied warning and the Cannot open file error when I try to open/write a file.It seems (if the file exists) the file that is to be written to needs to be 777 for it to work. Isn't the a+ argument supposed to create the file and open it if its not there?? The script itself has 777 permissions.What I want to do is if the file doesn't exists, create it and change the permission so that I can write to it properly.What am I doing wrong? Link to comment https://forums.phpfreaks.com/topic/24569-fwrite/ Share on other sites More sharing options...
obsidian Posted October 20, 2006 Share Posted October 20, 2006 does the [b]folder[/b] into which you're trying to write your file have writable permissions? that's key. the file itself needs them, yes, but if the folder in which you are trying to create a file doesn't, you're hosed. Link to comment https://forums.phpfreaks.com/topic/24569-fwrite/#findComment-111964 Share on other sites More sharing options...
AlexJ312 Posted October 20, 2006 Share Posted October 20, 2006 Sounds like a permission issue. Link to comment https://forums.phpfreaks.com/topic/24569-fwrite/#findComment-111983 Share on other sites More sharing options...
SharkBait Posted October 20, 2006 Author Share Posted October 20, 2006 So i would have to turn the entire folder that the file sits in to writable? geesh that seems a bit of a security issue...Or is it best to put it into a subdirectory of its own and 777 that subdir? Link to comment https://forums.phpfreaks.com/topic/24569-fwrite/#findComment-112026 Share on other sites More sharing options...
obsidian Posted October 20, 2006 Share Posted October 20, 2006 [quote author=SharkBait link=topic=112147.msg455140#msg455140 date=1161372941]Or is it best to put it into a subdirectory of its own and 777 that subdir?[/quote]bingo... however, if possible, you should set up your apache user to have group permissions so you can set your folder to 755 or 775 instead of 777. Link to comment https://forums.phpfreaks.com/topic/24569-fwrite/#findComment-112027 Share on other sites More sharing options...
SharkBait Posted October 20, 2006 Author Share Posted October 20, 2006 I'll look into that as well. Thanks Obsidian, thanks others too :) Link to comment https://forums.phpfreaks.com/topic/24569-fwrite/#findComment-112035 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.