本文整理汇总了PHP中Mage_Core_Model_File_Uploader::setAllowRenameFiles方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Core_Model_File_Uploader::setAllowRenameFiles方法的具体用法?PHP Mage_Core_Model_File_Uploader::setAllowRenameFiles怎么用?PHP Mage_Core_Model_File_Uploader::setAllowRenameFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Core_Model_File_Uploader
的用法示例。
在下文中一共展示了Mage_Core_Model_File_Uploader::setAllowRenameFiles方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例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: 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: 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));
}
示例5: 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;
}
示例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: 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));
}
示例8: 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));
}
示例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: 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']);
}
}
}
}
示例11: 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;
}
示例12: _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;
}
示例13: 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;
}
}
示例14: 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']);
}
}
示例15: 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('*/*/');
}