Greetings. I have a situation where I need to be able to perform validation on a file upload, which has to happen simultaneously with a database operation; however, I have hit a brick wall with validating the upload before actually altering the DB data. I basically need to be able to do the following:
- Validate the POST part of the form input;
- Validate the file itself;
- Echo any errors about either the file OR the DB data;
- If everything’s OK, perform the actual operations.
Please let me state beforehand that changing the process can only be done to a certain extent, and that I don’t want to separate the upload from the database operation: the user needs to see everything in a single form, and work from there.
Now, I have identified a couple of possible routes to go about this: since I noticed that CI relies on PHP’s native upload functions to verify the validity of any given file (ie, attempts to do the upload and posts the results), I could either try to “fake” the file upload, so to speak, or manually hack together a validation routine.
Apparently, the former requires me to muck around with the PHP engine itself, whereas the second route is rather error-prone; which option would be best? is there anything better out there, short of doing the upload and deleting the file if the DB insertion fails? Many thanks in advance for any and all useful insight.
