Mantasgl wrote:
>
> $element = new Zend_Form_Element_File('g_nuotrauka');
> $element->setLabel('Nuotrauka:')
> ->setDestination(APPLICATION_PATH.'\images')
> ->addValidator('Count', false, 1)
> ->addValidator('Size', false, 204800)
> ->addValidator('Extension', false, 'jpg,png,gif')
> ->setDecorators($this->_standardElementDecorator);
> $this->addElement($element, 'g_nuotrauka');
>
> I tried to use addFilter('Rename') in file element and in my controller,
> but nothing worked out.
> What i'm dooing wrong?
>
Here is what I do on one of my Social Sites.
if($form->isValid($_POST)) {
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('Size', false, 2000000, 'file1');
$upload->setDestination(_IMGSOURCE_);
$files = $upload->getFileInfo();
$i=0;
foreach ($files as $file => $info) {
if($upload->isValid($file)){
$ext = pathinfo($info['name']);
$filename =
'image_'.$userid.'_'.date('Ymdhs').'.'.$ext['extension'];
$upload->addFilter('Rename',
array('target' => _IMGSOURCE_.$filename,
'overwrite' => true),'file1');
$upload->receive($file);
$i++;
// Add Photo to Db
$photo = new Photos();
$rate = new Ratings();
$resized = new
App_Thumbnail(_IMGSOURCE_.$filename);
$data = array(
'userid' => $userid,
'name' => $filename,
'desc' => $_POST['desc'],
'url' => $_POST['url'],
'dateAdded' => new
Zend_Db_Expr('NOW()')
);
try {
$photo->insert($data);
$pid =
$photo->getAdapter()->lastInsertId();
$resized->resize( 600, 800);
$resized->save(_IMGSOURCE_.$filename,80);
$resized->watermark(_IMGSOURCE_.$filename);
$photo->_createThumbnail(_IMGSOURCE_.$filename,
_THUMBSOURCE_.$filename, 100, 150, $q = 80);
$rate->baseRating($pid);
}
catch (Exception $e)
{
$logger =
Zend_Registry::get('logger');
$logger->warn("Image Insert
Error - ". $e->getMessage());
$this->flash('There was a
problem. Please Try
Again!','/member/submit');
}
}
Hope it helps took me alot of trial and error along with some great help on
here
Eric Haskins
PHP Programmer
--
View this message in context:
http://www.nabble.com/How-to-rename-the-uploaded-file-tp22203609p22216209.html
Sent from the Zend Framework mailing list archive at Nabble.com.
- [fw-general] How to rename the uploaded file Mantasgl
- RE: [fw-general] How to rename the uploaded file Guillaume BABIK
- Re: [fw-general] How to rename the uploaded file Lucas Corbeaux
- Re: [fw-general] How to rename the uploaded file Ehask71
