This question is related to my previous question where I'd created a tab form in admin using a template file. The content of template file is:

<div class="entry-edit">
    <div class="entry-edit-head">
        <h4 class="icon-head head-edit-form fieldset-legend">Images</h4>
    <div class="fieldset">
        <div class="hor-scroll">
            <table class="form-list container">
                <tr class="wrapper-tr">
                    <td class="value">
                        <input type="file" name="images[]"/>
                    <td class="label">
                        <span class="remove">Remove</span>
            <input type="button" class="add" value="Add Image"/>

    jQuery(document).ready(function() {
        jQuery('.add').click(function() {
            var wrapper = "<tr class='wrapper-tr'>" +
                    "<td class='value'><input type='file' name='images[]'></td>" +
                    "<td class='label'><span class='remove'>Remove</span></td>" +
            jQuery(wrapper).find('.remove').on('click', function() {
        jQuery('.container').on('click', 'span.remove', function() {
            if (jQuery('.wrapper-tr').length > 1) {
            } else {
                alert('at least one image need to be selected');

for uploading multiple files.

But as my input type name is images[] that's why in my controller's saveAction() I'm unable to upload file using Varien_File_Uploader as:

$uploader = new Varien_File_Uploader('images');

what value should I pass in Varien_File_Uploader constructor in order to be able to upload file?

I tried logging and found this warning:

Warning: file_exists() expects parameter 1 to be a valid path, array given in /var/www/mageqb/lib/Varien/File/Uploader.php on line 150

Code in my controller is:

foreach ($_FILES['images']['name'] as $key => $image) {
    if (empty($image)) {
    try {
        $uploader = new Varien_File_Uploader('images');

        // Any extention would work
        $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));


        $path = Mage::getBaseDir('media') . DS . 'authors' . DS;
        $img = $uploader->save($path, $_FILES['images']['name'][$key]);
    } catch (Exception $e) {
        echo $e->getMessage();

1 Answer 1


this is the expected code

$uploader = new Varien_File_Uploader(
    'name' => $_FILES['images']['name'][$key],
    'type' => $_FILES['images']['type'][$key],
    'tmp_name' => $_FILES['images']['tmp_name'][$key],
    'error' => $_FILES['images']['error'][$key],
    'size' => $_FILES['images']['size'][$key]
  • What is the $key in this? Jun 24, 2016 at 12:19
  • I tried above code but only one file is uploaded.can you please help Mar 1, 2017 at 14:28
  • 1
    @J.Jenith: perhaps, you have got only one item in $_FILES. can you verify the size of array received at your end? Mar 1, 2017 at 15:01
  • Thanks , yes i got one item but i upload multiple files jQuery('#front_files input[type="file"]').each(function(index){ var file_id = jQuery(this).attr("id"); file_data = jQuery(this)[0].files; // get multiple files from input file if(file_data.length >0 ){ formdata.append('upload_artworks', file_data[0]); // we can put more than 1 image file } }); Mar 2, 2017 at 7:30
  • 1
    @J.Jenith: so this is clearly a JavaScript issue where in your data:{collection: files} you have just one item. Its better you should ask a new question for the same. Mar 2, 2017 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.