I'm trying to upload file to server with php script. I'm Using MAMP with PHP7.0.8
I have HTML form:
<form enctype="multipart/form-data" action="hi" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="300000" />
Send File: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
And simple php:
<?php
$uploaddir = 'img/';
print_r($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 'info:';
print_r($_FILES);
echo "<br />";
print_r($_FILES['userfile']['error']);
print "</pre>";
?>
My result is:
Possible file upload attack!
info:Array
(
[userfile] => Array
(
[name] => high-school-icon.png
[type] => image/png
[tmp_name] => /Applications/MAMP/tmp/php/phpoaPmYv
[error] => 0
[size] => 1807
)
)
Form action documentation
Error:
action="hi"
Change it to: action="simple.php"
<form enctype="multipart/form-data" action="simple.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="300000" />
Send File: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With