PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I've been running in circles throughout the day trying to figure out how to upload a file by way of an HTML form and save it in a particular directory. It seems to be a permissions issue that I keep running into:
Warning: move_uploaded_file(./pics/quote_start.gif): failed to open stream: Permission denied in /home/uplandw/public_html/resamp.php on line 16
I'm working on a shared hosting server. Could this be the source of my permission issues or have I not stumbled across the correct paths for this function?
Last edited by charp on Sat Jul 02, 2005 12:56 pm, edited 1 time in total.
ummmm.... 'kay... I can do this, but let's just pretend that I'm not sure how to begin...
Ah heck, there's no pretending. I need more help.
I have the destination directory CHMOD'd to 755 and the php file that's doing the writing set to 644. Is this the sort of permissions you're suggesting?
Also, if anyone can point me to a really good online tutorial for uploading files and chmoding via php, I'd be very appreciative.
Thanks for the hint in your first post. I played around with the chmod value for the destination directory and managed to get everything to work. However, I had to set directory to 777. Is this an inherently unsafe setting for a directory? Perhaps I should be chmoding it to 777 to save the file and then chmoding it back to a safer setting? Any thoughts?
Thanks for the hint in your first post. I played around with the chmod value for the destination directory and managed to get everything to work. However, I had to set directory to 777. Is this an inherently unsafe setting for a directory? Perhaps I should be chmoding it to 777 to save the file and then chmoding it back to a safer setting? Any thoughts?
Yes that is the way, By script also you can do that.
chmod("$dir_path",0666);
I tried to follow smo's advice and chmod the directory before using move_uploaded_file and then chmod back afterwards.
However, I get this error message:
Warning: chmod(): Operation not permitted in /home/uplandw/public_html/resamp.php on line 12
Not permitted? I can't see my way around this problem.
I thought about using facet's suggestion, but uploading to a tmp directory and copying to another directory still requires the 777 setting, doesn't it?
Perhaps this could all be done via ftp, but surely there must be a straight PHP solution???
Try giving 777 to the dir through FTP , if that works then upload with that permission. But by FTP if you are not able to give 777 then you don't have that permisssion to do, so with script also you won't get.
I check with my hosting company -- here's an excerpt from their reply:
PHP scripts run under the user ID of the web server, which is 'nobody'. This means that PHP scripts can only CHMOD files and directories that are owned by the user 'nobody'. In your case, $upload_dir is owned by you (your user ID), so your PHP script is not allowed to change that directory's permissions with CHMOD.
I tried to use mkdir in an attempt to create a directory owned by 'nobody', but that too failed because the script does not have permission to write to the parent directory. Elsewhere, I read that shared hosting environments typically disable chown so that option is out as well.
In the end, the only options are to chmod the directory to 0777 and leave it there or use FTP to get the job done.