// 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() );
				}
		}	
 
	}
 
pear/formbuilder/fileupload.txt · Last modified: 2008/09/16 11:49 (external edit)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki