php - display data of form in html
351
I have a form in HTML. After submitting it, I want to show the name of file in the same HTML page. I use a PHP file calledupLoad.php
to echo the name of the file but what should I do to show the name of file in the same html page?
I also don't want to use php code in my html code.
HTML:
<form action="upLoad.php" method="post" enctype="multipart/form-data">
<input type="file" name="file"/>
<input type="submit" name="submit" value="submit"/>
</form>
PHP:
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
Answer
Solution:
Keep
action
emptyAnd put this at the start of the page
You can now use the
$print
variable anywhere in the same page to show the result by usingecho $print
Answer
Solution:
You cannot receive data with HTML only so you'll have to make your first page a .php with:
And if you end up working with multiple forms you can use a get variable on your action like this:
Or just use an hidden input if you prefer not to have any GET variables like so:
Answer
Solution:
If you really don't want to use php on the HTML file, you could use jquery form plugin http://jquery.malsup.com/form/