This is another one where I look at 3 or 4 examples that are all nearly identical and show basic functionality. When I try to use the code I receive an error that is unclear to me as to why it fails.
I tried two different examples, but here is the one I'm currently using. I received the same error with both.
<form enctype="multipart/form-data" action="uploader.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>
Here is the upload code.
$uploaddir = 'uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo '<pre>';
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 "</pre>";
Here is what I get...
Warning: move_uploaded_file(uploads/ipap4p.jpg): failed to open stream: Permission denied in /usr/home/domain/public_html/www-sec/myfolder/uploader.php on line 28
Warning: move_uploaded_file(): Unable to move '/tmp/php3QO4Ye' to 'uploads/ipap4p.jpg' in /usr/home/domain/public_html/www-sec/myfolder/uploader.php on line 28
Possible file upload attack!
Here is some more debugging info:Array
(
[userfile] => Array
(
[name] => ipap4p.jpg
[type] => image/jpeg
[tmp_name] => /tmp/php3QO4Ye
[error] => 0
[size] => 7342
)
)
It seems to be a permissions issue or it could be that the folder does not exist or I'm pointing at the wrong folder.
Where is the tmp folder that it uses?
What should the permissions be?
I have an uploads folder that is just below the root of where the page is. I have a tmp folder that is at the same level as 'public_html', 'public_ftp', and 'www'. Both my 'uploads' folder and the 'tmp' folder have permissions set at 7-7-7. I also tried adding an 'uploads' folder at the same level as 'tmp'. At one point I changed the code above to $uploaddir = './uploads/';
Greg