本文整理汇总了PHP中Varien_File_Uploader::getNewFileName方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_File_Uploader::getNewFileName方法的具体用法?PHP Varien_File_Uploader::getNewFileName怎么用?PHP Varien_File_Uploader::getNewFileName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_File_Uploader
的用法示例。
在下文中一共展示了Varien_File_Uploader::getNewFileName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getYouTubeImage
/**
* @param $value
* @param bool $forceDownload
* @return string
*/
public function getYouTubeImage($value, $forceDownload = false)
{
$baseDir = Mage::getBaseDir('media');
$localDir = 'gallery' . DS . 'data' . DS . 'thumbnail';
if (is_dir($localDir)) {
mkdir($localDir, 0777, true);
}
$fileName = Varien_File_Uploader::getNewFileName($baseDir . DS . $localDir . DS . $value . '.jpg');
$absPath = $baseDir . DS . $localDir . DS . $fileName;
if ($forceDownload || !is_file($absPath)) {
try {
$url = sprintf('http://img.youtube.com/vi/%s/0.jpg', $value);
$client = new Zend_Http_Client($url);
$response = $client->request(Zend_Http_Client::GET);
if (200 != $response->getStatus()) {
Mage::throwException("Can't download youtube thumbnail");
}
if (!is_dir($baseDir . DS . $localDir)) {
mkdir($baseDir . DS . $localDir, 0777, true);
}
file_put_contents($absPath, $response->getBody());
} catch (Exception $e) {
Mage::logException($e);
return false;
}
}
return $localDir . DS . $fileName;
}
示例2: saveAction
public function saveAction()
{
$post_data = $this->getRequest()->getPost();
if ($post_data) {
try {
$post_data['category'] = implode(',', $post_data['category']);
//save image
try {
if ((bool) $post_data['image']['delete'] == 1) {
$post_data['image'] = '';
} else {
unset($post_data['image']);
if (isset($_FILES)) {
if ($_FILES['image']['name']) {
if ($this->getRequest()->getParam("id")) {
$model = Mage::getModel("gallery/image")->load($this->getRequest()->getParam("id"));
if ($model->getData('image')) {
$io = new Varien_Io_File();
$io->rm(Mage::getBaseDir('media') . DS . implode(DS, explode('/', $model->getData('image'))));
}
}
$path = Mage::getBaseDir('media') . DS . 'gallery' . DS . 'image' . DS;
$uploader = new Varien_File_Uploader('image');
$uploader->setAllowedExtensions(array('jpg', 'png', 'gif'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$destFile = $path . $_FILES['image']['name'];
$filename = $uploader->getNewFileName($destFile);
$uploader->save($path, $filename);
$post_data['image'] = 'gallery/image/' . $filename;
}
}
}
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
return;
}
//save image
$model = Mage::getModel("gallery/image")->addData($post_data)->setId($this->getRequest()->getParam("id"))->save();
Mage::getSingleton("adminhtml/session")->addSuccess(Mage::helper("adminhtml")->__("Image was successfully saved"));
Mage::getSingleton("adminhtml/session")->setImageData(false);
if ($this->getRequest()->getParam("back")) {
$this->_redirect("*/*/edit", array("id" => $model->getId()));
return;
}
$this->_redirect("*/*/");
return;
} catch (Exception $e) {
Mage::getSingleton("adminhtml/session")->addError($e->getMessage());
Mage::getSingleton("adminhtml/session")->setImageData($this->getRequest()->getPost());
$this->_redirect("*/*/edit", array("id" => $this->getRequest()->getParam("id")));
return;
}
}
$this->_redirect("*/*/");
}
示例3: moveFileFromTmp
/**
* Move file from tmp path to base path
*
* @param string $baseTmpPath
* @param string $basePath
* @param string $file
* @return string
*/
public function moveFileFromTmp($baseTmpPath, $basePath, $file)
{
$ioObject = new Varien_Io_File();
$destDirectory = dirname($this->getFilePath($basePath, $file));
try {
$ioObject->open(array('path' => $destDirectory));
} catch (Exception $e) {
$ioObject->mkdir($destDirectory, 0777, true);
$ioObject->open(array('path' => $destDirectory));
}
if (strrpos($file, '.tmp') == strlen($file) - 4) {
$file = substr($file, 0, strlen($file) - 4);
}
$destFile = dirname($file) . $ioObject->dirsep() . Varien_File_Uploader::getNewFileName($this->getFilePath($basePath, $file));
$result = $ioObject->mv($this->getFilePath($baseTmpPath, $file), $this->getFilePath($basePath, $file));
return str_replace($ioObject->dirsep(), '/', $destFile);
}
示例4: moveImageFromTmp
public function moveImageFromTmp($file)
{
$ioObject = new Varien_Io_File();
$destDirectory = Mage::getBaseDir('media') . '/option_image';
try {
$ioObject->open(array('path' => $destDirectory));
} catch (Exception $e) {
$ioObject->mkdir($destDirectory, 0777, true);
$ioObject->open(array('path' => $destDirectory));
}
if (strrpos($file, '.tmp') == strlen($file) - 4) {
$file = substr($file, 0, strlen($file) - 4);
}
$destFile = Varien_File_Uploader::getNewFileName($file);
$dest = $destDirectory . '/' . $destFile;
$ioObject->mv($this->_getMadiaConfig()->getTmpMediaPath($file), $dest);
return $destFile;
}
示例5: uploadAction
public function uploadAction()
{
if (isset($_FILES)) {
if ($_FILES['image']['size'] > 52428800) {
//throw new Exception('Disallowed File size it should be less than 50 MB .');
Mage::getSingleton('core/session')->addError('Disallowed File size it should be less than 50 MB .');
echo "sizeerror";
return;
}
$fileTypeArray = explode(".", $_FILES['image']['name']);
$fileType = end($fileTypeArray);
if (!in_array(strtolower($fileType), array('jpg', 'JPG', 'JPEG', 'jpeg', 'png', 'PNG', 'tiff', 'tif'))) {
Mage::getSingleton('core/session')->addError('Disallowed File Type');
echo "fileerror";
return;
}
$path = Mage::getBaseDir('media') . DS . 'userUploads' . DS . 'image' . DS;
//$path = Mage::getBaseDir()."/plupload/examples/uploads";
$uploader = new Varien_File_Uploader('image');
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif', 'tiff', 'tif'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$str = str_replace(' ', '', $_FILES['image']['name']);
$destFile = $path . time() . $str;
$filename = $uploader->getNewFileName($destFile);
$uploader->save($path, $filename);
$image = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'userUploads/image/' . $filename;
$path_parts = pathinfo($image);
if ($path_parts['extension'] == "tif" || $path_parts['extension'] == "TIF" || $path_parts['extension'] == "tiff" || $path_parts['extension'] == "TIFF") {
$changetype = new Imagick($image);
$changetype->setImageFormat('jpg');
$typeChangeImageName = time();
$changetype->writeImage(Mage::getBaseDir('media') . DS . "userUploads" . DS . "image" . DS . $typeChangeImageName . ".jpg");
$image = Mage::getBaseUrl('media') . DS . "userUploads" . DS . "image" . DS . $typeChangeImageName . ".jpg";
}
echo $image;
return;
}
}
示例6: _getUniqueFileName
/**
* Check whether file to move exists. Getting unique name
*
* @param <type> $file
* @param <type> $dirsep
* @return string
*/
protected function _getUniqueFileName($file, $dirsep)
{
if ($this->_checkDb()) {
$destFile = Mage::helper('core/file_storage_database')->getUniqueFilename(Mage::getSingleton('catalog/product_media_config')->getBaseMediaUrlAddition(), $file);
} else {
$destFile = dirname($file) . $dirsep;
if (version_compare(Mage::getVersion(), '1.5') > 0) {
$destFile .= Mage_Core_Model_File_Uploader::getNewFileName($this->_getConfig()->getMediaPath($file));
} else {
$destFile .= Varien_File_Uploader::getNewFileName($this->_getConfig()->getMediaPath($file));
}
}
return $destFile;
}
示例7: _processDownloadableProduct
protected function _processDownloadableProduct($product, &$importData)
{
// comment if --------------------------
//if ($new) {
$filearrayforimports = array();
$downloadableitems = array();
$downloadableitemsoptionscount = 0;
//THIS IS FOR DOWNLOADABLE OPTIONS
$commadelimiteddata = explode('|', $importData['downloadable_options']);
foreach ($commadelimiteddata as $data) {
$configBundleOptionsCodes = $this->userCSVDataAsArray($data);
$downloadableitems['link'][$downloadableitemsoptionscount]['is_delete'] = 0;
$downloadableitems['link'][$downloadableitemsoptionscount]['link_id'] = 0;
$downloadableitems['link'][$downloadableitemsoptionscount]['title'] = $configBundleOptionsCodes[0];
$downloadableitems['link'][$downloadableitemsoptionscount]['price'] = $configBundleOptionsCodes[1];
$downloadableitems['link'][$downloadableitemsoptionscount]['number_of_downloads'] = $configBundleOptionsCodes[2];
$downloadableitems['link'][$downloadableitemsoptionscount]['is_shareable'] = 2;
if (isset($configBundleOptionsCodes[5])) {
#$downloadableitems['link'][$downloadableitemsoptionscount]['sample'] = '';
$downloadableitems['link'][$downloadableitemsoptionscount]['sample'] = array('file' => '[]', 'type' => 'url', 'url' => '' . $configBundleOptionsCodes[5] . '');
} else {
$downloadableitems['link'][$downloadableitemsoptionscount]['sample'] = '';
}
$downloadableitems['link'][$downloadableitemsoptionscount]['file'] = '';
$downloadableitems['link'][$downloadableitemsoptionscount]['type'] = $configBundleOptionsCodes[3];
#$downloadableitems['link'][$downloadableitemsoptionscount]['link_url'] = $configBundleOptionsCodes[4];
if ($configBundleOptionsCodes[3] == "file") {
#$filearrayforimport = array('file' => 'media/import/mypdf.pdf' , 'name' => 'asdad.txt', 'size' => '316', 'status' => 'old');
#$document_directory = Mage :: getBaseDir( 'media' ) . DS . 'import' . DS;
#echo "DIRECTORY: " . $document_directory;
#$filearrayforimport = '[{"file": "/home/discou33/public_html/media/import/mypdf.pdf", "name": "mypdf.pdf", "status": "new"}]';
#$filearrayforimport = '[{"file": "mypdf.pdf", "name": "quickstart.pdf", "size": 324075, "status": "new"}]';
#$product->setLinksPurchasedSeparately(0);
#$product->setLinksPurchasedSeparately(false);
#$files = Zend_Json::decode($filearrayforimport);
#$files = "mypdf.pdf";
//--------------- upload file ------------------
$document_directory = Mage::getBaseDir('media') . DS . 'import' . DS . $this->__vendorName . DS;
$files = '' . $configBundleOptionsCodes[4] . '';
$link_file = $document_directory . $files;
$file = realpath($link_file);
if (!$file || !file_exists($file)) {
Mage::throwException(Mage::helper('catalog')->__($rowInfo . 'Link file ' . $file . ' not exists'));
}
$pathinfo = pathinfo($file);
$linkfile = Varien_File_Uploader::getCorrectFileName($pathinfo['basename']);
$dispretionPath = Varien_File_Uploader::getDispretionPath($linkfile);
$linkfile = $dispretionPath . DS . $linkfile;
$linkfile = $dispretionPath . DS . Varien_File_Uploader::getNewFileName(Mage_Downloadable_Model_Link::getBaseTmpPath() . DS . $linkfile);
$ioAdapter = new Varien_Io_File();
$ioAdapter->setAllowCreateFolders(true);
$distanationDirectory = dirname(Mage_Downloadable_Model_Link::getBaseTmpPath() . DS . $linkfile);
try {
$ioAdapter->open(array('path' => $distanationDirectory));
$ioAdapter->cp($file, Mage_Downloadable_Model_Link::getBaseTmpPath() . DS . $linkfile);
$ioAdapter->chmod(Mage_Downloadable_Model_Link::getBaseTmpPath() . DS . $linkfile, 0777);
} catch (exception $e) {
Mage::throwException(Mage::helper('catalog')->__('Failed to move file: %s', $e->getMessage()));
}
//{"file": "/2/_/2.jpg", "name": "2.jpg", "size": 23407, "status": "new"}
$linkfile = str_replace(DS, '/', $linkfile);
$filearrayforimports = array(array('file' => $linkfile, 'name' => $pathinfo['filename'] . '.' . $pathinfo['extension'], 'status' => 'new', 'size' => filesize($file)));
if (isset($configBundleOptionsCodes[5])) {
if ($configBundleOptionsCodes[5] == 0) {
$linkspurchasedstatus = 0;
$linkspurchasedstatustext = false;
} else {
$linkspurchasedstatus = 1;
$linkspurchasedstatustext = true;
}
$product->setLinksPurchasedSeparately($linkspurchasedstatus);
$product->setLinksPurchasedSeparately($linkspurchasedstatustext);
}
//$downloadableitems['link'][$downloadableitemsoptionscount]['link_file'] = $linkfile;
$downloadableitems['link'][$downloadableitemsoptionscount]['file'] = Mage::helper('core')->jsonEncode($filearrayforimports);
} else {
if ($configBundleOptionsCodes[3] == "url") {
$downloadableitems['link'][$downloadableitemsoptionscount]['link_url'] = $configBundleOptionsCodes[4];
}
}
$downloadableitems['link'][$downloadableitemsoptionscount]['sort_order'] = 0;
$product->setDownloadableData($downloadableitems);
$downloadableitemsoptionscount += 1;
}
#print_r($downloadableitems);
//}
}
示例8: uploadFile
public function uploadFile($key)
{
try {
$path = Mage::getBaseDir('media') . DS . 'formbuilder/frontend/uploaded_files' . DS;
$uploader = new Varien_File_Uploader($key);
//$uploader->setAllowedExtensions(array('jpg','png','gif'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$destFile = $path . $this->_fileObject[$key]['name'];
$filename = $uploader->getNewFileName($destFile);
$uploader->save($path, $filename);
return "formbuilder/frontend/uploaded_files/" . $filename;
} catch (Exception $e) {
$this->_session->addError($this->_helper->__("Error uploading file"));
return false;
}
}
示例9: saveAction
public function saveAction()
{
if ($data = $this->getRequest()->getPost()) {
/*echo "<pre>";
print_r($data);
echo "</pre>";
exit();*/
$model = Mage::getModel("formbuilder/forms")->load($this->getRequest()->getParam("id"));
$currentFormId = $this->getRequest()->getParam("id");
//save image
try {
if ((bool) $data['title_image']['delete'] == 1) {
$data['title_image'] = '';
} else {
unset($data['title_image']);
if (isset($_FILES)) {
if ($_FILES['title_image']['name']) {
if ($this->getRequest()->getParam("id")) {
//$model = Mage::getModel("formbuilder/forms")->load($this->getRequest()->getParam("id"));
if ($model->getData('title_image')) {
$io = new Varien_Io_File();
$io->rm(Mage::getBaseDir('media') . DS . implode(DS, explode('/', $model->getData('title_image'))));
}
}
$path = Mage::getBaseDir('media') . DS . 'formbuilder/images' . DS;
$uploader = new Varien_File_Uploader('title_image');
$uploader->setAllowedExtensions(array('jpg', 'png', 'gif'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$destFile = $path . $_FILES['title_image']['name'];
$filename = $uploader->getNewFileName($destFile);
$uploader->save($path, $filename);
$data['title_image'] = 'formbuilder/images/' . $filename;
}
}
}
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
return;
}
//save image ends
try {
//$model = Mage::getModel("formbuilder/forms")->load($this->getRequest()->getParam("id"));
if (isset($data['stores']) && !empty($data['stores'])) {
if (in_array('0', $data['stores'])) {
$data['stores'] = array(0);
}
//$stores = Mage::helper('core')->jsonEncode($data['stores']);
$data['stores'] = implode(',', $data['stores']);
}
if ($model->getCreatedTime() == NULL) {
$data['created_time'] = now();
}
$data['update_time'] = now();
/*$fieldsModel = Mage::helper('formbuilder')->getFieldsModel();
$getFieldsCollection = $fieldsModel->getFieldsCollection($currentFormId);
$getNoOfFields = count($getFieldsCollection);
$data['no_of_fields'] = $getNoOfFields;*/
/*if($data['title']=='' || $data['title']==NULL)
$data['title'] = $model['title'];*/
/*$data['title'] = $data['in_toplinks'];
$data['title_image'] = $data['in_menu'];*/
$model->addData($data)->setFormsIndex($this->getRequest()->getParam("id"))->save();
if (!$currentFormId) {
$currentFormId = $model->getFormsIndex();
}
// saveFields
$fieldsArray = $data['product']['options'];
//Mage::helper('formbuilder')->saveFields($fieldsArray);
$fieldsModel = Mage::helper('formbuilder')->getFieldsModel();
$fieldsModel->saveFields($fieldsArray, $currentFormId);
// saveFields
//save no of fields
$fieldsModel = Mage::helper('formbuilder')->getFieldsModel();
$getFieldsCollection = $fieldsModel->getFieldsCollection($currentFormId);
$getNoOfFields = count($getFieldsCollection);
//$data['no_of_fields'] = $getNoOfFields;
$formsModel = Mage::helper('formbuilder')->getFormsModel();
$formsModel->load($currentFormId);
$formsModel->setNoOfFields($getNoOfFields);
$formsModel->save();
//save no of fields ends
//$this->createCmsPage($model);
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('formbuilder')->__('Form was successfully saved'));
Mage::getSingleton('adminhtml/session')->setFormData(false);
if ($this->getRequest()->getParam('back')) {
$this->_redirect('*/*/edit', array('id' => $model->getFormsIndex()));
return;
}
$this->_redirect('*/*/');
return;
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
Mage::getSingleton('adminhtml/session')->setFormData($data);
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
return;
}
}
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('formbuilder')->__('Unable to find Form to save'));
//.........这里部分代码省略.........
示例10: saveProductTabData
/**
* This method will run when the product is saved from the Magento Admin
* Use this function to update the product model, process the
* data or anything you like
*
* @param Varien_Event_Observer $observer
*/
public function saveProductTabData(Varien_Event_Observer $observer)
{
if (self::$_singletonFlag) {
return;
}
self::$_singletonFlag = true;
$product = $observer->getEvent()->getProduct();
$storeId = $product->getStoreId();
try {
$files = $this->_getRequest()->getPost('infofile_file');
$names = $this->_getRequest()->getPost('infofile_name');
$labels = $this->_getRequest()->getPost('infofile_label');
for ($i = 1; $i < count($files); $i++) { // Skip $i=0, because it contains the template!
$fileName = $files[$i];
$originalName = $names[$i];
// move the file from the tmp media folder to the real folder
$currentFile = Mage::getSingleton('catalog/product_media_config')->getTmpMediaPath($fileName);
$dispretionPath = Varien_File_Uploader::getDispretionPath($originalName);
$destinationFolder = Mage::getSingleton('catalog/product_media_config')->getMediaPath($dispretionPath);
$destFile = Mage::getSingleton('catalog/product_media_config')->getMediaPath($dispretionPath . DS . $originalName);
if (!(@is_dir($destinationFolder) || @mkdir($destinationFolder, 0777, true))) {
throw new Exception("Unable to create directory '{$destinationFolder}'.");
}
// adds a counter to the filename
$destFilename = $dispretionPath . DS . Varien_File_Uploader::getNewFileName($destFile);
$destFile = Mage::getSingleton('catalog/product_media_config')
->getMediaPath($destFilename);
rename($currentFile, $destFile);
// add entry in the database
$model = Mage::getModel('n98infofiles/file');
$model->setFilename($destFilename);
$label = trim($labels[$i]);
if (empty($label)) {
$label = $originalName;
}
$model->setLabel($label);
$model->setProductId($product->getId());
$model->setStoreId($storeId);
$model->save();
}
// process existing files
$exLabels = $this->_getRequest()->getPost('infofile_existing_label');
$exRemove = $this->_getRequest()->getPost('infofile_existing_remove');
if (count($exRemove) > 0) {
foreach ($exLabels as $id => $label) {
$fileModel = Mage::getModel('n98infofiles/file');
$fileModel->load($id);
if (isset($exRemove[$id])) {
// delete file from disk
$filename = Mage::getSingleton('catalog/product_media_config')->getMediaPath($fileModel->getFilename());
unlink($filename);
// delete record
$fileModel->delete();
continue;
}
$fileModel->setLabel($label);
$fileModel->save();
}
}
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
}
示例11: saveAction
public function saveAction()
{
if ($data = $this->getRequest()->getPost()) {
$model = Mage::getModel('blog/post');
if (isset($_FILES['featured_image']['name']) and file_exists($_FILES['featured_image']['tmp_name'])) {
try {
$uploader = new Varien_File_Uploader('featured_image');
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$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 . 'wysiwyg/dgtthemes/blog/' . DS;
$destFile = $path . $_FILES['featured_image']['name'];
$filename = $uploader->getNewFileName($destFile);
$uploader->save($path, $filename);
$data[featured_image] = 'wysiwyg/dgtthemes/blog/' . $filename;
} catch (Exception $e) {
}
} else {
if (isset($data['featured_image']['delete']) && $data['featured_image']['delete'] == 1) {
$data['featured_image'] = '';
} else {
unset($data['featured_image']);
}
}
if (isset($data['tags'])) {
if ($this->getRequest()->getParam('id')) {
$model->load($this->getRequest()->getParam('id'));
$originalTags = explode(",", $model->getTags());
} else {
$originalTags = array();
}
$tags = explode(',', $data['tags']);
array_walk($tags, 'trim');
foreach ($tags as $key => $tag) {
$tags[$key] = Mage::helper('blog')->convertSlashes($tag, 'forward');
}
$tags = array_unique($tags);
$commonTags = array_intersect($tags, $originalTags);
$removedTags = array_diff($originalTags, $commonTags);
$addedTags = array_diff($tags, $commonTags);
if (count($tags)) {
$data['tags'] = trim(implode(',', $tags));
} else {
$data['tags'] = '';
}
}
if (isset($data['stores'])) {
if ($data['stores'][0] == 0) {
unset($data['stores']);
$data['stores'] = array();
$stores = Mage::getSingleton('adminhtml/system_store')->getStoreCollection();
foreach ($stores as $store) {
$data['stores'][] = $store->getId();
}
}
}
$model->setData($data)->setId($this->getRequest()->getParam('id'));
try {
$format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
if (isset($data['created_time']) && $data['created_time']) {
$dateFrom = Mage::app()->getLocale()->date($data['created_time'], $format);
$model->setCreatedTime(Mage::getModel('core/date')->gmtDate(null, $dateFrom->getTimestamp()));
$model->setUpdateTime(Mage::getModel('core/date')->gmtDate());
} else {
$model->setCreatedTime(Mage::getModel('core/date')->gmtDate());
}
if ($this->getRequest()->getParam('user') == null) {
$model->setUser(Mage::getSingleton('admin/session')->getUser()->getFirstname() . " " . Mage::getSingleton('admin/session')->getUser()->getLastname())->setUpdateUser(Mage::getSingleton('admin/session')->getUser()->getFirstname() . " " . Mage::getSingleton('admin/session')->getUser()->getLastname());
} else {
$model->setUpdateUser(Mage::getSingleton('admin/session')->getUser()->getFirstname() . " " . Mage::getSingleton('admin/session')->getUser()->getLastname());
}
$model->save();
/* recount affected tags */
if (isset($data['stores'])) {
$stores = $data['stores'];
} else {
$stores = array(null);
}
$affectedTags = array_merge($addedTags, $removedTags);
foreach ($affectedTags as $tag) {
foreach ($stores as $store) {
if (trim($tag)) {
Mage::getModel('blog/tag')->loadByName($tag, $store)->refreshCount();
}
}
}
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('blog')->__('Post was successfully saved'));
Mage::getSingleton('adminhtml/session')->setFormData(false);
if ($this->getRequest()->getParam('back')) {
$this->_redirect('*/*/edit', array('id' => $model->getId()));
return;
}
$this->_redirect('*/*/');
return;
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
Mage::getSingleton('adminhtml/session')->setFormData($data);
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
//.........这里部分代码省略.........
示例12: _moveImageFromTmp
/**
* Move image from temporary directory to normal
*
* @param string $file
* @return string
*/
protected function _moveImageFromTmp($file)
{
$ioObject = new Varien_Io_File();
$destDirectory = dirname($this->_getConfig()->getMediaPath($file));
try {
$ioObject->open(array('path' => $destDirectory));
} catch (Exception $e) {
$ioObject->mkdir($destDirectory, 0777, true);
$ioObject->open(array('path' => $destDirectory));
}
$destFile = dirname($file) . $ioObject->dirsep() . Varien_File_Uploader::getNewFileName($this->_getConfig()->getMediaPath($file));
$ioObject->mv($this->_getConfig()->getTmpMediaPath($file), $this->_getConfig()->getMediaPath($destFile));
return $destFile;
}
示例13: saveAction
public function saveAction()
{
if ($data = $this->getRequest()->getPost()) {
if (isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
try {
$path = Mage::getBaseDir('media') . DS . 'gallery' . DS;
$itemId = $this->getRequest()->getParam('id');
if ($itemId) {
$temporaryModel = Mage::getModel('gallery/gallery')->load($itemId);
$oldFile = $temporaryModel->getFilename();
if ($oldFile && $oldFile != '' && file_exists($path . $oldFile)) {
unlink($path . $oldFile);
}
}
/* Starting upload */
$uploader = new Varien_File_Uploader('filename');
// Any extention would work
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->setAllowRenameFiles(false);
// Set the file upload mode
// false -> get the file directly in the specified folder
// true -> get the file in the product like folders
// (file.jpg will go in something like /media/f/i/file.jpg)
$uploader->setFilesDispersion(false);
// We set media as the upload dir
$destFile = $path . $_FILES['filename']['name'];
$filename = $uploader->getNewFileName($destFile);
$uploader->save($path, $filename);
} catch (Exception $e) {
}
//this way the name is saved in DB
$data['filename'] = $filename;
}
$model = Mage::getModel('gallery/gallery');
$model->setData($data)->setId($this->getRequest()->getParam('id'));
try {
if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
$model->setCreatedTime(now())->setUpdateTime(now());
} else {
$model->setUpdateTime(now());
}
$model->save();
if (isset($_FILES['filename'])) {
$model->makeThumbnail(150, 120, true);
}
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('gallery')->__('Item was successfully saved'));
Mage::getSingleton('adminhtml/session')->setFormData(false);
if ($this->getRequest()->getParam('back')) {
$this->_redirect('*/*/edit', array('id' => $model->getId()));
return;
}
$this->_redirect('*/*/');
return;
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
Mage::getSingleton('adminhtml/session')->setFormData($data);
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
return;
}
}
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('gallery')->__('Unable to find item to save'));
$this->_redirect('*/*/');
}
示例14: _copyImage
/**
* Copy image and return new filename.
*
* @param string $file
* @return string
*/
protected function _copyImage($file)
{
$ioObject = new Varien_Io_File();
$destDirectory = dirname($this->_getConfig()->getMediaPath($file));
$ioObject->open(array('path' => $destDirectory));
$destFile = dirname($file) . $ioObject->dirsep() . Varien_File_Uploader::getNewFileName($this->_getConfig()->getMediaPath($file));
$ioObject->cp($this->_getConfig()->getMediaPath($file), $this->_getConfig()->getMediaPath($destFile));
return str_replace($ioObject->dirsep(), '/', $destFile);
}
示例15: _getNotDuplicatedFilename
/**
* Get filename which is not duplicated with other files in media temporary and media directories
*
* @param String $fileName
* @param String $dispretionPath
* @return String
*/
protected function _getNotDuplicatedFilename($fileName, $dispretionPath)
{
$fileMediaName = $dispretionPath . DS . Varien_File_Uploader::getNewFileName($this->_getConfig()->getMediaPath($fileName));
$fileTmpMediaName = $dispretionPath . DS . Varien_File_Uploader::getNewFileName($this->_getConfig()->getTmpMediaPath($fileName));
if ($fileMediaName != $fileTmpMediaName) {
if ($fileMediaName != $fileName) {
return $this->_getNotDuplicatedFileName($fileMediaName, $dispretionPath);
} elseif ($fileTmpMediaName != $fileName) {
return $this->_getNotDuplicatedFilename($fileTmpMediaName, $dispretionPath);
}
}
return $fileMediaName;
}