0

Below is my 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 my 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 ) BUT $_FILES gives empty result.

5
  • 3
    print_R should be print_r Commented Jul 22, 2013 at 4:04
  • it is working in my and print array like Array ( [file] => Array ( [name] => Programmer- Website Changes.zip [type] => application/octet-stream [tmp_name] => D:\xampp\tmp\phpF829.tmp [error] => 0 [size] => 2707463 ) ) Array ( [submit] => Submit ) Upload: Type: application/octet-stream Size: 2644.00683594 kB Stored in: D:\xampp\tmp\phpF829.tmp Please check your apache or .ini settings Commented Jul 22, 2013 at 4:07
  • print_R works for me, on the 3 platforms i just tested it Commented Jul 22, 2013 at 4:09
  • @Dagon May be print_R working , but I think it should not be. May be its a bug in PHP. :) Commented Jul 22, 2013 at 4:14
  • 1
    its php, there are no bugs Commented Jul 22, 2013 at 4:14

2 Answers 2

1

When you try to print File array that time your Spell of "print_r" is wrong. You write "print_R" instead of "print_r", Php is case sensitive so it's matters a lot.

Sign up to request clarification or add additional context in comments.

Comments

0

You're trying to output the value of $_POST['file']['name'];. It will return an undefined index error message.

Change that line to:

echo "Upload: " . $_FILES['file']['name'] . "<br>";

That should fix the issue.

Also, here's how I'd do it:

<pre>
<?php
if(isset($_POST['submit'])) //checking if form was 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 this helps!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.