Herland Cid
Herland Cid

Reputation: 574

unable to get value from $_FILES

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

Answers (4)

abhayendra
abhayendra

Reputation: 187

<input type="submit" value="Submit" name="submit" >

use this on submit input your code run

Upvotes: 1

Sachem
Sachem

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

devBinnooh
devBinnooh

Reputation: 611

Try

<?php

if(isset($_POST['submit'])) {
     var_dump($_FILES);
     //OR
     print_r($_FILES);
}

?>

Upvotes: 0

Musa
Musa

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

Related Questions