magento 文件上传类
2016-10-21 17:46
387 查看
class Uploadimg extends Mage_Core_Helper_Abstract { protected $_supportedExtensions = array('jpg', 'JPG', 'png', 'PNG', 'gif', 'GIF','jpeg','JPEG'); protected $_file = null; protected $_baspath=null; public function getBasePath() { return $this->_baspath; } public function setBasePath($dir){ $this->_baspath=Mage::getBaseDir('media') . DS . $dir; } public function setFileData($fileData) { $this->_file = $fileData; } public function getFileData() { return $this->_file; } public function saveFile() { $uploadedFile = null; if ($fileData = $this->getFileData()) { $uploader = new Varien_File_Uploader($this->getFileData()); $uploader->setFilesDispersion(true); $uploader->setFilenamesCaseSensitivity(false); $uploader->setAllowRenameFiles(true); $uploader->setAllowedExtensions($this->_supportedExtensions); if(!is_null($this->getBasePath())) { 4000 $uploader->save($this->getBasePath(), $fileData['name']); $uploadedFile = $uploader->getUploadedFileName(); } } return $uploadedFile; } }