Last active
December 17, 2015 20:29
-
-
Save tpphu/5667615 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private function _getImageNameAndReceive($name, $subPath = null) | |
{ | |
$ret_name = ''; | |
/*@var $imageElement Zend_Form_Element_File*/ | |
$imageElement = $this->$name; | |
if( !empty($imageElement) ) | |
{ | |
$image_name = $imageElement->getFileName(null, false); | |
if ( !empty($image_name) ) | |
{ | |
$name_length = strlen($image_name); | |
if($name_length > 40 ) | |
{ | |
$image_name = substr($image_name, 0, 40) . substr($image_name, $name_length - 4, $name_length); | |
} | |
$ret_name = time() . '_'. mt_rand(0, 9999).'_'. preg_replace('/[^A-Za-z0-9-_.]/', '', $image_name); | |
$target = UPLOAD_PATH; | |
$thumnail = UPLOAD_PATH.'/'.FOLDER_THUMBNAIL.'/'; | |
if( empty($subPath) ) | |
{ | |
$target .= '/'; | |
} | |
else | |
{ | |
$target .= '/'.$subPath.'/'; | |
} | |
$target .= $ret_name; | |
$thumnail .= $ret_name; | |
$imageElement->addFilter('Rename',array( | |
'target' => $target | |
)); | |
if( $imageElement->receive() ) | |
{ | |
if( $name == 'image_banner') | |
{ | |
$this->_cropImage($target, $thumnail); | |
} | |
} | |
} | |
} | |
return $ret_name; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment