Re: Permission denied when executing 'copy' command inaPHPscript

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Ashley Sheridan wrote:
On Mon, 2008-09-15 at 18:27 -0400, Edward Diener wrote:

Ashley Sheridan wrote:
On Mon, 2008-09-15 at 17:47 -0400, Edward Diener wrote:

b wrote:
Edward Diener wrote:
In a PHP file upload script which looks like:

$htmlplace="aplace";
if ($_FILES['HtmlFile']['name'] != "")
{

    $filenamex = basename($_FILES['HtmlFile']['name']);
copy($_FILES['HtmlFile']['tmp_name'],$htmlplace."/".$filenamex);
}
You should take a look at is_uploaded_file() and move_uploaded_file().
OK, thanks for pointing this out.

I am getting the error message:

<br />
<b>Warning</b>: copy(aplace/ahtml.html) [<a href='function.copy'>function.copy</a>]: failed to open stream: Permission denied in <b>/home/directory/anotherdirectory/makecopy2.php</b> on line <b>6</b><br />

This was working perfectly before so I am at a loss as to why it is now failing. Does anybody have any idea what could be happening and what the Permission denied refers to and means ? Thanks !

It means that the web server has been denied permission by the OS. Check that the directory perms are properly set.
The directory perms of the 'to' directory ? It is 755.

You might also want to use a full directory path (ie. from the root of the server) for the location the file should be saved to.
I do not think I can know this from my PHP script.

Make sure that apache can write to that directory though. You may need
to make apache the owner of the directory
Agreed, but see my other reply.


Unfortunately then the only thing to do in this case is to give the
directory 777 permissions allowing it to be written to by any user. It's
not ideal, but it is the only way which will let you write to it.

Your suggestion worked without any problems, although it is inherently dangerous.
It probably is but there not much to do about it. Perhaps if there is a web interface on the hosting site you could change the ownership of the file (meaning the owner and the group.

I am guessing that somehow the ownership of the directory was changed.
I think there is a default umask (meaning that when you create a file the default rights are configured) and probably the user that you use to ftp is the owner.

However I have another surmise, based on this question: if the ownership of the PHP script itself changed, could that affect the script's ability to write to the directory ?
The rights of the php script define who reads, writes or executes the script not what he can do. What he can do is defined by who he is and what are his rights on the system (e.g. when you are root you can do anything, when you belong to the root or wheel group you can do many etc).

I am able to create the PHP file in a number of ways through the online interface ( new file, copy, move etc. ) but I can not see what ownership is given to the file via the online user interface. My thought was that I had somehow 'updated' the original PHP file which was working correctly against the aforesaid directory using the online interface differently than I had used it before and this somehow changed the ownership setting ( user and group ) of the PHP file itself, and that this may have caused the attempt to write to the directory to fail.

Actually I have answered that above. It is your user that copies, moves or does anything else with your files so it is his file he has its ownership. I think that most web interfaces don't let you change that for security reasons (at least it makes sense to me).

--
Thodoris


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux