Re: PEAR Quickform Upload Rule

From: Date: Wed, 22 Dec 2004 01:12:53 +0000
Subject: Re: PEAR Quickform Upload Rule
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-16394@lists.php.net to get a copy of this message
Please do not post the same question twice. On Tue, 21 Dec 2004 21:24:31 -0200, fromvega <mtnvega@yahoo.com.br> wrote: > Hello! > > I'm using Quickform to make an upload form that would upload a jpeg > image to > the server. > I read some tutorials on the internet about uploading with Quickform and > used it to build my own script. > But I'm having a problem with the rule that should validate if the file was > uploaded or not > The rule is $form->addRule('imagename', 'You need to select a file to > upload', 'uploadedfile'); What does print_r($_POST['imagename']) have in it? > > What happens is that everytime I try to upload a file, the rule fail and > presents me the error message: > 'You need to select a file to upload' !! But I selected the file correctly! > And when I remove this rule, > the image file is uploaded right the way it should be with the rule!! > > I don't know why is it happening because I followed the tutorials. > > So, I was wondering if you could help me with this, so here is a copy of > the > upload form. > > PS.: if possible foward the answer to mtnvega@yahoo.com.br > > Thanks a lot, > fromvega > > <?php > require_once("HTML/QuickForm.php"); > > $form = new HTML_QuickForm('frm_upload', 'post'); > > $form->setMaxFileSize('5120000'); > $form->addElement('file', 'imagename', 'Image:'); > > // this is the problematic rule > $form->addRule('imagename', 'You need to select a file to upload', > 'uploadedfile'); > > $form->addRule('imagename', 'The file is larger than 5MB', > maxfilesize', > '5120000'); > > $form->addRule('imagename', 'Needs to be a jpg', 'mimetype', > 'image/jpeg'); > > if( $form->validate() ) > { > $tmp_name = time().".jpg"; > $file =& $form->getElement('imagename'); > > if ($file->isUploadedFile()) > { > $file->moveUploadedFile("upload/",$tmp_name); > } > > echo "Validated!"; > } > else > { > $form->addElement('submit','upload','UPLOAD'); > $form->display(); > } > ?> > -- Justin Patrin

« previous php.pear.general (#16394) next »