LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 08-26-2004, 01:52 AM   #1
obj63
LQ Newbie
 
Registered: Oct 2003
Location: St. Louis, Tampa
Distribution: Mandrake 9.1
Posts: 9

Rep: Reputation: 0
Question PHP error message when uploading files


I am trying to create an html file with php to upload a file here is the code first

<html>
<?
// In PHP earlier then 4.1.0, $HTTP_POST_FILES should be used instead of $_FILES.
if(!empty($_FILES["userfile"])) {
$uploaddir = "/var/www/uploads/"; // set this to wherever
//copy the file to some permanent location
echo "Test<br><br>";
if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $uploaddir . $_FILES["userfile"]["name"])) {
echo("file uploaded");
} else {
echo ("error!");
}
}
?>
<form action="?php $_SERVER['PHP_SELF']?" method=post enctype="multipart/form-data">
submit this file: <input type=file name="userfile"><br>
<input type=submit><br>
</form>
</html>
---------------------------------------------
-----myupload.php
<html>
<?
// In PHP earlier then 4.1.0, $HTTP_POST_FILES should be used instead of $_FILES.
if(!empty($_FILES["userfile"])) {
$uploaddir = "/uploads/"; // set this to wherever
//copy the file to some permanent location
echo "Test<br><br>";
if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $uploaddir . $_FILES["userfile"]["name"])) {
echo("file uploaded");
} else {
echo ("error!");
}
}
?>
</html>

When I run this script I get

Warning: Unable to create '/var/www/uploads/email.html': Permission denied in /var/www/html/upload.html on line 8

Warning: Unable to move '/tmp/phpQASbmS' to '/var/www/uploads/email.html' in /var/www/html/upload.html on line 8
error!

I do not understand why this is since the permisions of this folder are able to be writen to from others. Also the directory for uploads in php.ini is that directory in the code and the upload settings are on.

Thanks for all the help
Joe
 
Old 08-26-2004, 02:55 AM   #2
Ashkhan
Member
 
Registered: Oct 2003
Distribution: Debian, Solaris, MacOS
Posts: 39

Rep: Reputation: 16
Try to chmod the folder to 777.

Maybe you have a file in this folder with the same name, which can't be overwritten.
 
Old 08-26-2004, 10:39 AM   #3
obj63
LQ Newbie
 
Registered: Oct 2003
Location: St. Louis, Tampa
Distribution: Mandrake 9.1
Posts: 9

Original Poster
Rep: Reputation: 0
Yeah I have tried that already for the base /var/www/uploads/ folder and the tmp folder is set as that as well. Any other suggesstions?

Thanks
Joe
 
Old 08-26-2004, 10:40 AM   #4
obj63
LQ Newbie
 
Registered: Oct 2003
Location: St. Louis, Tampa
Distribution: Mandrake 9.1
Posts: 9

Original Poster
Rep: Reputation: 0
also that file doesnot exist on my linux box.

Thanks
 
Old 08-26-2004, 12:15 PM   #5
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
Did you try with :
$uploaddir = "/var/www/uploads/"

instead of:
$uploaddir = "/uploads/"

Also the error message mention a line in a html file, I assume apache is set (on your system) to execute this type of file rather than display it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
uploading multiple files with php dizzutch Programming 0 01-04-2005 04:29 PM
Uploading files using PHP giving Permission Denied error MatthewG Programming 4 05-27-2004 03:38 PM
Error uploading file with PHP jacksmash Programming 8 11-22-2003 11:11 AM
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


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration