file upload validation |
[eluser]badgeek[/eluser]
how to validate file upload using validation class? thanks
[eluser]Gordaen[/eluser]
What about the file are you trying to validate? Did you take a look at the File Uploading Class?
[eluser]Isos[/eluser]
I have came to this issue .. I am using file uploading class with validation class. The form contains a lot of fields to be validated .. So, logically thinking, I created $rules['userfile'] = "callback__userfile"; and then a function: Code: function _userfile(){ This is supposed to work! but even when I pass wrong extensions (not specified in $config['allowed_types']) or even when I don't pass any file (leave field empty) validation works without any errors, and when I select a file with the right conditions also validation works and no upload is done. I am sure of 777 permission, and everything else cuz I am using file upload in other places in my website. Any tips? Was the idea of creating a callback a bad one? Thanks
[eluser]wiredesignz[/eluser]
Upload uses $_FILES and Validation uses $_POST so I can't see how you could validate this way. Sorry. Maybe some hidden form fields might help, but I haven't investigated this.
[eluser]xwero[/eluser]
Isos it's a great idea but you have no configuration. I guess you autoload the library Code: function _userfile(){
[eluser]wiredesignz[/eluser]
This works, but you must fake a $_POST value for 'userfile' to force validation to run Code: class Welcome extends Controller
[eluser]Isos[/eluser]
[quote author="xwero" date="1207244643"]Isos it's a great idea but you have no configuration. I guess you autoload the library Code: function _userfile(){ Thanks ![]() I have decided to separate the two forms as my work requires faster solutions for now. But I will try out the fake POST ![]() Thanks for your help guys.
[eluser]Kenzie[/eluser]
I use this to check if there was a file selected, before faking the POST to execute the callback: Code: if(isset($_FILES['userfile']) && !empty($_FILES['userfile']['name'])) $_POST['userfile'] = 'uploadfile'; // fake the $_POST or use a hidden field in the form
[eluser]Colin Williams[/eluser]
Let's not forget about the PHP manual: Quote:$_FILES['userfile']['error'] I imagine that would make sense to check! ![]()
[eluser]Bramme[/eluser]
I'm with Colin, more specifically: $_FILES['userfile']['error'] == 4 means there was no file selected. |
Welcome Guest, Not a member yet? Register Sign In |