Welcome Guest, Not a member yet? Register   Sign In
File Uploading Class, validation without upload?
#1

[eluser]axed[/eluser]
Hi,

The do_upload function validates the userfile and then uploads it, but is it possible to just validate the userfile without uploading it?

//Dan
#2

[eluser]axed[/eluser]
Ok I will try to explain myself a little better.

I have a form with two input fields (name and date) and a upload field (userfile) and I validate the input fields with the form validation class. This is no problem, it works as it should.

I'm also using the upload file class to validate and upload the userfile from the upload field. This is also working, but the problem is when one of the two input fields fails in validation and the upload field doesn't. Then the userfile have been uploaded but the input fields needs to be showed and filled in again.

Then the next time the form is submited with the same file, that file already exists on the server?

How is best practise to handle this. When usual form validation fails, then I don't want to upload the userfile. If I only want to validate the userfile, do I need to write my own function for this, can it not be done with the upload file class?
#3

[eluser]falkencreative[/eluser]
If you show the code in your controller that you are using for form validation/upload, that might help.

Perhaps do something like this, splitting your form validation and checking for correct file upload into two steps:

Code:
if (check if the two inputs are invalid)
{
    // if inputs are invalid, show form
}
else
{
    // if inputs are valid, continue

    if (! $this->upload->do_upload())
    {
        // show form
    }
    else
    {
        // continue
    }

}
#4

[eluser]axed[/eluser]
Thank you, that makes sense.
#5

[eluser]axed[/eluser]
Another question about the File Uploading Class: Is there a way to change, by config, the language for the error messages? Or do I have to change the source code?
#6

[eluser]radine[/eluser]
axed, just change it on language folder..
#7

[eluser]radine[/eluser]
falken,,but how if there are more than 1 upload field?? let see this case,, there are 3 upload fields.. so,we have to validate those part one by one.. if one part from three upload field contain forbidden file,,meanwhile to validate it we have to use do_upload first..
So,there are some file that have been uploaded if the forbidden file is in the second or third validation section.. It means, it will makes many junks in our directory..
And the point is,, how we ensure that 3part have been validate,, after that we can upload it..??




Theme © iAndrew 2016 - Forum software by © MyBB