« Return to Thread: Making $_POST and $_FILES play together nicely

Making $_POST and $_FILES play together nicely

by Mike Potter-2 :: Rate this Message:

Reply to Author | View in Thread

Hi,

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:

        public function validateForm() {
                $requiredFields = array( "name" => "My Name", "phone" => "My
Telephone", "email" => "My Email",
                 "file" => "My Upload File", "comments" => "My Comments" );
               
                if( isset( $_POST ) && is_array( $_POST ) && count( $_POST ) > 0 ) {
                        $reqFieldsPresent = true;
                        $this->msg = "<p>The following required fields were not filled out:</p><ul>";
                        foreach( $requiredFields as $field => $value ) {
                                if( !isset( $_POST[ $field ] ) ||
                                                         $_POST[ $field ] == "" ||
                                                         $_POST[ $field ] == $value ) {
                                        $reqFieldsPresent = false;
                                        $this->msg .= "<li>" . $value . "</li>";

                        }

How can I modify this so that if $_FILES['userfile']['name'] is
present the fileUpload() function can be invoked and the file uploaded
to the client's server, but if the upload file has not been specified
the absence will be reported same as if $_POST['name'] is absent?

Ski

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

 « Return to Thread: Making $_POST and $_FILES play together nicely

LightInTheBox - Buy quality products at wholesale price!