17

The HTML:

<form action="formhandler.php" method="post" enctype="multipart/form-data">
    <input type="file" name="file" />
    <input type="submit" name="submit" value="Submit" />
</form>

and doing a print_r($_FILES) in formhandler.php after choosing a file and clicking submit yields:

[file] => Array
    (
        [name] => 
        [type] => 
        [tmp_name] => 
        [error] => 4
        [size] => 0
    )

And error code 4, according to the manual stands for "UPLOAD_ERR_NO_FILE - No file was uploaded" but I can't figure out why it wasn't uploaded.

3
  • 3
    Could be to do with your tmp folder? Does PHP have the right permissions? Commented Feb 11, 2014 at 9:48
  • @JoshuaSmickus Hmm maybe. Where is this temp folder? I know there is a temporary upload before you handle it properly with move_uploaded_file(). Is it the folder where formhandler.php is in? Commented Feb 11, 2014 at 9:49
  • Print_r($_FILES); return the complete information of file please make sure your uploading file and the event call on button submit Commented Feb 11, 2014 at 9:50

4 Answers 4

24

In this case, the problem was: I had multiple input elements with the attribute name="image". When I changed to individual names the error disappeared.

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

3 Comments

Hello. Is it possible for you to ellaborate more on this? I have the same error and I think is the same cause, but I'm not understanding what you mean to "changed to individual names". Thanks in advance.
@RaRdEvA Hi. What I meant was that I gave all my <input> a unique name attribute. Before I had name="image" for several inputs. Then I changed it so that no <input> had the same name="" attribute as anything else. That's what I meant with "individual names". I made the name attributes unique.
That clarifies a lot. I thought you meant to give that name in the PHP code and I never thought it was in the HTML. I solved it by changing the name of what was received before it was uploaded. Thanks again, I will give it a try.
1

Other solution (PHP 7.3.11)

for answer @Weblurk https://stackoverflow.com/a/21698740/9635711

Don't works:

<input id="files" multiple="true" name="file_images_send[header_image]" type="file">
<input id="files" multiple="true" name="file_images_send[header_image]" type="file">

It works - Solution - with array "[]" end name input

<input id="files" multiple="true" name="file_images_send[header_image][]" type="file">
<input id="files" multiple="true" name="file_images_send[header_image][]" type="file">

1 Comment

I started getting this error after I removed the "[]" from the name. The error is what brought me to this page.
0

These may happen when you upload multiple pictures and the device is a phone; because sometimes phones save the file with same name under different folders; but, in the upload, you get the same file in the same folder with the same name, thus, leaving you without files.

What I did is to change the name before the upload, in PHP, to grant a unique name to each file. Error is gone now.

This is not the solution, just a solution for a specific situation in the same circumstances.

Comments

0

My issue for this error was having multiple forms in an index view (each row having a separate form of inputs of the same name) and the forms falsely sharing the same id.

Once I removed the forms id the issue was resolved.

Comments

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.