//save softwarefile start
try{
    if((bool)$data['softwarefile']['delete']==1) {
        if ($data['softwarefile']['value'] != ''){
            $this->removeFile($data['softwarefile']['value']);
        }
        $data['softwarefile']='';

    }
    else {
        unset($data['softwarefile']);
        if (isset($_FILES)){
            if ($_FILES['softwarefile']['name']) {
                if($this->getRequest()->getParam("id")){
                    $model = Mage::getModel("usermanuals/usermanuals")->load($this->getRequest()->getParam("id"));
                    if($model->getData('softwarefile')){
                            $this->removeFile($model->getData('softwarefile'));
                    }
                }
                $path = Mage::getBaseDir('media') . DS.'usermanuals';
                $uploader = new Varien_File_Uploader('softwarefile');
                $uploader->setAllowedExtensions(array('exe', 'zip',));
                $uploader->setAllowCreateFolders(true);
                $uploader->setAllowRenameFiles(false);
                $uploader->setFilesDispersion(true);
                $destFile = $path.DS.$_FILES['softwarefile']['name'];
                $filename = $uploader->getNewFileName($destFile);
                $uploader->save($path, $filename);
                
                $data['softwarefile'] = 'usermanuals'.$uploader->getUploadedFileName();
            }
        }
    }

} catch (Exception $e) {
    Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
    $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
    return;
}
//save softwarefile end

Categories: Magento

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *