How to check if ‘userfile’ field is not empty before uploading a file? |
[eluser]pulok[/eluser]
How can I check if user has selected any file to upload (before calling the $this->upload->do_upload() in my controller)? This is needed because there are other input fields along with a file upload field which is not mandatory. Basically what I want to do is: Code: if ( user_chose_any_file_to_upload ){
[eluser]Michael Wales[/eluser]
Code: <?php
[eluser]pulok[/eluser]
Thanks Michael. Sorry it was posted somehow twice :-(
[eluser]LuckyFella73[/eluser]
Maybe it's a bit fussy to mention: While checking the file (like Michael stated before) the file is allready uploaded to the temp-directory of your webserver. You then just decide to move the file to your decided filestructure or not. Nice weekend - Fussyfella ![]()
[eluser]pulok[/eluser]
For some reason it is not working as expected. Take the upload example in userguide at http://ellislab.com/codeigniter/user-gui...ading.html I slightly modified the code of upload.php as follows. It did not work! Am I missing anything? Code: if (isset($_FILES)) {
[eluser]LuckyFella73[/eluser]
Would be nice if you could post the whole controller code. Your post doesn't make clear for example if you did set the config params. Code: # CI Manual: And please describe what kind of error do you get or what happen (or what exactly do not happen) after submitting the form.
[eluser]pulok[/eluser]
I am trying to check, if user has really selected any file to upload (before calling the do_upload ) in my controller. Regarding the code, I referred the standard upload example from CI user guide. I only added ‘if (isset($_FILES))’ block in code to check if user selected any file to upload or not, which is not working anyway. Other words, I like to separate ‘validation’ and ‘error check’ for upload file. HTH.
[eluser]elvix[/eluser]
I'm not 100% sure testing for presence of $_FILES is enough. Seems like (in my limited testing) that any multipart form with an upload is going to generate the $_FILES array regardless, which makes sense since you need to know if there was a problem (found in $_FILES['userfile']['error']). So, I added a test for no errors, which seems to work: Code: isset($_FILES) && @$_FILES['userfile']['error'] == '0' |
Welcome Guest, Not a member yet? Register Sign In |