I have a question on file uploading. I hve searched the forum but have not found a solution.
I used the following test files to test the file upload. It works fine except that the file does not appear where it is supposed to. In fact, it does not appear anywhere accessible! It ends up in /tmp/some_random_name. When I check the directory /tmp no such file or folder exists!
Since this is a site hosted by an outside hosting company, I cannot modify the php.ini file, as directed in the php manual to change the temp_dir (if this is what I need to do). This is what I have and the output:
<form action="test_upload.php" method="post" enctype="multipart/form-data">
<p>Pictures:
<input type="file" name="pictures" />
<input type="submit" value="Send" />
</p>
</form>
test_upload.php:
$uploaddir = '/home/mydomain/www/demo/images/uploads';
$uploadfile = $uploaddir . basename($_FILES['pictures']['name']);
if (move_uploaded_file($_FILES['pictures']['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);
?>
Output:
File is valid, and was successfully uploaded.
Here is some more debugging info:
Array(
[pictures] => Array
(
[name] => bg_blue.jpg
[type] => image/jpeg
[tmp_name] => /tmp/phpc7nOLo
[error] => 0
[size] => 14772
)
)
If I replace the $_FILES['pictures']['tmp_name'] with $uploaddir in the function move_uploaded_file(), I get "Possible file upload attack!"
TIA