php - upload multiple files with Varien_File_Uploader -


this question related previous question i'd created tab form in admin using template file. 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>     <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>                     <td class="label">                         <span class="remove">remove</span>                     </td>                 </tr>             </table>             <input type="button" class="add" value="add image"/>         </div>     </div> </div>  <script>     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>" +                     "</tr>";             jquery(wrapper).find('.remove').on('click', function() {                 jquery(this).parent('.wrapper-tr').remove();             });             jquery(wrapper).appendto('.container');         });         jquery('.container').on('click', 'span.remove', function() {             if (jquery('.wrapper-tr').length > 1) {                 jquery(this).parents('.wrapper-tr').remove();             } else {                 alert('at least 1 image need selected');             }         });     }); </script> 

for uploading multiple files.

but input type name images[] that's why in controller's saveaction() i'm unable upload file using varien_file_uploader as:

$uploader = new varien_file_uploader('images'); 

what value should pass in varien_file_uploader constructor in order able upload file?

update
tried logging , found warning:

warning: file_exists() expects parameter 1 valid path, array given in /var/www/mageqb/lib/varien/file/uploader.php on line 150

code in controller is:

foreach ($_files['images']['name'] $key => $image) {     mage::log('looping');     if (empty($image)) {         mage::log('continue');         continue;     }     try {         mage::log('uploading');         /* starting upload */         $uploader = new varien_file_uploader('images');          // extention work         $uploader->setallowedextensions(array('jpg', 'jpeg', 'gif', 'png'));         $uploader->setallowrenamefiles(true);          // set file upload mode         // false -> file directly in specified folder         // true -> file in product folders         //  (file.jpg go in /media/f/i/file.jpg)         $uploader->setfilesdispersion(false);          // set media upload dir         $path = mage::getbasedir('media') . ds . 'authors' . ds;         $img = $uploader->save($path, $_files['images']['name'][$key]);         mage::log($img['file']);     } catch (exception $e) {         echo $e->getmessage();         mage::log($e->getmessage());     } } 

this expected code

$uploader = new varien_file_uploader(         array(     '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]         ) ); 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -