Hi everyone!
I'm trying to manage images uploads using my own class which renames the uploaded file prepending a random string:
define('UPLOAD_PATH', realpath(APPLICATION_PATH . '/../public/uploads'));
class Lib_Form_Element_File extends Zend_Form_Element_File
{
public function init()
{
if($this->isUploaded()) {
$this->setDestination(UPLOAD_PATH);
$realname = $this->getFileName(null, false);
do {
$filename = UPLOAD_PATH . '/' . md5(time()) . '_' . $realname;
} while(is_file($filename));
$this->addFilter('Rename', $filename);
}
}
}
With it I can add my own element to a form:
$form->addElement(new Lib_Form_Element_File(array(
'name' => 'image',
'label' => 'Image'
)
)
);
When inserting everything is OK. I have problems while updating/deleting the record.
I'm trying to find a way to:
- Display the current image inside the modify form
- Find a way to remove the current image without uploading another one
- Delete the image while deleting the associated row (this is probably simple)
Suggestions anyone?
How do you manage these problems?
I'm also trying to associate a photo gallery for every row so any help is very much appreciated! :)