// Prepare the form so it contains a file upload field function preGenerateForm(&$fg) { $this->fb_preDefElements['image'] =& HTML_QuickForm::createElement('file', 'image', 'Image to upload', 'maxfilesize=5000000'); } function insert() { $this->handleFileUpload( 'image' ); return parent::insert(); } function update($do=false) { $this->handleFileUpload( 'image' ); parent::update($do); } function handleFileUpload( $fieldName ){ require_once "HTTP/Upload.php"; $upload = new HTTP_Upload("en"); $file = $upload->getFiles($fieldName); if ($file->isValid()) { $file->setName("seq"); $moved = $file->moveTo( UPLOADDIR ); if (!PEAR::isError($moved)) { $this->{$fieldName} = $file->getProp('name'); } else { die( 'error moving file: ' . $file->errorMsg() ); } } }