LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP error message when uploading files (https://www.linuxquestions.org/questions/programming-9/php-error-message-when-uploading-files-222523/)

obj63 08-26-2004 01:52 AM

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

Ashkhan 08-26-2004 02:55 AM

Try to chmod the folder to 777.

Maybe you have a file in this folder with the same name, which can't be overwritten.

obj63 08-26-2004 10:39 AM

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

obj63 08-26-2004 10:40 AM

also that file doesnot exist on my linux box.

Thanks

Cedrik 08-26-2004 12:15 PM

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.


All times are GMT -5. The time now is 10:17 AM.