LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Uploading files using PHP giving Permission Denied error (https://www.linuxquestions.org/questions/programming-9/uploading-files-using-php-giving-permission-denied-error-186097/)

MatthewG 05-26-2004 11:41 AM

Uploading files using PHP giving Permission Denied error
 
I am trying to provide file uploading for my web site. I read the PHP manual at php dot net and followed their instructions, namely:

Code:

<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir = 'the directory I use is here';
$uploadfile = $uploaddir . $_FILES['userfile']['name'];

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
  print "File is valid, and was successfully uploaded. ";
  print "Here's some more debugging info:\n";
  print_r($_FILES);
} else {
  print "Possible file upload attack!  Here's some debugging info:\n";
  print_r($_FILES);
}

?>

But when I run the script I get the following error:

Code:

Warning: move_uploaded_file('The directory from above'/black.gif): failed to open stream:
Permission denied in /home/randomrp/public_html/dev/upload.php on line 16

Warning: move_uploaded_file(): Unable to move '/var/tmp/phpRxVKaA' to
'The directory from above'black.gif' in 'The directory from above'/upload.php on line 16

Unfortunately I am completely stumped by this. Any ideas what it might be? I have the latest version of PHP installed on the server.

Thanks in advance,
Matthew Glanfield

Mara 05-26-2004 03:28 PM

Are you sure that Apache process (usually run by 'apache' user) has permissions to write to the directory you're trying to write?

MatthewG 05-26-2004 05:11 PM

Hmmm... I'm not sure how to answer that question. Where would I be able to check that?

Matthew

MatthewG 05-26-2004 09:01 PM

Would that involve changing the permissions of the folders with the chmod command?

Matthew

Mara 05-27-2004 03:38 PM

Quote:

Hmmm... I'm not sure how to answer that question. Where would I be able to check that?
Open a terminal, use cd to move to one directory up the one you want to share the files in and then run
ls -l|grep directoryname
where directoryname is the name of your directory.

Quote:

Would that involve changing the permissions of the folders with the chmod command?
If the 'apache' user has no rights to write to the directory, permissions must be changed. Correct combinations would be: 'apache' as owner (3rd column of ls -l) plus 'rwx' for user (beginning of first column in ls -l output) or other user as owner and 'rwx' for other users (at the end of first column in ls -l output).


All times are GMT -5. The time now is 02:53 AM.