本文整理汇总了PHP中Varien_File_Uploader::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_File_Uploader::save方法的具体用法?PHP Varien_File_Uploader::save怎么用?PHP Varien_File_Uploader::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_File_Uploader
的用法示例。
在下文中一共展示了Varien_File_Uploader::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload
public function upload($optionId, $optionLabel, $productId)
{
$fieldName = 'image_' . $optionId;
if (empty($_FILES[$fieldName]['name'])) {
return $this;
}
$optionLabel = preg_replace('/[^A-Za-z0-9_\\-]/', '_', $optionLabel);
$imageName = $productId . '_' . $optionId . '_' . $optionLabel;
$imageName .= '_' . time();
// give unique names here
$imageName .= '.' . strtolower(substr(strrchr($_FILES[$fieldName]['name'], '.'), 1));
//upload an icon file
$uploader = new Varien_File_Uploader($fieldName);
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$uploader->save($this->_imagePath, $imageName);
$thumbSizes = Mage::helper('adjicon')->getThumbsSizes();
foreach ($thumbSizes as $thumbSize) {
$this->resize($imageName, $thumbSize);
}
// store new values in DB
$this->setOptionId($optionId);
$this->setProductId($productId);
$this->setFile($imageName);
$this->save();
}
示例2: uploadFile
public function uploadFile(&$someField, $code)
{
$multiple = is_array($_FILES['to_upload']['error']);
for ($i = 0; $i < sizeof($_FILES['to_upload']['error']); $i++) {
$error = $multiple ? $_FILES['to_upload']['error'][$i] : $_FILES['to_upload']['error'];
if ($error == UPLOAD_ERR_OK) {
try {
$fileName = $multiple ? $_FILES['to_upload']['name'][$i] : $_FILES['to_upload']['name'];
$fileName = Mage::helper('amorderattach/upload')->cleanFileName($fileName);
$uploader = new Varien_File_Uploader($multiple ? "to_upload[{$i}]" : 'to_upload');
$uploader->setFilesDispersion(false);
$fileDestination = Mage::helper('amorderattach/upload')->getUploadDir();
if (file_exists($fileDestination . $fileName)) {
$fileName = uniqid(date('ihs')) . $fileName;
}
$uploader->save($fileDestination, $fileName);
} catch (Exception $e) {
$this->addException($e, Mage::helper('amorderattach')->__('An error occurred while saving the file: ') . $e->getMessage());
}
if ('file' == Mage::app()->getRequest()->getPost('type')) {
$someField->setData($code, $fileName);
}
if ('file_multiple' == Mage::app()->getRequest()->getPost('type')) {
$fieldData = $someField->getData($code);
$fieldData = explode(';', $someField->getData($code));
$fieldData[] = $fileName;
$fieldData = implode(';', $fieldData);
$someField->setData($code, $fieldData);
}
}
}
}
示例3: saveAction
public function saveAction()
{
$data = $this->getRequest()->getPost();
if (isset($_FILES['bannerimage']['name']) and file_exists($_FILES['bannerimage']['tmp_name'])) {
try {
$uploader = new Varien_File_Uploader('bannerimage');
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
// or pdf or anything
$uploader->setAllowRenameFiles(false);
// setAllowRenameFiles(true) -> move your file in a folder the magento way
// setAllowRenameFiles(true) -> move your file directly in the $path folder
$uploader->setFilesDispersion(false);
$path = Mage::getBaseDir('media') . DS . 'footer_banner' . DS;
$uploader->save($path, $_FILES['bannerimage']['name']);
if ($data['position'] == 'left') {
$imgPath = $path . $_FILES['bannerimage']['name'];
$imageObj = new Varien_Image($imgPath);
$imageObj->constrainOnly(TRUE);
$imageObj->keepAspectRatio(TRUE);
$imageObj->resize(466, 521);
$imageObj->save($imgPath);
} else {
$imgPath = $path . $_FILES['bannerimage']['name'];
$imageObj = new Varien_Image($imgPath);
$imageObj->constrainOnly(TRUE);
$imageObj->keepAspectRatio(TRUE);
$imageObj->resize(269, 258);
$imageObj->save($imgPath);
}
$data['bannerimage'] = $_FILES['bannerimage']['name'];
$file_nm = str_replace(" ", "_", $_FILES['bannerimage']['name']);
$imgPath = Mage::getBaseUrl('media') . "footer_banner/" . $file_nm;
$data['filethumbgrid'] = '<img src="' . $imgPath . '" border="0" width="75" height="75" />';
} catch (Exception $e) {
}
}
$banner_id = $this->getRequest()->getParam('id');
if ($banner_id) {
$resource = Mage::getSingleton('core/resource');
$write = $resource->getConnection('core_write');
if ($file_nm) {
$file = "bannerimage = '" . $file_nm . "',";
} else {
$file = '';
}
if ($data['filethumbgrid']) {
$img_filed = "filethumbgrid='" . $data['filethumbgrid'] . "', ";
} else {
$img_filed = '';
}
$sql = "UPDATE banner SET block_id='" . $data['block_id'] . "'," . $file . $img_filed . "gender='" . $data['gender'] . "',link='" . $data['link'] . "',image_text='" . $data['image_text'] . "',position='" . $data['position'] . "' " . "WHERE banner_id = '" . $banner_id . "'";
$write->query($sql);
$message = 'Banner Settings updated !!';
} else {
Mage::getModel('banner/banner')->setBlockId($data['block_id'])->setBannerimage($file_nm)->setFilethumbgrid($data['filethumbgrid'])->setGender($data['gender'])->setImageText($data['image_text'])->setLink($data['link'])->setBanner_type('1')->setPosition($data['position'])->save();
$message = 'Banner Settings saved !!';
}
Mage::getSingleton('adminhtml/session')->addSuccess($message);
$this->_redirect('*/*/index');
}
示例4: upload
public function upload($attributeId, $attributeOptionInfo)
{
$fieldName = 'option_' . $attributeOptionInfo['option_id'];
if (empty($_FILES[$fieldName]['name'])) {
return $this;
}
// create a human readable name
$iconName = $attributeId . '_' . $attributeOptionInfo['option_id'] . '_';
// for better debug/maintenance
$iconName .= preg_replace('/[^a-z0-9]+/', '', strtolower($attributeOptionInfo['value']));
$iconName .= '_' . rand(0, 99);
// to prevent browser cache
$iconName .= '.' . strtolower(substr(strrchr($_FILES[$fieldName]['name'], '.'), 1));
// keep original extension
//upload an icon file
$uploader = new Varien_File_Uploader($fieldName);
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$uploader->save($this->_iconPath, $iconName);
// create and save thumbnail
$this->makeThumb($iconName);
// store new values in DB
$oldFile = $this->getFilename();
if ($oldFile) {
@unlink($this->_iconPath . $oldFile);
@unlink($this->_iconPath . 'l_' . $oldFile);
@unlink($this->_iconPath . 'pl_' . $oldFile);
@unlink($this->_iconPath . 'v_' . $oldFile);
@unlink($this->_iconPath . 'o_' . $oldFile);
}
$this->setOptionId($attributeOptionInfo['option_id']);
$this->setFilename($iconName);
$this->save();
}
示例5: 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 Varien_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('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));
}
示例6: 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 Varien_File_Uploader($this->getAttribute()->getName());
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->setAllowRenameFiles(true);
$result = $uploader->save($path);
$result['file'] = Mage::helper('core/file_storage_database')->saveUploadedFile($result);
$object->setData($this->getAttribute()->getName(), $result['file']);
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
} catch (Exception $e) {
if ($e->getCode() != Varien_File_Uploader::TMP_NAME_EMPTY) {
Mage::logException($e);
}
/** @TODO ??? */
return;
}
}
示例7: postAction
public function postAction()
{
if (!empty($_FILES)) {
$type = 'file';
if (isset($_FILES[$type]['name']) && $_FILES[$type]['name'] != '') {
try {
$uploadsDir = Mage::getBaseDir('upload');
$uploader = new Varien_File_Uploader($type);
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
$path = Mage::getBaseDir('media') . DS . 'upload';
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
$uploader->save($path, $_FILES[$type]['name']);
$filename = $uploader->getUploadedFileName();
$md5 = md5($filename);
$owner = Mage::getSingleton('customer/session')->getCustomerId() ? Mage::getSingleton('customer/session')->getCustomerId() : Mage::getSingleton('customer/session')->getSessionId();
Mage::getModel('xxx_catalog/upload')->setMd5($md5)->setFilename($filename)->setOwner($owner)->save();
$varienImage = new Varien_Image($uploadsDir . $filename);
$width = $varienImage->getOriginalWidth();
$height = $varienImage->getOriginalHeight();
$data = ['id' => $md5, 'width' => $width, 'height' => $height];
echo json_encode($data);
die;
} catch (Exception $e) {
Mage::log($e->getMessage(), null, $this->_logFile);
echo json_encode(['error' => $this->__($e->getMessage())]);
}
}
}
$this->getResponse()->setRedirect(Mage::getUrl('*/*/index'));
}
示例8: saveAction
/**
* Save form action
*/
public function saveAction()
{
if ($this->getRequest()->getPost()) {
try {
$data = $this->getRequest()->getPost();
if (isset($_FILES['testimonial_img']['name']) and file_exists($_FILES['testimonial_img']['tmp_name'])) {
$uploader = new Varien_File_Uploader('testimonial_img');
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$path = Mage::getBaseDir('media') . DS;
$uploader->save($path, $_FILES['testimonial_img']['name']);
$data['testimonial_img'] = $_FILES['testimonial_img']['name'];
} else {
if (isset($data['testimonial_img']['delete']) && $data['testimonial_img']['delete'] == 1) {
$data['testimonial_img'] = '';
} else {
unset($data['testimonial_img']);
}
}
$model = Mage::getModel('turnkeye_testimonial/testimonial');
$model->setData($data)->setTestimonialId($this->getRequest()->getParam('id'))->save();
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('turnkeye_testimonial')->__('Testimonial was successfully saved'));
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
return;
}
}
$this->_redirect('*/*/');
}
示例9: load
public function load()
{
if (!$_FILES) {
?>
<form method="POST" enctype="multipart/form-data">
File to upload: <input type="file" name="io_file"/> <input type="submit" value="Upload"/>
</form>
<?php
exit;
}
if (!empty($_FILES['io_file']['tmp_name'])) {
//$this->setData(file_get_contents($_FILES['io_file']['tmp_name']));
$uploader = new Varien_File_Uploader('io_file');
$uploader->setAllowedExtensions(array('csv', 'xml'));
$path = Mage::app()->getConfig()->getTempVarDir() . '/import/';
$uploader->save($path);
if ($uploadFile = $uploader->getUploadedFileName()) {
$fp = fopen($uploadFile, 'rb');
while ($row = fgetcsv($fp)) {
}
fclose($fp);
}
}
return $this;
}
示例10: afterSave
/**
* Save uploaded file and set its name to entity
*
* @param Goodahead_Etm_Model_Entity $object
* @return void
*/
public function afterSave($object)
{
parent::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 $this;
}
$path = Mage::getBaseDir('media') . DS . 'goodahead' . DS . 'etm' . DS . 'images' . DS . $object->getEntityTypeInstance()->getEntityTypeCode() . DS . $this->getAttribute()->getAttributeCode() . DS;
try {
$uploader = new Varien_File_Uploader($this->getAttribute()->getName());
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->setAllowRenameFiles(true);
$uploader->setAllowCreateFolders(true);
$uploader->setFilesDispersion(true);
$uploader->save($path);
$object->setData($this->getAttribute()->getName(), $uploader->getUploadedFileName());
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
} catch (Exception $e) {
if ($e->getCode() != Varien_File_Uploader::TMP_NAME_EMPTY) {
Mage::logException($e);
}
/** @TODO ??? */
return $this;
}
return $this;
}
示例11: _uploadSwatches
protected function _uploadSwatches()
{
$thePath = Mage::getBaseDir('media') . DS . 'colorselectorplus' . DS . 'swatches' . DS;
$deleteMe = Mage::app()->getRequest()->getPost('colorselectorplus_swatch_delete');
if ($deleteMe) {
foreach ($deleteMe as $optionId => $delete) {
if ($delete) {
@unlink($thePath . $optionId . '.jpg');
}
}
}
if (isset($_FILES['colorselectorplus_swatch']) && isset($_FILES['colorselectorplus_swatch']['error'])) {
foreach ($_FILES['colorselectorplus_swatch']['error'] as $optionId => $error) {
try {
$uploader = new Varien_File_Uploader('colorselectorplus_swatch[' . $optionId . ']');
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$uploader->save($thePath, $optionId . '.jpg');
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($this->__($e->getMessage()));
}
}
}
}
示例12: controllerPredispatch
public function controllerPredispatch()
{
if ($this->_getPathInfo() == 'catalog_product_action_attribute_save') {
$this->_unsetEmptyPositions();
if (!empty($_FILES)) {
$onSaleFiles = array("0" => "aw_os_product_image", "1" => "aw_os_category_image");
$path = AW_Onsale_Model_Entity_Attribute_Backend_Image::getUploadDirName();
$onSaleAllowedExt = AW_Onsale_Model_Entity_Attribute_Backend_Image::getAllowedImgExt();
foreach ($onSaleFiles as $file) {
if (isset($_FILES[$file])) {
try {
$uploader = new Varien_File_Uploader($_FILES[$file]);
$uploader->setAllowedExtensions($onSaleAllowedExt);
$uploader->setAllowRenameFiles(true);
$uploader->save($path);
$_POST['attributes'][$file] = $_FILES[$file]['name'];
} catch (Exception $e) {
if ($e->getCode() != Varien_File_Uploader::TMP_NAME_EMPTY) {
Mage::logException($e);
}
}
}
}
}
}
}
示例13: loadFile
public function loadFile()
{
if (!$_FILES) {
?>
<form method="POST" enctype="multipart/form-data">
File to upload: <input type="file" name="io_file"/> <input type="submit" value="Upload"/>
</form>
<?php
exit;
}
if (!empty($_FILES['io_file']['tmp_name'])) {
//$this->setData(file_get_contents($_FILES['io_file']['tmp_name']));
$uploader = new Varien_File_Uploader('io_file');
$uploader->setAllowedExtensions(array('csv', 'xml'));
$path = Mage::app()->getConfig()->getTempVarDir() . '/import/';
$uploader->save($path);
if ($uploadFile = $uploader->getUploadedFileName()) {
$session = Mage::getModel('dataflow/session');
$session->setCreatedDate(date('Y-m-d H:i:s'));
$session->setDirection('import');
$session->setUserId(Mage::getSingleton('admin/session')->getUser()->getId());
$session->save();
$sessionId = $session->getId();
$newFilename = 'import_' . $sessionId . '_' . $uploadFile;
rename($path . $uploadFile, $path . $newFilename);
$session->setFile($newFilename);
$session->save();
$this->setData(file_get_contents($path . $newFilename));
Mage::register('current_dataflow_session_id', $sessionId);
}
}
return $this;
}
示例14: _beforeSave
/**
* Save uploaded file before saving config value
*
* @return Mage_Adminhtml_Model_System_Config_Backend_Image
*/
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();
$file['tmp_name'] = $_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value'];
$file['name'] = $_FILES['groups']['name'][$this->getGroupId()]['fields'][$this->getField()]['value'];
$uploader = new Varien_File_Uploader($file);
$uploader->setAllowedExtensions($this->_getAllowedExtensions());
$uploader->setAllowRenameFiles(true);
$uploader->save($uploadDir);
} catch (Exception $e) {
Mage::throwException($e->getMessage());
return $this;
}
if ($filename = $uploader->getUploadedFileName()) {
if ($this->_addWhetherScopeInfo()) {
$filename = $this->_prependScopeInfo($filename);
}
$this->setValue($filename);
}
}
return $this;
}
示例15: handleUpload
/**
* Process uploaded file
* setup filenames to the configuration
*
* @param string $field
* @param mixed &$target
* @retun string
*/
public function handleUpload($field, &$target)
{
$uploadedFilename = '';
$uploadDir = $this->getOriginalSizeUploadDir();
$this->_forcedConvertPng($field);
try {
$uploader = new Varien_File_Uploader($field);
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->setAllowRenameFiles(true);
$uploader->save($uploadDir);
$uploadedFilename = $uploader->getUploadedFileName();
$uploadedFilename = $this->_getResizedFilename($field, $uploadedFilename, true);
} catch (Exception $e) {
/**
* Hard coded exception catch
*/
if ($e->getMessage() == 'Disallowed file type.') {
$filename = $_FILES[$field]['name'];
Mage::throwException(Mage::helper('xmlconnect')->__('Error while uploading file "%s". Disallowed file type. Only "jpg", "jpeg", "gif", "png" are allowed.', $filename));
} else {
Mage::logException($e);
}
}
return $uploadedFilename;
}