本文整理汇总了PHP中Varien_File_Uploader::addValidateCallback方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_File_Uploader::addValidateCallback方法的具体用法?PHP Varien_File_Uploader::addValidateCallback怎么用?PHP Varien_File_Uploader::addValidateCallback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_File_Uploader
的用法示例。
在下文中一共展示了Varien_File_Uploader::addValidateCallback方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uploadAction
public function uploadAction()
{
try {
//Mage::log($_FILES);
/* $mageVersion = Mage::getVersionInfo();
if($mageVersion<'1.5.1.0'){
$uploader = new Mage_Core_Model_File_Uploader('image');
}else{
$uploader = new Varien_File_Uploader('image');
} */
$uploader = new Varien_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->getBaseTmpMediaPath());
Mage::dispatchEvent('catalog_product_gallery_upload_image_after', array('result' => $result, 'action' => $this));
/**
* 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']);
$tempUrl = $this->_prepareFileForUrl($result['file']);
if (substr($tempUrl, 0, 1) == '/') {
$tempUrl = substr($tempUrl, 1);
}
$result['url'] = $this->getBaseTmpMediaUrl() . '/' . $tempUrl;
/* $result['url'] = Mage::getSingleton('catalog/product_media_config')->getTmpMediaUrl($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));
}
示例2: uploadAction
public function uploadAction()
{
$result = array();
try {
$uploader = new Varien_File_Uploader('image');
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->addValidateCallback('catalog_product_image', Mage::helper('catalog/image'), 'validateUploadFile');
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
$result = $uploader->save(Mage::getSingleton('catalog/product_media_config')->getBaseTmpMediaPath());
$result['url'] = Mage::getSingleton('catalog/product_media_config')->getTmpMediaUrl($result['file']);
$result['file'] = $result['file'] . '.tmp';
$result['cookie'] = array('name' => session_name(), 'value' => $this->_getSession()->getSessionId(), 'lifetime' => $this->_getSession()->getCookieLifetime(), 'path' => $this->_getSession()->getCookiePath(), 'domain' => $this->_getSession()->getCookieDomain());
} catch (Exception $e) {
$result = array('error' => $e->getMessage(), 'errorcode' => $e->getCode());
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
示例3: uploadAction
public function uploadAction()
{
//We are unable to change Varien_File_Uploader, so in case when DB storage allowed we will do next:
//We upload image to local Magento FS, then we check whether this file exists in DB
//If it exists, we are getting unique name from DB, and change them on FS
//After this we upload file to DB storage
$result = array();
try {
$uploader = new Varien_File_Uploader('image');
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->addValidateCallback('catalog_product_image', Mage::helper('catalog/image'), 'validateUploadFile');
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
$result = $uploader->save(Mage::getSingleton('catalog/product_media_config')->getBaseTmpMediaPath());
$result['file'] = Mage::helper('core/file_storage_database')->saveUploadedFile($result);
$result['url'] = Mage::getSingleton('catalog/product_media_config')->getTmpMediaUrl($result['file']);
$result['file'] = $result['file'] . '.tmp';
$result['cookie'] = array('name' => session_name(), 'value' => $this->_getSession()->getSessionId(), 'lifetime' => $this->_getSession()->getCookieLifetime(), 'path' => $this->_getSession()->getCookiePath(), 'domain' => $this->_getSession()->getCookieDomain());
} catch (Exception $e) {
$result = array('error' => $e->getMessage(), 'errorcode' => $e->getCode());
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
示例4: uploadImage
/**
* Function to upload product image
*
* @param int $filename
* @param array $filesDataArray
* @return string
*/
public function uploadImage($filename, $filesDataArray)
{
/**
* Create instance for uploader
*/
$uploader = new Varien_File_Uploader($filename);
/**
* SEt allowed extensions
*/
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->addValidateCallback('catalog_product_image', Mage::helper('catalog/image'), 'validateUploadFile');
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(false);
/**
* Initilize path
*/
$path = Mage::getBaseDir('media') . DS . 'tmp' . DS . 'catalog' . DS . 'product' . DS;
$uploader->save($path, $filesDataArray[$filename]['name']);
/**
* Return path
*/
return $path . $uploader->getUploadedFileName();
}
示例5: saveLogoForSeller
/**
* save logo for seller
*
* @param array $filesDataArray
* @param string $basedir
* @return string $imagesPathLogo
*/
public function saveLogoForSeller($filesDataArray, $basedir, $logo)
{
/**
* check store logo has not been empty
*/
$imagesPathLogoBanner = '';
if (isset($filesDataArray[$logo]['name']) && file_exists($filesDataArray[$logo]['tmp_name'])) {
try {
$uploader = new Varien_File_Uploader($filesDataArray[$logo]);
/**
* Define the allowed file extension of uploading file
*/
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->addValidateCallback('catalog_product_image', Mage::helper('catalog/image'), 'validateUploadFile');
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(false);
$path = $basedir . DS . 'sellerimage';
/**
* upload the file to the images path
*/
$uploader->save($path, $filesDataArray[$logo]['name']);
$imagesPathLogoBanner = $uploader->getUploadedFileName();
} catch (Exception $e) {
/**
* Display error message for images upload
*/
Mage::getSingleton('core/session')->addError($this->__($e->getMessage()));
}
/**
* check for resized directory and create new one if its not exist already
*/
Mage::getModel('marketplace/seller')->createDirecotryForSellerProfileImage($basedir, 2);
/**
* Define the logo and resized logo paths
*/
if ($logo == 'store_logo') {
$imageUrlLogo = Mage::getBaseDir('media') . DS . 'sellerimage' . DS . $imagesPathLogoBanner;
$imageResizedLogo = Mage::getBaseDir('media') . DS . 'marketplace' . DS . 'resized' . DS . $imagesPathLogoBanner;
} else {
$imageUrlLogo = Mage::getBaseDir('media') . DS . 'sellerimage' . DS . $imagesPathLogoBanner;
$imageResizedLogo = Mage::getBaseDir('media') . DS . 'marketplace' . DS . 'resized' . DS . $imagesPathLogoBanner;
}
/**
* check the file is in logo path and not in resized logo path
*/
if (file_exists($imageUrlLogo) && !file_exists($imageResizedLogo)) {
/**
* Define the atributes before resize
*/
$imageObj = new Varien_Image($imageUrlLogo);
$imageObj->constrainOnly(TRUE);
$imageObj->keepAspectRatio(False);
$imageObj->keepFrame(FALSE);
/**
* Resize the image according to the atributes
*/
if ($logo == 'store_logo') {
$imageObj->resize(150, 110);
} else {
$imageObj->resize(750, 230);
}
/**
* Saving the Resized image
*/
$imageObj->save($imageResizedLogo);
}
}
return $imagesPathLogoBanner;
}