Upload files

Tweet, share & co

tweet fb share g+ share

Tags


Description

How to upload files in magento

Code

    if (isset($_FILES['logo']['name']) && $_FILES['logo']['name'] != '') {  
        try {  
            $uploader = new Varien_File_Uploader('logo');  
            $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));  
            $uploader->setAllowRenameFiles(false);  
            $uploader->setFilesDispersion(false);  
            $path = Mage::getBaseDir('media') . DS;  
            // $path = Mage::getBaseDir('media') . DS . 'logo' . DS;  
            $logoName = $_FILES['logo']['name'];  
            $uploader->save($path, $logoName);  
        
        } catch (Exception $e) {  
        
        }  
    }