0

Please forgive if this is a silly question. I am trying to learn to upload an image to a website. The code I am using is:

<?php

$name = $_FILES ['file']['name'];
$size = $_FILES ['file']['size'];
$type = $_FILES ['file']['type'];
$tmp_name = $_FILES ['file']['tmp_name'];
$error = $_FILES ['file']['error'];

echo $name . $type . $size;

?>

<form action="test.php" method="POST" enctype="multipart/file-data">

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


</form>

And I'm getting the following error:

Notice: Undefined index: file in C:\wamp\www\Learning\test.php on line ...

I've already checked to see if file upload is enabled in php.ini, and it is. I already tried to nest everything inside two "if" statement, as follows:

if (isset($_FILES['file'])){
if (!empty($_FILES['file'])){
....
variables here
....
echo $name . $size . $type;
}
}

But in this case nothing happens in the page, even when I do select an image from the browse button.

Please tell me what I am doing wrong.

Thanks in advance

3
  • What do you get with var_dump($_FILES); ? Commented Dec 12, 2015 at 15:01
  • Same error +array (size=0) empty Commented Dec 12, 2015 at 15:40
  • it only gives me no error if I enclose it within if statement now (after changing file-data to form-data. Otherwise, it gives error says 'file' is 'undefined index'. Commented Dec 12, 2015 at 15:42

1 Answer 1

3

change enctype="multipart/file-data" to enctype="multipart/form-data"

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

1 Comment

no problem. Next time make sure you double-check all typos before you post... :)

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.