本文整理汇总了PHP中Mage_Core_Model_File_Uploader::setAllowedExtensions方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Core_Model_File_Uploader::setAllowedExtensions方法的具体用法?PHP Mage_Core_Model_File_Uploader::setAllowedExtensions怎么用?PHP Mage_Core_Model_File_Uploader::setAllowedExtensions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Core_Model_File_Uploader
的用法示例。
在下文中一共展示了Mage_Core_Model_File_Uploader::setAllowedExtensions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: afterSave
/**
* After save
*
* @param Varien_Object $object
* @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Image
*/
public function afterSave($object)
{
$value = $object->getData($this->getAttribute()->getName());
if (is_array($value) && !empty($value['delete'])) {
$object->setData($this->getAttribute()->getName(), '');
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
return;
}
try {
$uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName());
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
$uploader->addValidateCallback(Mage_Core_Model_File_Validator_Image::NAME, new Mage_Core_Model_File_Validator_Image(), "validate");
$uploader->save(Mage::getBaseDir('media') . '/catalog/product');
$fileName = $uploader->getUploadedFileName();
if ($fileName) {
$object->setData($this->getAttribute()->getName(), $fileName);
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
}
} catch (Exception $e) {
return $this;
}
return $this;
}
示例2: uploadAction
public function uploadAction()
{
try {
$pattern = "/([0-9]+\\.[0-9]+\\.[0-9]+)(?:\\.[0-9]+)*/";
$matches = array();
preg_match($pattern, Mage::getVersion(), $matches);
if (version_compare($matches[1], '1.5.1', '<')) {
$uploader = new Varien_File_Uploader('image');
} else {
$uploader = new Mage_Core_Model_File_Uploader('image');
}
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->addValidateCallback('catalog_product_image', Mage::helper('catalog/image'), 'validateUploadFile');
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
$result = $uploader->save($this->getMagicslideshowBaseMediaPath());
/**
* Workaround for prototype 1.7 methods "isJSON", "evalJSON" on Windows OS
*/
$result['tmp_name'] = str_replace(DS, "/", $result['tmp_name']);
$result['path'] = str_replace(DS, "/", $result['path']);
$result['url'] = $this->getMagicslideshowMediaUrl($result['file']);
$result['file'] = $result['file'];
$result['cookie'] = array('name' => session_name(), 'value' => $this->_getSession()->getSessionId(), 'lifetime' => $this->_getSession()->getCookieLifetime(), 'path' => $this->_getSession()->getCookiePath(), 'domain' => $this->_getSession()->getCookieDomain());
} catch (Exception $e) {
$result = array('error' => $e->getMessage(), 'errorcode' => $e->getCode());
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
示例3: saveFlag
public function saveFlag(Varien_Event_Observer $observer)
{
$store = $observer->getEvent()->getStore();
$data = Mage::app()->getRequest()->getPost();
if (!empty($_FILES)) {
if (isset($_FILES['flag']['name']) && $_FILES['flag']['name'] != '') {
try {
$uploader = new Mage_Core_Model_File_Uploader('flag');
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png', 'svg'));
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(false);
$dirPath = Mage::getBaseDir('media') . DS . 'store_flag';
$result = $uploader->save($dirPath, $_FILES['flag']['name']);
} catch (Exception $e) {
Mage::log($e->getMessage());
}
$store->setFlag('store_flag' . $result['file']);
} elseif (isset($data['flag']) && is_array($data['flag'])) {
if (isset($data['flag']['delete']) && $data['flag']['delete'] === "1") {
$store->setFlag(null);
} else {
$store->setFlag($data['flag']['value']);
}
}
}
}
示例4: afterSave
/**
* After attribute is saved upload file to media
* folder and save it to its associated product.
*
* @param Mage_Catalog_Model_Product $object
* @return Jvs_FileAttribute_Model_Attribute_Backend_File
*/
public function afterSave($object)
{
$value = $object->getData($this->getAttribute()->getName());
if (is_array($value) && !empty($value['delete'])) {
$object->setData($this->getAttribute()->getName(), '');
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
return;
}
try {
$uploadedFile = new Varien_Object();
$uploadedFile->setData('name', $this->getAttribute()->getName());
$uploadedFile->setData('allowed_extensions', array('jpg', 'jpeg', 'gif', 'png', 'tif', 'tiff', 'mpg', 'mpeg', 'mp3', 'wav', 'pdf', 'txt'));
Mage::dispatchEvent('jvs_fileattribute_allowed_extensions', array('file' => $uploadedFile));
$uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName());
$uploader->setAllowedExtensions($uploadedFile->getData('allowed_extensions'));
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
$uploader->save(Mage::getBaseDir('media') . '/catalog/product');
} catch (Exception $e) {
return $this;
}
$fileName = $uploader->getUploadedFileName();
if ($fileName) {
$object->setData($this->getAttribute()->getName(), $fileName);
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
}
return $this;
}
示例5: afterSave
/**
* Save uploaded file and set its name to category
*
* @param Varien_Object $object
*/
public function afterSave($object)
{
$value = $object->getData($this->getAttribute()->getName());
if (is_array($value) && !empty($value['delete'])) {
$object->setData($this->getAttribute()->getName(), '');
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
return;
}
$path = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category' . DS;
try {
$uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName());
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->setAllowRenameFiles(true);
$uploader->addValidateCallback(Mage_Core_Model_File_Validator_Image::NAME, new Mage_Core_Model_File_Validator_Image(), "validate");
$result = $uploader->save($path);
$object->setData($this->getAttribute()->getName(), $result['file']);
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
} catch (Exception $e) {
if ($e->getCode() != Mage_Core_Model_File_Uploader::TMP_NAME_EMPTY) {
Mage::logException($e);
}
/** @TODO ??? */
return;
}
}
示例6: uploadAction
public function uploadAction()
{
try {
$uploader = new Mage_Core_Model_File_Uploader('file');
$uploader->setAllowedExtensions();
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
$result = $uploader->save(
Mage::getSingleton('catalog/product_media_config')->getBaseTmpMediaPath()
);
$result['url'] = Mage::getSingleton('catalog/product_media_config')->getTmpMediaUrl($result['file']);
$result['cookie'] = array(
'name' => session_name(),
'value' => $this->_getSession()->getSessionId(),
'lifetime' => $this->_getSession()->getCookieLifetime(),
'path' => $this->_getSession()->getCookiePath(),
'domain' => $this->_getSession()->getCookieDomain()
);
} catch (Exception $e) {
$result = array(
'error' => $e->getMessage(),
'errorcode' => $e->getCode());
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
示例7: importAction
public function importAction()
{
try {
$productId = $this->getRequest()->getParam('id');
$fileName = $this->getRequest()->getParam('Filename');
$path = Mage::getBaseDir('var') . DS . 'import' . DS;
$uploader = new Mage_Core_Model_File_Uploader('file');
$uploader->setAllowedExtensions(array('csv'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$result = $uploader->save($path, $fileName);
$io = new Varien_Io_File();
$io->open(array('path' => $path));
$io->streamOpen($path . $fileName, 'r');
$io->streamLock(true);
while ($data = $io->streamReadCsv(';', '"')) {
if ($data[0]) {
$model = Mage::getModel('giftcards/pregenerated')->load($data[0], 'card_code');
if ($model->getId()) {
continue;
}
$model->setCardCode($data[0]);
$model->setCardStatus(1);
$model->setProductId($productId);
$model->save();
} else {
continue;
}
}
} catch (Exception $e) {
$result = array('error' => $e->getMessage(), 'errorcode' => $e->getCode());
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
示例8: saveFields
public function saveFields(Varien_Event_Observer $observer)
{
$model = $observer->getEvent()->getPage();
$request = $observer->getEvent()->getRequest();
if (isset($_FILES['image']['name']) && $_FILES['image']['name'] != '') {
try {
$uploader = new Mage_Core_Model_File_Uploader('image');
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(false);
$dirPath = Mage::getBaseDir('media') . DS . 'page' . DS;
$result = $uploader->save($dirPath, $_FILES['image']['name']);
} catch (Exception $e) {
Mage::log($e->getMessage());
}
$model->setImage('page/' . $result['file']);
} else {
$data = $request->getPost();
if (isset($data['image']) && isset($data['image']['delete']) && $data['image']['delete'] == 1) {
$model->setImage(false);
} elseif (isset($data['image']) && is_array($data['image'])) {
$model->setImage($data['image']['value']);
}
}
if (empty($model->getPageType())) {
$model->setPageType(null);
}
}
示例9: afterSave
/**
* Save uploaded file and set its name to category
*
* @param Varien_Object $object
* @return Mage_Catalog_Model_Category_Attribute_Backend_Image
*/
public function afterSave($object)
{
$value = $object->getData($this->getAttribute()->getName());
// if no image was set - nothing to do
if (empty($value) && empty($_FILES)) {
return $this;
}
if (is_array($value) && !empty($value['delete'])) {
$object->setData($this->getAttribute()->getName(), '');
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
return $this;
}
$path = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category' . DS;
try {
$uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName());
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->setAllowRenameFiles(true);
$result = $uploader->save($path);
$object->setData($this->getAttribute()->getName(), $result['file']);
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
} catch (Exception $e) {
if ($e->getCode() != Mage_Core_Model_File_Uploader::TMP_NAME_EMPTY) {
Mage::logException($e);
}
/** @TODO ??? */
}
return $this;
}
示例10: _beforeSave
/**
* Save uploaded file before saving config value
*
* @return Mage_Adminhtml_Model_System_Config_Backend_File
*/
protected function _beforeSave()
{
$value = $this->getValue();
if (is_array($value) && !empty($value['delete'])) {
$this->setValue('');
}
if ($_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value']) {
$uploadDir = $this->_getUploadDir();
try {
$file = array();
$tmpName = $_FILES['groups']['tmp_name'];
$file['tmp_name'] = $tmpName[$this->getGroupId()]['fields'][$this->getField()]['value'];
$name = $_FILES['groups']['name'];
$file['name'] = $name[$this->getGroupId()]['fields'][$this->getField()]['value'];
$uploader = new Mage_Core_Model_File_Uploader($file);
$uploader->setAllowedExtensions($this->_getAllowedExtensions());
$uploader->setAllowRenameFiles(true);
$result = $uploader->save($uploadDir);
} catch (Exception $e) {
Mage::throwException($e->getMessage());
return $this;
}
$filename = $result['file'];
if ($filename) {
if ($this->_addWhetherScopeInfo()) {
$filename = $this->_prependScopeInfo($filename);
}
$this->setValue($filename);
}
}
return $this;
}
示例11: saveCustomOptionImages
public function saveCustomOptionImages(Varien_Event_Observer $observer)
{
if (!isset($_FILES) || empty($_FILES) || !isset($_FILES['product'])) {
return;
}
$product = $observer->getEvent()->getProduct();
$productData = $observer->getEvent()->getRequest()->getPost('product');
if (isset($productData['options']) && !$product->getOptionsReadonly()) {
if (isset($_FILES['product']['name']['options'])) {
$images = array();
foreach ($_FILES['product'] as $attr => $options) {
if (isset($options['options'])) {
foreach ($options['options'] as $optionId => $values) {
if (isset($values['values'])) {
foreach ($values['values'] as $valueId => $data) {
$key = 'option_' . $optionId . '_value_' . $valueId;
if (!isset($images[$key])) {
$images[$key] = array();
}
$images[$key][$attr] = $data['image'];
}
}
}
}
}
foreach ($images as $imageName => $imageData) {
$_FILES[$imageName] = $imageData;
}
}
foreach ($productData['options'] as $optionId => $option) {
if (!empty($option['values'])) {
foreach ($option['values'] as $valueId => $value) {
$imageName = 'option_' . $optionId . '_value_' . $valueId;
if (!isset($_FILES[$imageName]) || empty($_FILES[$imageName]) || $_FILES[$imageName]['name'] === "") {
continue;
}
try {
$uploader = new Mage_Core_Model_File_Uploader($imageName);
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(false);
$dirPath = Mage::getBaseDir('media') . DS . 'custom_option_image' . DS;
$result = $uploader->save($dirPath, $_FILES[$imageName]['name']);
} catch (Exception $e) {
Mage::log($e->getMessage());
}
$productData['options'][$optionId]['values'][$valueId]['image'] = 'custom_option_image/' . $result['file'];
$product->setCanSaveCustomOptions(true);
}
}
}
$product->setProductOptions($productData['options']);
}
}
示例12: saveAction
public function saveAction()
{
// check if data sent
if ($data = $this->getRequest()->getPost()) {
if (!empty($_FILES)) {
foreach ($_FILES as $name => $fileData) {
if (isset($fileData['name']) && $fileData['name'] != '') {
try {
$uploader = new Mage_Core_Model_File_Uploader($name);
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png', 'svg'));
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(false);
$dirPath = Mage::getBaseDir('media') . DS . 'block' . DS;
$result = $uploader->save($dirPath, $fileData['name']);
} catch (Exception $e) {
Mage::log($e->getMessage());
}
$data[$name] = 'block/' . $result['file'];
} elseif (isset($data[$name]) && is_array($data[$name])) {
$data[$name] = $data[$name]['value'];
}
}
}
$data = $this->_filterDates($data, array('active_from', 'active_to'));
//init model and set data
$model = Mage::getModel('block/block');
$model->setData($data);
// try to save it
try {
// save the data
$model->save();
// display success message
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('block')->__('The block has been saved.'));
// clear previously saved data from session
Mage::getSingleton('adminhtml/session')->setFormData(false);
// check if 'Save and Continue'
if ($this->getRequest()->getParam('back')) {
$this->_redirect('*/*/edit', array('block_id' => $model->getId()));
return;
}
// go to grid
$this->_redirect('*/*/');
return;
} catch (Mage_Core_Exception $e) {
$this->_getSession()->addError($e->getMessage());
} catch (Exception $e) {
$this->_getSession()->addException($e, Mage::helper('block')->__('An error occurred while saving the block.'));
}
$this->_getSession()->setFormData($data);
$this->_redirect('*/*/edit', array('block_id' => $this->getRequest()->getParam('block_id')));
return;
}
$this->_redirect('*/*/');
}
示例13: saveAction
public function saveAction()
{
$data = $this->getRequest()->getParams();
$uploader = new Mage_Core_Model_File_Uploader('file');
$uploader->setAllowedExtensions(array('csv'));
$uploader->setAllowRenameFiles(true);
$path = Mage::getBaseDir('var') . DS . 'import';
if (!file_exists($path)) {
mkdir($path, 0777);
}
try {
$result = $uploader->save($path);
$fullPath = $result['path'] . DS . $result['file'];
$csv = new Varien_File_Csv();
$data = $csv->getData($fullPath);
$items = array();
if (count($data) > 1) {
for ($i = 1; $i < count($data); $i++) {
$item = array();
for ($j = 0; $j < count($data[0]); $j++) {
if (isset($data[$i][$j]) && trim($data[$i][$j]) != '') {
$item[strtolower($data[0][$j])] = $data[$i][$j];
}
}
$items[] = $item;
}
}
$resource = Mage::getSingleton('core/resource');
$writeConnection = $resource->getConnection('core_write');
$table = $resource->getTableName('seo/redirect');
$table2 = $resource->getTableName('seo/redirect_store');
$i = 0;
foreach ($items as $item) {
pr($item);
if (!isset($item['url_from']) || !isset($item['url_to'])) {
continue;
}
$item = new Varien_Object($item);
$query = "REPLACE {$table} SET\n url_from = '" . addslashes($item->getUrlFrom()) . "',\n url_to = '" . addslashes($item->getUrlTo()) . "',\n is_redirect_only_error_page = '" . addslashes($item->getIsRedirectOnlyErrorPage()) . "',\n comments = '" . addslashes($item->getComments()) . "',\n is_active = '" . addslashes($item->getIsActive()) . "';\n REPLACE {$table2} SET\n store_id = 0,\n redirect_id = LAST_INSERT_ID();\n ";
$writeConnection->query($query);
$i++;
}
Mage::getSingleton('adminhtml/session')->addSuccess('' . $i . ' records were inserted or updated');
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
$this->_redirect('*/*/');
}
示例14: saveImage
/**
* Does some saving action
*
* @param [type] $name name of the input field
*
* @return [string | false] filename or false on exception
*/
public function saveImage($name)
{
$path = $this->getFullImagesDir();
try {
$uploader = new Mage_Core_Model_File_Uploader($name);
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->setAllowRenameFiles(true);
$result = $uploader->save($path);
return $result['file'];
} catch (Exception $e) {
if ($e->getCode() != Mage_Core_Model_File_Uploader::TMP_NAME_EMPTY) {
Mage::logException($e);
}
return;
}
}
示例15: loadAction
public function loadAction()
{
$request = new Varien_Object($this->getRequest()->getParams());
if ($request && $request->getKey()) {
$uploader = new Mage_Core_Model_File_Uploader('file');
$allowed = Mage::getSingleton('cms/wysiwyg_images_storage')->getAllowedExtensions('image');
$uploader->setAllowedExtensions($allowed);
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(false);
$result = $uploader->save(Mage::helper('cms/wysiwyg_images')->getCurrentPath());
$imageUrl = sprintf('/media/%s/%s', Mage_Cms_Model_Wysiwyg_Config::IMAGE_DIRECTORY, $result['file']);
$array = array('filelink' => $imageUrl, 'filename' => $_FILES['file']['name']);
echo stripslashes(json_encode($array));
exit;
}
}