html - php file upload not working returns empty result -


below html code....

    <form enctype="multipart/form-data" action="some.php" method="post">                                   <label for="file">filename:</label>        <input type="file" name="file" id="file"><br>        <input type="submit" name="submit" value="submit">     </form> 

and some.php code...

    print_r($_files);     print_r($_post);     if ($_files["file"]["error"] > 0)     {        echo "error: " . $_files["file"]["error"] . "<br>";     }     else     {        echo "upload: " . $_post["file"]["name"] . "<br>";        echo "type: " . $_files["file"]["type"] . "<br>";        echo "size: " . ($_files["file"]["size"] / 1024) . " kb<br>";        echo "stored in: " . $_files["file"]["tmp_name"];     } 

$_post results in array ( [file] => gcc-mlion.tar [submit] => submit ) $_files gives empty result.

you're trying output value of $_post['file']['name'];. return undefined index error message.

change line to:

echo "upload: " . $_files['file']['name'] . "<br>"; 

that should fix issue.

also, here's how i'd it:

<pre> <?php if(isset($_post['submit'])) //checking if form submitted { print_r($_files); print_r($_post);  if ($_files["file"]["error"] > 0) //checking if error'ed     {     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"];     } } ?> </pre>  <form enctype="multipart/form-data" action="" method="post">                               <label for="file">filename:</label>    <input type="file" name="file" id="file"><br>    <input type="submit" name="submit" value="submit"> </form> 

hope helps!


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -