LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-26-2004, 11:41 AM   #1
MatthewG
LQ Newbie
 
Registered: Mar 2004
Posts: 3

Rep: Reputation: 0
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
 
Old 05-26-2004, 03:28 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Are you sure that Apache process (usually run by 'apache' user) has permissions to write to the directory you're trying to write?
 
Old 05-26-2004, 05:11 PM   #3
MatthewG
LQ Newbie
 
Registered: Mar 2004
Posts: 3

Original Poster
Rep: Reputation: 0
Hmmm... I'm not sure how to answer that question. Where would I be able to check that?

Matthew
 
Old 05-26-2004, 09:01 PM   #4
MatthewG
LQ Newbie
 
Registered: Mar 2004
Posts: 3

Original Poster
Rep: Reputation: 0
Would that involve changing the permissions of the folders with the chmod command?

Matthew
 
Old 05-27-2004, 03:38 PM   #5
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
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).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
FC3, PHP 4.3.9, and fopen PERMISSION DENIED Cottsay Programming 4 06-25-2005 02:39 PM
uploading multiple files with php dizzutch Programming 0 01-04-2005 04:29 PM
PHP error message when uploading files obj63 Programming 4 08-26-2004 12:15 PM
Problems with uploading files tried php.conf bwreath Linux - General 0 07-31-2003 03:31 PM
PHP and uploading files Syncrm Linux - General 5 07-02-2002 11:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration