File validation conundrum |
[eluser]LeonardoGaiero[/eluser]
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.
[eluser]umefarooq[/eluser]
hope this will help you to solve your problem check the file validation http://devbro.com/testing/ci_form_validation/
[eluser]LeonardoGaiero[/eluser]
[quote author="umefarooq" date="1288883741"]hope this will help you to solve your problem check the file validation http://devbro.com/testing/ci_form_validation/[/quote] Thanks for the link, that looks rather useful; however, I figured that things should be much simpler than they actually are, so I decided I'd just make the DB data mandatory and the file data optional. If an user tries to upload a file without inserting änything in a provided textarea, the application stops at form validation, and only performs the upload logic once validation has passed. That way, I can single out the upload logic, and work on the DB/validation part in two separate steps, so that the UL won't happen unless the rest of the data has passed validation. Thanks either way for the function, it will come in handy at another point ![]()
[eluser]LuckyFella73[/eluser]
If I got you right you want to validate form-data and only if a file was selected validate the file too. In that case you could do something like this: Code: <?php The code is just a part of my whole controller file but should work basically.
[eluser]bravonet[/eluser]
[quote author="umefarooq" date="1288883741"]hope this will help you to solve your problem check the file validation http://devbro.com/testing/ci_form_validation/[/quote] elo, i am quite new to codeigniter i have some problem with multiple uploader validaion i tried to make it like Code: for ($i=0; $i < $num_files ; $i++) { and its seem like the validation is not working |
Welcome Guest, Not a member yet? Register Sign In |