PEAR Quickform Upload Rule

From: Date: Tue, 21 Dec 2004 23:24:31 +0000
Subject: PEAR Quickform Upload Rule
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-16392@lists.php.net to get a copy of this message
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 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();
} ?>

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