Reputation: 13
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
Upvotes: 0
Views: 3068
Reputation: 989
change enctype="multipart/file-data"
to enctype="multipart/form-data"
Upvotes: 3