Quickform Image validation

From: Date: Mon, 03 Nov 2003 23:16:40 +0000
Subject: Quickform Image validation
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-8742@lists.php.net to get a copy of this message
I'm using the following class for a form with an image in, but I need to use a function to validate that an image was uploaded with the correct type and that it's not too large. I don't seem to be able to access the information about the file from within the class witrhout using the $_FILES array. Does anyone have any ideas? <?php require_once 'HTML/QuickForm.php'; class Form_addShop extends HTML_QuickForm { function Form_addShop($formName='addShop', $method = 'post', $target = '_self', $attributes = null) { $this->HTML_QuickForm($formName, $method, '', $target, $attributes); $this->addElement('header', null, 'Add a Shop'); $this->addElement('text', 'txtName', 'Name', array('size'=>20, 'maxlength'=>50)); $this->addElement('textarea', 'txtDescription', 'Description'); $this->addElement('file', 'fileImage', 'Image'); $this->addElement('submit', null, 'Submit'); $this->applyFilter('txtName', 'trim'); $this->applyFilter('txtDescription', 'htmlspecialchars'); $this->addRule('txtName', 'Name is required', 'required', null, 'server'); $this->addRule('txtDescription', 'Description is required', 'required', null, 'server'); $this->addFormRule(array(&$this,'CheckUpload')); } function CheckUpload($stuff) { // shows MAX_FILE_SIZE var_dump($stuff); // shows nothing (probably due to form not having completed validation var_dump($this->exportValue('fileImage')); // shows what Iwant var_dump($_FILES); return array('fileImage' => 'This is not an image'); } } ?> Kind Regards, -- Ian P. Christian http://www.fuzzmail.co.uk ~ Free, Fast and Fuzzy webmail

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