本文整理汇总了PHP中Varien_File_Uploader::getFileExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_File_Uploader::getFileExtension方法的具体用法?PHP Varien_File_Uploader::getFileExtension怎么用?PHP Varien_File_Uploader::getFileExtension使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_File_Uploader
的用法示例。
在下文中一共展示了Varien_File_Uploader::getFileExtension方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uploadAndSaveImages
/**
* upload and save the option images (after attribute save)
* @access public
* @param $observer
* @return self
* @author Emil [carco] Sirbu <emil.sirbu@gmail.com>
*/
public function uploadAndSaveImages($observer)
{
$action = $observer->getEvent()->getControllerAction();
if (!$action instanceof Mage_Adminhtml_Catalog_Product_AttributeController) {
return $this;
}
$request = $action->getRequest();
$attribute_id = $request->getParam('attribute_id');
if (!$attribute_id) {
return $this;
}
$session = Mage::getSingleton('adminhtml/session');
if ($session->getAttributeData()) {
//there was error when saving attribute, do nothing
$session->addError(Mage::helper('easylife_switcher/optimage')->__('No attribute option image(s) was saved'));
return $this;
}
$options = $request->getParam('option');
if (empty($options['value'])) {
//do nothing
return $this;
}
//images marked to delete
$delete = $action->getRequest()->getPost('delete');
$success = 0;
$deleted = 0;
$destinationFolder = Mage::helper('easylife_switcher/optimage')->getImageBaseDir();
$toInsert = array();
$toDelete = array();
$hashCodes = $request->getPost('hashcode');
foreach ($options['value'] as $option_id => $values) {
$option_id = (int) $option_id;
if ($option_id <= 0) {
continue;
}
//remove actual images at user request (or new file is uploaded) or if option was removed ([delete][<option_id>] = 1)
if (!empty($delete[$option_id]) || !empty($options['delete'][$option_id]) || !empty($_FILES['image_' . $option_id]['name'])) {
foreach ($this->_allowedExt as $ext) {
$file = $destinationFolder . DS . $option_id . '.' . $ext;
if (file_exists($file)) {
$deleted++;
@unlink($file);
}
}
}
if (!empty($_FILES['image_' . $option_id]['name']) && empty($options['delete'][$option_id])) {
try {
$uploader = new Varien_File_Uploader('image_' . $option_id);
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$uploader->setAllowCreateFolders(true);
$uploader->setAllowedExtensions($this->_allowedExt);
$result = $uploader->save($destinationFolder, $option_id . '.' . strtolower($uploader->getFileExtension()));
$success++;
} catch (Exception $e) {
$session->addError($label . ' [image_' . $option_id . ']: ' . $e->getMessage());
}
}
//insert hash codes
if (is_array($hashCodes)) {
if (isset($hashCodes[$option_id])) {
if (strlen(trim($hashCodes[$option_id])) > 0) {
$toInsert[] = array('option_id' => $option_id, 'hashcode' => $hashCodes[$option_id]);
} else {
$toDelete[] = $option_id;
}
}
}
}
if (count($toInsert)) {
Mage::getResourceModel('easylife_switcher/hashcode')->insertValues($toInsert);
}
if (count($toDelete)) {
Mage::getResourceModel('easylife_switcher/hashcode')->deleteValues($toDelete);
}
if ($deleted) {
$session->addSuccess(Mage::helper('easylife_switcher/optimage')->__('%s attribute option image(s) deleted', $deleted));
}
if ($success) {
$session->addSuccess(Mage::helper('easylife_switcher/optimage')->__('%s attribute option image(s) uploaded', $success));
}
if ($success || $deleted) {
//clean cache
Mage::helper('easylife_switcher/optimage')->cleanCache();
}
}