On Tue, 30 Sep 2008 11:11:33 -0500, Mike Potter wrote:
>I have a PHP5 .class file that validates form inputs and sends
>notification emails from contact pages. Recently a client wanted to
>add a file upload function. No sweat, I thought.
>
>Well, I can't get the $_FILES portion to validate properly in my
>.class file, since it apparently only registers the $_POST vars. This
>is the section of code, *currently functional as-is* that I need to
>modify so that $_FILES is also processed:
>[...]
Not wanting to comment on your formfield validation, here's what I do
with file upload validation:
if (!isset($_FILES[$inputName])) {
// handle form error (e.g. forgot form encoding type!)
}
else
switch ($_FILES[$inputName]['error']) {
case UPLOAD_ERR_OK:
// process as per nicely uploaded file
break;
case UPLOAD_ERR_NO_FILE:
// file wasn't attached; if mandatory, complain!
break;
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
$errmsg .= "# error uploading file: file too big.<br/>\n";
break;
default:
$errmsg .= "# error uploading file: "
. $_FILES[$inputName]['error'] . ".<br/>\n";
break;
}
--
Ross McKay, Toronto, NSW Australia
"Let the laddie play wi the knife - he'll learn"
- The Wee Book of Calvin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php