本文整理汇总了PHP中Mage_Core_Model_File_Uploader类的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Core_Model_File_Uploader类的具体用法?PHP Mage_Core_Model_File_Uploader怎么用?PHP Mage_Core_Model_File_Uploader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mage_Core_Model_File_Uploader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: 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));
}
开发者ID:netz98,项目名称:N98_InfoFiles,代码行数:27,代码来源:FilesController.php
示例2: _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;
}
开发者ID:natxetee,项目名称:magento2,代码行数:37,代码来源:File.php
示例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);
}
}
开发者ID:outeredge,项目名称:edge-magento-module-pages,代码行数:28,代码来源:Page.php
示例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);
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));
}
开发者ID:relue,项目名称:magento2,代码行数:30,代码来源:FileController.php
示例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;
}
}
开发者ID:lynxtdc,项目名称:aromaworks,代码行数:30,代码来源:Image.php
示例6: 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;
}
开发者ID:natxetee,项目名称:magento2,代码行数:34,代码来源:Image.php
示例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));
}
开发者ID:enjoy2000,项目名称:gemz,代码行数:34,代码来源:ProductController.php
示例8: 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));
}
开发者ID:cewolf2002,项目名称:magento,代码行数:35,代码来源:FileController.php
示例9: 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']);
}
}
}
}
开发者ID:outeredge,项目名称:edge-magento-module-storeflag,代码行数:26,代码来源:Store.php
示例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;
}
开发者ID:riker09,项目名称:EasyTemplate,代码行数:32,代码来源:File.php
示例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']);
}
}
开发者ID:outeredge,项目名称:edge-magento-module-customoptionimage,代码行数:54,代码来源:Product.php
示例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('*/*/');
}
开发者ID:outeredge,项目名称:edge-magento-module-block,代码行数:54,代码来源:BlockController.php
示例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('*/*/');
}
开发者ID:technomagegithub,项目名称:olgo.nl,代码行数:48,代码来源:RedirectimportController.php
示例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;
}
}
开发者ID:AlexanderParker,项目名称:Doghouse_Carousel,代码行数:23,代码来源:Data.php
示例15: getFiles
/**
* Count files recursively for given directory
*
* @param string $directory
* @param array $files
* @param int $level
* @param string $sku
*
* @return array
*/
public function getFiles($directory, $files = array(), $level = 0, $sku = '')
{
$level++;
$handle = opendir($directory);
while ($file = readdir($handle)) {
if ($file != "." && $file != ".." && $file != ".DS_Store") {
if (is_dir($directory . DS . $file)) {
if ($level == 1) {
$sku = $file;
$files[$sku] = array();
}
$files = $this->getFiles($directory . DS . $file, $files, $level, $sku);
if (isset($files[$sku])) {
if (!count($files[$sku])) {
unset($files[$sku]);
}
}
} else {
$extension = pathinfo($directory . DS . $file, PATHINFO_EXTENSION);
$name = strtolower($sku . '-' . (count($files[$sku]) + 1) . '.' . $extension);
$fileName = Mage_Core_Model_File_Uploader::getCorrectFileName($name);
$path = Mage_Core_Model_File_Uploader::getDispretionPath($fileName);
$fileName = $path . DS . $fileName;
if (empty($files[$sku][$directory])) {
$files[$sku][$directory] = array('directory' => $directory . DS, 'file' => $file, 'name' => $fileName);
}
ksort($files[$sku]);
}
}
}
closedir($handle);
return $files;
}
开发者ID:nocturnalfrog,项目名称:PIMGento,代码行数:43,代码来源:Data.php
示例16: 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;
}
}
开发者ID:ngreimel,项目名称:mci,代码行数:16,代码来源:MgtamazingwysiwygController.php
示例17: 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('seoautolink/link');
$table2 = $resource->getTableName('seoautolink/link_store');
$i = 0;
foreach ($items as $item) {
if (!isset($item['keyword'])) {
continue;
}
$item = new Varien_Object($item);
$query = "REPLACE {$table} SET\n keyword = '" . addslashes($item->getKeyword()) . "',\n url = '" . addslashes($item->getUrl()) . "',\n url_title = '" . addslashes($item->getUrlTitle()) . "',\n url_target = '" . addslashes($item->getUrlTarget()) . "',\n is_nofollow = '" . (int) $item->getIsNofollow() . "',\n max_replacements = '" . (int) $item->getMaxReplacements() . "',\n sort_order = '" . (int) $item->getSortOrder() . "',\n occurence = '" . (int) $item->getOccurence() . "',\n is_active = '" . (int) $item->getIsActive() . "',\n created_at = '" . now() . "',\n updated_at = '" . now() . "';\n REPLACE {$table2} SET\n store_id = '" . (int) $item->getStoreId() . "',\n link_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('*/*/');
}
开发者ID:technomagegithub,项目名称:olgo.nl,代码行数:47,代码来源:ImportController.php
示例18: _beforeSave
/**
* Save uploaded file before saving config value
*
* @return Mage_Adminhtml_Model_System_Config_Backend_File
*/
protected function _beforeSave()
{
/*
print 'GroupID = '.$this->getGroupId().'<br>Field = '.$this->getField();
print "<pre>";
print_r($_FILES);
print "</pre>";
die;
*/
$value = $this->getValue();
if ($_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value']) {
//$uploadDir = $this->_getUploadDir();
$uploadDir = Mage::getBaseDir('media') . DIRECTORY_SEPARATOR . 'productvideos' . DIRECTORY_SEPARATOR;
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'];
/* extra code added to add time stamp to file name to get latest on top */
$file['name'] = date('YmdHis') . '_' . $file['name'];
$uploader = new Mage_Core_Model_File_Uploader($file);
$uploader->setAllowedExtensions($this->_getAllowedExtensions());
$uploader->setAllowRenameFiles(true);
$uploader->addValidateCallback('size', $this, 'validateMaxSize');
$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);
}
} else {
if (is_array($value) && !empty($value['delete'])) {
$this->setValue('');
} else {
$this->unsValue();
}
}
return $this;
}
开发者ID:sagmahajan,项目名称:aswan_release,代码行数:51,代码来源:File.php
示例19: _afterSave
public function _afterSave()
{
if (empty($_FILES['groups']['tmp_name']['purchaseorder']['fields']['paid_icon']['value'])) {
return $this;
}
try {
$_FILES['paid_icon'] = array('name' => $_FILES['groups']['name']['purchaseorder']['fields']['paid_icon']['value'], 'type' => $_FILES['groups']['type']['purchaseorder']['fields']['paid_icon']['value'], 'tmp_name' => $_FILES['groups']['tmp_name']['purchaseorder']['fields']['paid_icon']['value'], 'error' => $_FILES['groups']['error']['purchaseorder']['fields']['paid_icon']['value'], 'size' => $_FILES['groups']['size']['purchaseorder']['fields']['paid_icon']['value']);
$path = Mage::helper('emjainteractive_purchaseordermanagement')->getIconMediaPath();
$uploader = new Mage_Core_Model_File_Uploader('paid_icon');
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->setAllowRenameFiles(false);
$result = $uploader->save($path);
} catch (Exception $e) {
Mage::logException($e);
throw new Exception($e);
}
}
开发者ID:flintdigital,项目名称:mage-mod-ar-po-emja,代码行数:17,代码来源:Icon.php
示例20: _beforeSave
/**
* Return the root part of directory path for uploading
*
* @var string
* @return string
*/
protected function _beforeSave()
{
$value = $this->getValue();
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'];
//Check exists
if (file_exists($uploadDir . DS . $file['name'])) {
$msg = "+ " . Mage::helper('jmbasetheme')->__("Image with named %s was existed", $file['name']);
Mage::getSingleton('core/session')->addNotice($msg);
return $this;
} else {
$uploader = new Mage_Core_Model_File_Uploader($file);
$uploader->setAllowedExtensions($this->_getAllowedExtensions());
$uploader->setAllowRenameFiles(true);
$maxImageSize = 2 * 1024;
//2MB
$this->setMaxUploadFileSize($maxImageSize);
$uploader->addValidateCallback('size', $this, 'validateMaxSize');
$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);
}
} else {
if (is_array($value) && !empty($value['delete'])) {
$this->setValue('');
} else {
$this->unsValue();
}
}
return $this;
}
开发者ID:kozinthetdbp,项目名称:megamall,代码行数:52,代码来源:Image.php
注:本文中的Mage_Core_Model_File_Uploader类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论