Welcome Guest, Not a member yet? Register   Sign In
File uploading: Do not require a file to be uploaded
#8

[eluser]sjmiller85[/eluser]
I will go into much more in-depth detail. Unfortunately, I am unable to copy and paste code.

The form itself is an application for the user to apply for a position. They enter in the following fields (by _POST name):

RealName (type="text"),
Email (type="text"),
EmailValidate (type="text"),
UserName (type="text"),
PasswordValidate (type="text"),
TeamPositionID (multiselect),
Experience (type="text"),
WebsiteLink (type="text"),
userfile (upload),
MiscAppNotes (type="text")

The fields in question are: "WebsiteLink" and "userfile". I am using the form validation library for the rest of the fields. the function is straightforward, run the validation, if it fails, return the errors, use set_value() to fill in the fields, have them try again. If the form validation succeeds, this is where it gets hairy. For the form validation config file, the fields marked as required are ALL but "WebsiteLink", "userfile", and "MiscAppNotes". Of those three, "WebsiteLink" and "userfile" are the two in question with regards to this topic. For them. The user may link us to a website, and/or upload a file. I wouldn't necessarily classify it as having an order of precedence, since they can do either or both, so long as there is at least one. Without being able to copy and paste, I am going to fat finger the general construct of the function, omitting the database queries, the variable names, all the irrelevant parts:

Code:
function apply() {
    $this->load->library('form_validation');

    if($this->form_validation->run() == FALSE) {
        //Load the page, make the necessary queries relevant to the page load, etc.. etc..
    } else {
        $config['upload_path'] = $location;
        $config['allowed_types'] = $allowedTypes;
        // etc.. etc..
        
        $this->load->library('upload',$config);

        //escape all the $_POST variables, md5 the password, etc.. etc..

        //Now begins the part in question
        if ($this->upload->do_upload() && !empty( $_POST['WebsiteLink'] )) {
            //determine upload data, run a query into the database to store
            //all the information for both the file and the website link,
            //as well as the rest of the form that was filled out
        } elseif ( !$this->upload->do_upload() && !empty( $_POST['WebsiteLink'] )) {
            //Same deal as the last one, only exclude the file.  Now the problem that
            //I see with doing this, is that it will only call to this portion of the
            //if statement if there is any problem whatsoever with the file, be it the
            //wrong type (I am only allowing .zip), too big in size, etc..  Not only
            //if there was no file uploaded, this encompasses any reason for a file
            //not getting uploaded.
        } elseif ( $this->upload->do_upload() && !empty( $_POST['WebsiteLink'] )) {
            //This will get called if the user uploaded a file but did not post a link,
            //as with the previous, run the data in the database, etc.. etc.. without
            //a file upload
        } else {
            //return errors and have them try again.
        }
    }
}

I apologize if there are any syntax errors above, that was all fat fingered in a hurry. That is the general gist of the function that is being used. Fairly straightforward.

To sum up, with regards to the two fields ("WebsiteLink" and "userfile"), at least one of the two (if not both) must be filled out. They can upload a file, or link a website, or both, and I am not 100% certain on how to process the information with regards to the upload library, since I need to determine whether or not it returns an exception regarding not uploading a file, vice trying to upload one, but having it return a plethora of errors that could potentially occur. Any leads? I thank you sincerely for your assistance with this!

EDIT: For some reason that I cannot recall at this point, I also attempted to use !isset($_FILE) in the my script as well, but was telling myself that for a reason that I cannot remember, that would not suffice as a substitute for !$this->upload->do_upload(). I tried using it again and winded up getting double the errors when uploading a file. It would repeat the error twice if I did that. Can't quite recall why I was telling myself it wouldn't work, other than the double error (which I honestly am not sure why it's doing that), but something was stopping me (other than the aforementioned exception being raised).


Messages In This Thread
File uploading: Do not require a file to be uploaded - by El Forum - 07-13-2009, 12:33 PM
File uploading: Do not require a file to be uploaded - by El Forum - 07-13-2009, 12:51 PM
File uploading: Do not require a file to be uploaded - by El Forum - 07-13-2009, 01:07 PM
File uploading: Do not require a file to be uploaded - by El Forum - 07-13-2009, 02:37 PM
File uploading: Do not require a file to be uploaded - by El Forum - 07-13-2009, 05:01 PM
File uploading: Do not require a file to be uploaded - by El Forum - 07-14-2009, 10:20 AM
File uploading: Do not require a file to be uploaded - by El Forum - 07-14-2009, 10:26 AM
File uploading: Do not require a file to be uploaded - by El Forum - 07-14-2009, 11:20 AM
File uploading: Do not require a file to be uploaded - by El Forum - 07-14-2009, 12:09 PM
File uploading: Do not require a file to be uploaded - by El Forum - 07-14-2009, 12:57 PM
File uploading: Do not require a file to be uploaded - by El Forum - 07-14-2009, 01:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB