Extended form_validation: now with file checking :) |
[eluser]devbro[/eluser]
I have been thinking of doing this for a long time and finally did ![]() http://devbro.com/testing/ci_form_validation/ I extended the form_validation to now have ability to check $_FILES (file uploading). here is the way it can be used: Code: $this->form_validation->set_rules('image','Image','file_required|file_size_max[500]|file_allowed_type[image]'); I added 3 set of rules so far: 1. file_required: same as required 2. file_size_max: define maximum file size in KB 3. file_allowed_type: what type of file to expect. So what do you think? is there any way to improve it further?
[eluser]devbro[/eluser]
i used it myself in two projects already. so far no problem and it saves me writing callback_ with file upload.
[eluser]Johan André[/eluser]
I'm gonna try this one out! If it works good (which I'm sure it will do) you are truly awesome!
[eluser]devbro[/eluser]
I moved the location of the source code: http://devbro.com/testing/ci_form_validation/ hope it helps.
[eluser]GlennJ[/eluser]
Nice one! Just what I was looking for, will give this a go now.
[eluser]GlennJ[/eluser]
Change line 95 to Code: $result = $rule($postdata['name']); and you'll get rid of the PHP notice :coolsmile:
[eluser]devbro[/eluser]
[quote author="GlennJ" date="1249071765"]Change line 95 to Code: $result = $rule($postdata['name']); and you'll get rid of the PHP notice :coolsmile:[/quote] The issue is that if I do that then I would have problem if more fields are needed for that validation rule. also if there are more validations they will all fail.
[eluser]GlennJ[/eluser]
All $_FILE entries have the ['name'] field, so I don't see the problem?
[eluser]devbro[/eluser]
what if meta_data, size, temp_dir are the indexes that are needed? in case of allowed types name is no longer needed, just the mime type. If some sort of content checking is needed then temp_dir is needed. I was thinking of passing the field name instead but there may be things that need to be modified half way. Something like xss_clean or fix_mime_type or change_filename |
Welcome Guest, Not a member yet? Register Sign In |