Reputation: 574
I'm just not getting the Strings from $_FILES["file"]["name"], $_FILES["file"]["type"], and so on. It's my first time using $_FILES. In which way Could I improve the code so I get the echo from the strings? I've read every tutorial already. here is the code:
<html>
<head>
</head>
<body>
<form action="" method="POST" enctype="multipart/form-data" >
<input type="file" name="file">
<input type="submit" value="Submit">
</form>
<?php
if(isset($_POST['submit']))
{
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"];
}
}
?>
</body>
</html>
Upvotes: 2
Views: 3965
Reputation: 187
<input type="submit" value="Submit" name="submit" >
use this on submit input your code run
Upvotes: 1
Reputation: 491
use print_r($_FILES); not echo
You checks
if(isset($_POST['submit'])) {
but you are missing name="submit" in your form.
Upvotes: 0
Reputation: 611
Try
<?php
if(isset($_POST['submit'])) {
var_dump($_FILES);
//OR
print_r($_FILES);
}
?>
Upvotes: 0
Reputation: 97672
Your submit input does not have a name attribute so its value cant be sent when the form is submitted. Set its name attribute to submit and them your isset check will pass
<input type="submit" name="submit" value="Submit">
Upvotes: 4