$ _FILES is empty when trying to download a file

It drives me crazy. I am trying to figure out how to upload a file. I have two very simple files, but it does not seem to work. This is the first file that allows the user to select a file:

<html> <head> <title>File Upload Form</title> </head> <body> This form allows you to upload a file to the server.<br> <form action="getfile.php" method="post"><br> Type (or select) Filename: <input type="file" name="uploadFile"> <input type="submit" value="Upload File"> </form> </body> </html> </code> 

The second is a php file that processes it:

 <html> <head> <title>Process Uploaded File</title> </head> <body> <?php print_r($_FILES); print "<P>\n"; move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'], "../blimages/site/7337/{$_FILES['uploadFile'] ['name']}") ?> </body> </html> 

Since - with the exception of print_r - I pulled them out of a website tutorial on how to download a file, I think these files are fine.

print_r($FILES) returns a completely empty array.

I also checked php.ini . File permissions are allowed, and the maximum size is 2 M, which I assume is 2 megabytes, which is much larger than the file I was trying to upload.

What else could be wrong?

Thanks,

Sean.

+7
php
source share
3 answers

Add the correct enctype attribute to your form tag:

 <form action="getfile.php" method="post" enctype="multipart/form-data"> 

Described here: http://www.php.net/manual/en/features.file-upload.post-method.php

Also, make sure that there is no free space between your brackets when accessing multidimensional arrays:

 $_FILES['uploadFile']['tmp_name'] 
+25
source share

You can use the attribute enctype="multipart/form-data" in the form tag.

+1
source share

Add this to the form tag

ENCTYPE = "Multipart / Form Data"

0
source share

All Articles