This is driving me crazy. I'm trying to figure out how to upload a file. I've got two very simple files, yet it doesn't seem to work. This first is the file that allows the user to choose the 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 the php file that handles 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 -- except for the print_r
-- I pulled these off a website tutorial on how to do a file upload, I'd think these files are okay.
The print_r($FILES)
return a completely empty array.
I also checked the php.ini
. File uploads are allowed, and the max size is 2M, which I assume is 2 megabytes, which is far larger than the file I've been trying to upload.
What else could be wrong?
Thanks,
Sean.
Be sure to clear cache/cookies. Close your browser and re-open new windows. Check if you need to install updates to your browser or OS. Restart your computer.
You can check if there is a value, and if the image is valid by doing the following: if(empty($_FILES['cover_image']['tmp_name']) || ! is_uploaded_file($_FILES['cover_image']['tmp_name'])) { // Handle no image here... }
Description. $_FILES is a super global variable which can be used to upload files. Here we will see an example in which our php script checks if the form to upload the file is being submitted and generates a message if true. Code of files.
First, please make sure that you are attempting to upload one of the supported file types (see What file types or formats can I upload?). If your file is supported, please try again using a different browser (e.g., Firefox or Chrome instead of Internet Explorer). This should resolve the issue in most cases.
Add the proper enctype attribute to your form
tag:
<form action="getfile.php" method="post" enctype="multipart/form-data">
It's documented here: http://www.php.net/manual/en/features.file-upload.post-method.php
Also, make sure there's no space between your brackets when you access multi-dimensional arrays:
$_FILES['uploadFile']['tmp_name']
You shuold use attribute enctype="multipart/form-data"
in form tag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With