本文整理汇总了PHP中Mage_Core_Model_File_Uploader::setFilesDispersion方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Core_Model_File_Uploader::setFilesDispersion方法的具体用法?PHP Mage_Core_Model_File_Uploader::setFilesDispersion怎么用?PHP Mage_Core_Model_File_Uploader::setFilesDispersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Core_Model_File_Uploader
的用法示例。
在下文中一共展示了Mage_Core_Model_File_Uploader::setFilesDispersion方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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));
}
示例2: 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;
}
示例3: 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);
}
}
示例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: 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']);
}
}
}
}
示例6: uploadAction
/**
* Upload file controller action
*/
public function uploadAction()
{
$type = $this->getRequest()->getParam('type');
$tmpPath = '';
if ($type == 'samples') {
$tmpPath = Mage_Downloadable_Model_Sample::getBaseTmpPath();
} elseif ($type == 'links') {
$tmpPath = Mage_Downloadable_Model_Link::getBaseTmpPath();
} elseif ($type == 'link_samples') {
$tmpPath = Mage_Downloadable_Model_Link::getBaseSampleTmpPath();
}
$result = array();
try {
$uploader = new Mage_Core_Model_File_Uploader($type);
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
$result = $uploader->save($tmpPath);
/**
* 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']);
if (isset($result['file'])) {
$fullPath = rtrim($tmpPath, DS) . DS . ltrim($result['file'], DS);
Mage::helper('core/file_storage_database')->saveFile($fullPath);
}
$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: 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));
}
示例8: 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));
}
示例9: uploadAction
/**
* Upload file controller action
*/
public function uploadAction()
{
$type = $this->getRequest()->getParam('type');
$tmpPath = '';
if ($type == 'samples') {
$tmpPath = Mage_Downloadable_Model_Sample::getBaseTmpPath();
} elseif ($type == 'links') {
$tmpPath = Mage_Downloadable_Model_Link::getBaseTmpPath();
} elseif ($type == 'link_samples') {
$tmpPath = Mage_Downloadable_Model_Link::getBaseSampleTmpPath();
}
$result = array();
try {
$uploader = new Mage_Core_Model_File_Uploader($type);
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
$result = $uploader->save($tmpPath);
if (isset($result['file'])) {
$fullPath = rtrim($tmpPath, DS) . DS . ltrim($result['file'], DS);
Mage::helper('Mage_Core_Helper_File_Storage_Database')->saveFile($fullPath);
}
$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('Mage_Core_Helper_Data')->jsonEncode($result));
}
示例10: beforeFieldSave
public function beforeFieldSave($value, $oldValue)
{
$value = parent::beforeFieldSave($value, $oldValue);
$template = $this->getTemplate();
/** @var $fileHelper Webguys_Easytemplate_Helper_File */
$fileHelper = Mage::helper('easytemplate/file');
$destinationPath = $fileHelper->getDestinationFilePath($template->getGroupId(), $template->getId());
if ($oldValue && ($value && $oldValue != $value || $this->_deleteFile)) {
// Delete the old file
$oldFilePath = sprintf('%s/%s', $destinationPath, $oldValue);
if (file_exists($oldFilePath)) {
@unlink($oldFilePath);
}
}
if ($value) {
$fileHelper->createTmpPath($template->getGroupId(), $template->getId());
if ($this->uploadComplete()) {
$uploaderData = array('tmp_name' => $this->extractFilePostInformation('tmp_name'), 'name' => $value);
$uploader = new Mage_Core_Model_File_Uploader($uploaderData);
//$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png','pdf'));
$uploader->addValidateCallback('easytemplate_template_file', $fileHelper, 'validateUploadFile');
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$result = $uploader->save($destinationPath);
Mage::dispatchEvent('easytemplate_upload_file_after', array('result' => $result));
$value = $result['file'];
} else {
// TODO: Error handling
}
}
return $value;
}
示例11: 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('*/*/');
}
示例12: 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']);
}
}
示例13: 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;
}
}
示例14: saveCurrencyFlags
public function saveCurrencyFlags(Varien_Event_Observer $observer)
{
$currencyFlags = unserialize(Mage::getStoreConfig('currency/options/currencyflag', ""));
$deleteFlags = Mage::app()->getRequest()->getParam('delete_currency_flag', null);
if (!empty($deleteFlags)) {
foreach ($deleteFlags as $currency => $delete) {
unset($_FILES[$currency], $currencyFlags[$currency]);
}
}
$fileUpload = false;
foreach ($_FILES as $image) {
if (isset($image['name']) && $image['name'] !== '') {
$fileUpload = true;
}
}
if ($fileUpload) {
foreach ($_FILES as $currency => $image) {
if (isset($image['name']) && $image['name'] != '') {
try {
$uploader = new Mage_Core_Model_File_Uploader($currency);
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png', 'svg'));
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(false);
$dirPath = Mage::getBaseDir('media') . DS . 'currencyflag' . DS;
$result = $uploader->save($dirPath, $image['name']);
$currencyFlags[$currency] = 'currencyflag' . DS . $result['file'];
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
}
}
}
if (!empty($currencyFlags)) {
$config = array('value' => serialize($currencyFlags));
} else {
$config = array('inherit' => 1);
}
Mage::getModel('adminhtml/config_data')->setSection('currency')->setWebsite(null)->setStore(null)->setGroups(array('options' => array('fields' => array('currencyflag' => $config))))->save();
Mage::getSingleton('connect/session')->addSuccess(Mage::helper('adminhtml')->__('Custom currency flags were applied successfully.'));
}
示例15: uploadAction
public function uploadAction()
{
try {
$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(Mage::getSingleton('catalog/product_media_config')->getBaseTmpMediaPath());
/**
* 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'] = Mage::getSingleton('catalog/product_media_config')->getTmpMediaUrl($result['file']);
$result['file'] = $result['file'] . '.tmp';
$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));
}