html code:
<form enctype="multipart/form-data" action="upload_file.php"
method="POST">
<p> </p>
<p>Browse for file to upload: <br>
<input name="file" type="file" id="file" size="80"> <br>
<input type="submit" id="u_button" name="u_botton" value="Upload the File">
</p>
</form>
php code:
<?php
$file_result = "";
if ($_FILES["file"]["error"] > 0)
{
$_file_result .= "No File Upload or Invalid File";
$_file_result .= "Error Code: " . $_FILES["file"]["error"] . "<br>";
} else {
$file_result .=
"Upload: " . $_FILES["file"]["name"] . "<br>" .
"Type: " . $_FILES["file"]["type"] . "<br>" .
"Size: " . ($_FILES["file"]["size"] / 1024) . "Kb<br>" .
"Temp file: " . $_FILES["file"]["tmp_name"] . "<br>" .
move_uploaded_file($_FILES["file"]["tmp_name"],
"" . $_FILES["file"]["name"]);
$file_result .= "File Upload Successful !";
}
print " Now just go to www.example.com/ the name of the thing you uploaded "
?>
I am trying to get information from an html form, I am allowing people to upload to my server and I am trying to get the name of the file they uploaded
How do I do that?
Just var_dump
it. It will show all the information you need.
<?php
echo "<pre>";
var_dump($_FILES["file"]);
echo "</pre>";
?>
$fileName = $_FILES['file']['name'];
echo "File name is : " . $fileName;
It will print,
array(5) {
["name"]=>
string(10) "assume.png"
["type"]=>
string(9) "image/png"
["tmp_name"]=>
string(14) "/tmp/phpe9vaQc"
["error"]=>
int(0)
["size"]=>
int(12969)
}
File name is : assume.png
Here, assume.png
was the original file name which i chose from my computer.
EDIT : Since your question is solely based on how to get the filename which was submitted from the form, the answer is above.
If you want to store the image to database, then
upload
or images
& get the upload path.upload/someone.jpg
.Good luck!