PHP $_FILES multiple file uploading problem

12,178

Solution 1

A lot of suggestions here. I'll give it a go. This is based on @Pekka 's comment.

I see you're testing with mp3s, which probably exceed PHP upload limit. This is because in your first example, you actually have an upload error code 1: The uploaded file exceeds the upload_max_filesize directive in php.ini.. So even your fist upload didn't work. A successful upload always has 0 as the error code.

Modify you php.ini with upload_max_filesize = 10M (or 20M, or 300M; careful about that M - which means megabytes - as omitted, brings alot of headache.

I suggest testing with smaller files, as I see you have a limit of 2M for uploading.

Further reading.

Solution 2

I would bet that you exceeded post_max_size and PHP just ignored the uploaded files.

It's 8MB by default. If you try to upload one 5MB file everything will work. If you try to upload 2 5MB files, it exceeeds 8MB and PHP ignores posted data.

Try increasing the value of post_max_size in your php.ini.

Solution 3

Check your max_file_uploads setting -- is it more than 1?

echo ini_get('max_file_uploads');
Share:
12,178
homerun
Author by

homerun

My name is homerun just because I hit home run.

Updated on June 09, 2022

Comments

  • homerun
    homerun almost 2 years

    I have a little problem with uploading multiple files in PHP ,

    i have this html form:

    <form method="post" action="upload.php" enctype="multipart/form-data">
        <input type="file" name="myfile[]"  />
        <input type="submit" />
    </form>
    

    and this is the upload.php :

    <?php print_r( $_FILES ); ?> 
    

    when i'm sending a file it show me this:

     Array
    (
    [myfile] => Array
        (
            [name] => Array
                (
                    [0] => Krw_Qe4QKmI.mp3
                )
    
            [type] => Array
                (
                    [0] => 
                )
    
            [tmp_name] => Array
                (
                    [0] => 
                )
    
            [error] => Array
                (
                    [0] => 1
                )
    
            [size] => Array
                (
                    [0] => 0
                )
    
        )
    
     )
    

    so far so good.

    the problem starts when i upgrade my form to this one :

    <form method="post" action="upload.php" enctype="multipart/form-data">
        <input type="file" name="myfile[]"  />
        <input type="file" name="myfile[]"  />
        <input type="submit" />
    </form>
    

    now , when i send 2 files , it show me this :

    Array
    (
    )
    

    so , what's the problem here? thank you , Mor.

  • homerun
    homerun over 12 years
    i did run this command but nothing came up , i also checked in the ini file it self it does not have such a thing
  • Arnaud Le Blanc
    Arnaud Le Blanc over 12 years
    enable log_errors and look at your server's error_log
  • homerun
    homerun over 12 years
    im checking now , so far i can see if i upload 2 small files it works but with bigger files it wont
  • homerun
    homerun over 12 years
    i dont have the max_file_uploads part on my ini file , can you tell me which system you work with and download link to you're ini file?
  • Pekka
    Pekka over 12 years
    @Mor you need to modify your own php.ini, it's no good downloading somebody else's
  • tttony
    tttony over 12 years
    that's weird, you can copy & paste the code in you php.ini file and this is the content of the php.ini recommend I have php 5.2.17
  • homerun
    homerun over 12 years
    i run my code on WAMP 2 32 bit , this is what's on my ini ;;;;;;;;;;;;;;;; ; File Uploads ; ;;;;;;;;;;;;;;;; ; Whether to allow HTTP file uploads. ; php.net/file-uploads file_uploads = On ; Temporary directory for HTTP uploaded files (will use system default if not ; specified). ; php.net/upload-tmp-dir upload_tmp_dir = "c:/wamp/tmp" ; Maximum allowed size for uploaded files. ; php.net/upload-max-filesize upload_max_filesize = 2M
  • nevvermind
    nevvermind over 12 years
    Actually, you can upload multiple files having the same input name, just like OP used: name[].