Can't upload files with PHP

I have a very basic upload form on my page however I am unable to upload. I believe it has something to do with the tmp folder or upload folder.

 <form enctype="multipart/form-data" action="upload.php" method="POST">
 Please choose a file: <input name="uploaded" type="file" /><br />
 <input type="submit" value="Upload" />
 </form> 

[php]

<?php $target = "/uploads/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } ?>

[/php]

I am getting “Sorry, there was a problem uploading your file.”

file_uploads is ON
upload_tmp_dir is “sharing/tmp” sharing is the folder where the form html is as well as the uploads folder
Permissions for sharing/tmp are set to 777 (just temporarily)
Permissions for /uploads is set to 777 (temporarily)
Files im trying are 1kb so it’s not the file size
Right now there are no restricted file type

What else could the problem be?

I am running a LAMP setup on Ubuntu Server 12.0.4.3 (PHP Version 5.3.10-1ubuntu3.9)

Well I went over to php.net and used their code which the output gives you more of a cause for the error;

The HTML.

 <!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="upload.php" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>

The PHP
[php]
$uploaddir = ‘/uploads/’;
$uploadfile = $uploaddir . basename($_FILES[‘userfile’][‘name’]);

echo ‘

’;
if (move_uploaded_file($_FILES[‘userfile’][‘tmp_name’], $uploadfile)) {
echo “File is valid, and was successfully uploaded.\n”;
} else {
echo “Possible file upload attack!\n”;
}

echo ‘Here is some more debugging info:’;
print_r($_FILES);

print “

”;

?>
[/php]

The error when trying to upload a small pirate image;

Possible file upload attack!
Here is some more debugging info:Array
(
[userfile] => Array
(
[name] => pirate.png
[type] => image/png
[tmp_name] => /tmp/phpE9EkEh
[error] => 0
[size] => 12854
)

)

According to this there is no error however no file gets uploaded?

I have no idea what I did but I messed around with a multitude of things so I am not sure what combination fixed it.

Sponsor our Newsletter | Privacy Policy | Terms of Service