View Single Post
  #1 (permalink)  
Old 11-21-2008, 10:47 PM
Nitecon Nitecon is offline
Junior Member
 
Join Date: Nov 2008
Posts: 14
Default Zend Form Element File > Rename... working but with a question...

Hey folks,

My form element works just fine, with one exception... I wrote a small function to rename a particular photo to what I want although, as soon as the form is generated it automatically assigns the value, this of course is not too big a deal but it's just causing me some frustration, and I think I've been staring at the problem for a little too long and just need some fresh eyes.

So here is the form element itself :
[PHP] $photo = new Zend_Form_Element_File('photo');
$photo->setLabel('Upload your photo.')
->setRequired(false)
->setDestination('/path/to/full/permission/images/')
->addValidator('Size', false, 102400)
->addValidator('Extension', false, 'jpg,png,gif')
->addFilter('Rename',
array('source' => $this->file,
'target' => "/path/to/full/permission/images/'".$this->formRename($this->file),
'overwrite' => true));[/PHP]

And now the function that renames the actual file to something more or less of what I want :
[PHP] public function formRename($filename)
{
$path = $_SERVER['REQUEST_URI'];
$id = basename($path);
$ext = substr($filename, strrpos($filename, '.') + 1);
$newName = $id.'_photo.'.$ext;
return $newName;
}[/PHP]
As you can see I just basically get the ID by the url location and assign that as the users id, then add the _photo suffix, and add the extension to what the original file was....

Problem remains that as soon as the form loads the $photo section is now "x_photo." No matter if the user adds a file the file name stays the same... Granted the images do show up due to fairly smart browsers, but still this is something I would like to see fixed properly and I'm just staring at code at this point that looks right...

Last edited by Nitecon; 11-21-2008 at 11:01 PM. Reason: Fixed a quotation mark that distorted the php
Reply With Quote