Wednesday, April 27, 2016

Magento- upload multiple files with Varien_File_Uploader

Topic 1:  upload  file with Varien_File_Uploader .
Topic 2:  How can I upload image using Varien_File_Uploader in magento?
Topic 3:  Upload image using default magento function.

We can find above topic's solution in below code.
 

 if(isset($_FILES['add_image']['name']) && $_FILES['add_image']['name'] != '') {
            try {
                /* Starting upload */
                $uploader = new Varien_File_Uploader('add_image');

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

                $uploader->setFilesDispersion(true);

                // We set media as the upload dir
                $path = Mage::getBaseDir('media') . DS . 'projectphoto' . DS . 'image' . DS;
                $uploader->save($path, $_FILES['add_image']['name'] );
                echo '-->'.$img_name = $uploader->getUploadedFileName();
            } catch (Exception $e) {

            }
        }

No comments :

Post a Comment