PDA

View Full Version : failed to open stream: Permission denied


abbierose
04-17-2007, 04:53 AM
Hello! Can anyone help me with this.... thank you in advance

Every time that I upload a file thru a php form the error "failed to open stream: Permission denied" comes up. And everytime that this error occurs, I'll change the permission mode of the destination directory to 777 thru my ftp program, and the uploading of files will work again.

However, I do not want that each time that I upload a file I will have to set the file permission of the destination directory again and again. I have tried using the chmod in my php file, but I am not permitted to use it - "Warning: chmod() [function.chmod]: Operation not permitted "

How do I keep the directory mode to 777? It seems that the server changes it back to 755 everytime.

Thanks,
Abbie

mlseim
04-17-2007, 01:49 PM
What is the destination directory in relation to the "main" root directory?

Is it a directory that you created to use for your uploaded files?
Or is it a directory that already existed on the server before you used it?

ctene
04-17-2007, 11:55 PM
I had a similar problem - same system you helped me with - I needed to create and chmod folders so they allow for uploading files (and respectively updating and/or deleting) the best for you to preserve the chmodding is if you also create the initial directory via PHP script. Why? because then the directory is owned by the httpd user in most cases, meaning it will allow you to set permissions via php, if you create the directory manually via ftp, it's owned by the ftp user account which is always different (for a good reason) *UNIX geek talking here LOL* here is a codesnippet which will probably be useful to you:

if(isset($addcat))
{
$client = $_POST['client'];
$updq = "INSERT INTO clients SET name = '$client'";
$updr = mysql_query($updq) or die(mysql_error());

mkdir('/private/var/www/yoursite/images/'.$client.'', 0700);
chmod("/private/var/www/yoursite/images/".$client."", 0777);
mkdir('/private/var/www/yoursite/documents/'.$client.'', 0700);
chmod("/private/var/www/yoursite/documents/".$client."", 0777); ....

Hope I could help :) ... oh and of course you can do it with if/else, oce a directory exists to skip the mkdir command and the chmod command ... but you know that ;)

Cheers,

Pete :thumbsup: