Re: PEAR Quickform Upload Rule
| From: | Justin Patrin | Date: | Wed, 22 Dec 2004 17:44:42 +0000 |
| Subject: | Re: PEAR Quickform Upload Rule | ||
| References: | 1 2 3 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-16418@lists.php.net to get a copy of this message | ||
On Wed, 22 Dec 2004 09:56:45 -0200, fromvega <mtnvega@yahoo.com.br> wrote:
> Justin Patrin wrote:
> > 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();
> >>}
> >>?>
> >>
> >
> Thanks man but I already solve this. I think it was a bug because I
> update PEAR and it started working.
Please post if you solve the problems on your own. It can help others
who have the problem and we won't waste our time trying to help fix a
fixed problem.
>
> Thank you!
> fromvega
>
--
Justin Patrin