php question
- Started
- Last post
- 21 Responses
- abstrakt
i'm having some trouble and i'd really appreciate some help... i'm trying to create a new file in a folder. this is the code i use to create and write to the file:
$myfile = fopen("$myfile", "w");
fwrite($myfile, $filecontent);
fclose($myfile);i get this error:
Warning: fopen(/path/tofolder/filename.tx... failed to open stream: Permission denied in /path/tofolder/gen_files.php on line 19
i swapped out the real paths for privacy reasons, but the paths are OK. it says "Permission denied", but I'm creating a new file and writing to it. I'm really confused on what I need to do here. Thanks for any help!!
- abstrakt0
oh one other thing. it seems i only get the permission denied error if i'm creating a new file. if i open an existing file and modify it, i get no errors.
- toastie0
check the permissions on that folder.
- sparker0
the user/group you are using doesn't have write permission to the directory.
set your permissions accordingly via 'chmod'
- cosmo0
change the chmod to 766 of the folder u r about to create the file in.
- abstrakt0
oooh cool. yeah the folder is 755, so no group write access. i'll give that a try. just to make things automated/simpler, can i check the permissions of that folder through PHP and change them via code?
- cosmo0
u can change the folder/file permission using
http://us2.php.net/manual/en/fun…
- abstrakt0
you rock man :)
thanks
- abstrakt0
both of you rock :)
- cosmo0
to check for file permission u can
if(!chmod("myfile.txt", 0444)) {
echo "Error! Incorrect file permission";
exit;
}
- abstrakt0
oh neat, i didn't see that chmod returns a boolean
- toastie0
damn cosmo, way to make me look lazy.
- cosmo0
abstrakt, this might help out.
- cosmo0
hahah dude at work, i was just working on the same permissions bullshit. So i copied them from my files onto here. ;)
- abstrakt0
yeah toastie... slacker :P
right on cosmo, some good info at that URL. thanks
- abstrakt0
man, it won't let me change the permissions of any folders. it just gives an error on the chmod line...
Warning: chmod(): Operation not permitted in /home/virtual/site111/fst/var/ww... on line 19
i'll keep reading to see if i can figure this out, but if you guys have any suggestions i'd really appreciate it
- abstrakt0
i'm on media temple if maybe they have something weird with their servers that won't allow this
- fusionpixel0
most likely security reasons
- cosmo0
hmmm interesting.
- abstrakt0
i'm reading on Media Temple's knowledge base and it says they run their PHP in Safe Mode, which has a lot of limitations, including this one:
"File modifications: moving, copying and changing ownership/permissions of files can only be done when they are owned by the administrative user."
i'm kinda new to all this. can I use the "administrative user" thing? i don't know how to ask that question...