flourishlib / flourish-classes

The class files for Flourish
http://flourishlib.com
182 stars 78 forks source link

fUpload filter fails when empty file inputs are staggerred #148

Open wbond opened 12 years ago

wbond commented 12 years ago

Ticket #760 by @patrickatimarc

If i fill out the first two of three fields everything is fine. if I fill out one and three I get an error "The index specified, 1, is invalid for the field attachments"

:)

Comment by @wbond

Can you provide the HTML for the inputs and the PHP code you are using to upload the files?

Comment by @patrickatimarc

Sho can:

<div class="attachment">
    <input type="file" name="attachments[]">
    <a class="remove_attachment">- remove this attachment</a>
</div>

<div class="attachment">
    <input type="file" name="attachments[]">
    <a class="remove_attachment">- remove this attachment</a>
</div>

<div class="attachment">
    <input type="file" name="attachments[]">
    <a class="remove_attachment">- remove this attachment</a>
</div>

<p id="add_attachment"><a>+ Add Attachment</a></p>
if (!empty($_FILES)) {
    fUpload::filter('attachments');
    $uploader = new fUpload();
    $uploader->setMaxSize('5m');
    for ($i=0; $i < fUpload::count('attachments'); $i++) {
        $attachments[] = $uploader->move($_SERVER['DOCUMENT_ROOT'] . '/uploads/', 'attachments', $i);
    }
}

Comment by @MrDamien

--- fUpload.php Wed Aug 24 22:01:06 2011
+++ fUpload.php Wed Jul 25 11:40:16 2012
@@ -145,6 +145,11 @@
            }   
        }

+       foreach ($_FILES[$field] as $col=>$val)
+       {
+           $_FILES[$field][$col] = array_values($val);
+       }
+       
        return $indexes;
    }