本文整理汇总了PHP中Mage_Core_Model_File_Uploader::getUploadedFileName方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Core_Model_File_Uploader::getUploadedFileName方法的具体用法?PHP Mage_Core_Model_File_Uploader::getUploadedFileName怎么用?PHP Mage_Core_Model_File_Uploader::getUploadedFileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Core_Model_File_Uploader
的用法示例。
在下文中一共展示了Mage_Core_Model_File_Uploader::getUploadedFileName方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: afterSave
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);
} catch (Exception $e) {
return $this;
}
$uploader->save(Mage::getStoreConfig('system/filesystem/media') . '/catalog/product');
if ($fileName = $uploader->getUploadedFileName()) {
$object->setData($this->getAttribute()->getName(), $fileName);
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
}
return $this;
}
示例4: 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'])) {
$uploader = new Mage_Core_Model_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;
}
示例5: uploadFile
/**
* Upload and resize new file
*
* @param string $targetPath Target directory
* @param string $type Type of storage, e.g. image, media etc.
* @throws Mage_Core_Exception
* @return array File info Array
*/
public function uploadFile($targetPath, $type = null)
{
$uploader = new Mage_Core_Model_File_Uploader('image');
if ($allowed = $this->getAllowedExtensions($type)) {
$uploader->setAllowedExtensions($allowed);
}
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(false);
$result = $uploader->save($targetPath);
if (!$result) {
Mage::throwException(Mage::helper('cms')->__('Cannot upload file.'));
}
// create thumbnail
$this->resizeFile($targetPath . DS . $uploader->getUploadedFileName(), true);
$result['cookie'] = array('name' => session_name(), 'value' => $this->getSession()->getSessionId(), 'lifetime' => $this->getSession()->getCookieLifetime(), 'path' => $this->getSession()->getCookiePath(), 'domain' => $this->getSession()->getCookieDomain());
return $result;
}
示例6: _afterSave
protected function _afterSave()
{
if (is_string($this->getGuiData())) {
$this->setGuiData(unserialize($this->getGuiData()));
}
$profileHistory = Mage::getModel('Mage_Dataflow_Model_Profile_History');
$adminUserId = $this->getAdminUserId();
if ($adminUserId) {
$profileHistory->setUserId($adminUserId);
}
$profileHistory->setProfileId($this->getId())->setActionCode($this->getOrigData('profile_id') ? 'update' : 'create')->save();
if (isset($_FILES['file_1']['tmp_name']) || isset($_FILES['file_2']['tmp_name']) || isset($_FILES['file_3']['tmp_name'])) {
for ($index = 0; $index < 3; $index++) {
if ($file = $_FILES['file_' . ($index + 1)]['tmp_name']) {
$uploader = new Mage_Core_Model_File_Uploader('file_' . ($index + 1));
$uploader->setAllowedExtensions(array('csv', 'xml'));
$path = Mage::app()->getConfig()->getTempVarDir() . '/import/';
$uploader->save($path);
if ($uploadFile = $uploader->getUploadedFileName()) {
$newFilename = 'import-' . date('YmdHis') . '-' . ($index + 1) . '_' . $uploadFile;
rename($path . $uploadFile, $path . $newFilename);
}
}
//BOM deleting for UTF files
if (isset($newFilename) && $newFilename) {
$contents = file_get_contents($path . $newFilename);
if (ord($contents[0]) == 0xef && ord($contents[1]) == 0xbb && ord($contents[2]) == 0xbf) {
$contents = substr($contents, 3);
file_put_contents($path . $newFilename, $contents);
}
unset($contents);
}
}
}
parent::_afterSave();
}
示例7: compactValue
/**
* Export attribute value to entity model
*
* @param Mage_Core_Model_Abstract $entity
* @param array|string $value
* @return Mage_Customer_Model_Attribute_Data_File
*/
public function compactValue($value)
{
if ($this->getIsAjaxRequest()) {
return $this;
}
$attribute = $this->getAttribute();
$original = $this->getEntity()->getData($attribute->getAttributeCode());
$toDelete = false;
if ($original) {
if (!$attribute->getIsRequired() && !empty($value['delete'])) {
$toDelete = true;
}
if (!empty($value['tmp_name'])) {
$toDelete = true;
}
}
$ioFile = new Varien_Io_File();
$path = Mage::getBaseDir('media') . DS . 'customer';
$ioFile->open(array('path' => $path));
// unlink entity file
if ($toDelete) {
$this->getEntity()->setData($attribute->getAttributeCode(), '');
$file = $path . $original;
if ($ioFile->fileExists($file)) {
$ioFile->rm($file);
}
}
if (!empty($value['tmp_name'])) {
try {
$uploader = new Mage_Core_Model_File_Uploader($value);
$uploader->setFilesDispersion(true);
$uploader->setFilenamesCaseSensitivity(false);
$uploader->setAllowRenameFiles(true);
$uploader->save($path, $value['name']);
$fileName = $uploader->getUploadedFileName();
$this->getEntity()->setData($attribute->getAttributeCode(), $fileName);
} catch (Exception $e) {
Mage::logException($e);
}
}
return $this;
}