i am using the get
method to upload the file and when i write the $_FILES["file"]["name"]
then it gives the error Undefined index: file
but if i use the post
method then it works fine. How can i access the file name or file type.Here is the code of first page.
<html>
<body>
<form action="upload2.php" method="GET"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
Here is the code of second page
<?php
$_FILES["file"]["name"];
?>
Files cannot be uploaded through a GET
request. You need to use POST
.
The PHP manual's definition for $_FILES:
"An associative array of items uploaded to the current script via the HTTP POST method."
(Emphasis mine)
Files uploaded through a form using POST method It will always end up in PHP's $_FILES superglobal. while you are using GET method to do that but its not possible as per my knowledge at this condition PHP's $_FILES is not present that's why you are getting error Undefined index: file.