[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pear-general
Subject:    Re: [PEAR] HTML_QuickForm - Check of uploaded file using custom
From:       Bertrand Mansion <bmansion () mamasam ! com>
Date:       2003-09-29 14:39:49
[Download RAW message or body]

<php-list@stg-design.de> wrote :

> Hello,
> 
> i'm using HTML_QuickForm and HTML_QuickForm_Controller to build a
> mulit-page Wizard for sign-in in a community. in one of the steps users
> may upload one (at the moment, later more) image.
> So i want to check, if the uploaded file is really an image, so that my
> process-script will be able to save an scale it down.

Here, you have to make sure the step with the upload, actually keep track of
the uploaded file. What I use is a new index in the controller container.
For example:

$data =& $controller->container();
$data['uploads']['user_image'] = $filename;

In the process action (used when the form is finished), I check if there is
something in the 'upload' container and insert the value found in the
database.

I also suggest you extend the 'direct' action, or whatever action you use to
switch from one page to another, so that it takes care of the uploaded file
if the submitted page is the one with the upload.
For example:

If ($pagename == 'upload_page') {
    // Save the uploaded file and fill in the upload container
}

The above explanations are not related directly to your problem but they
will probably help you. I'll add an example for handling uploads to the docs
as soon as I can.

> I've tried the following Code:
> $file =& $this->addElement('file', 'pic1', 'Your Pictore:');
> $this->addRule('pic1', 'Not an image', 'function', 'CheckImage',
> 'validation');
> 
> But validation::CheckImage() is never executed. I've also tried to place
> the function in the HTML_QuickForm_Page and deleted the 'validation'-
> element of the rule, but it doesn't help.
> I avoid the use of checking the mime-type, b/c it made some failures
> with some files that are JPEG-images, but not accepted. Also i'm not
> really shure, what mimetypes for JPGs are... IE for example uses
> image/pjpeg...
> 
> I couldn't find anything in the docu about such problems.

CheckImage is probably the right way to go if your function works. You maybe
forgot to register the function before using it:

function checkImage($elName, $value, $options = null)
{
   return true;
}

$this->registerRule('checkimage', 'function', 'checkImage');
$this->addRule('pic1', 'Not an image', 'checkimage');

Good luck,

Bertrand Mansion
Mamasam

-- 
PEAR General Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic