![]() |
How to check the photo is selected when try to upload a photo - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: How to check the photo is selected when try to upload a photo (/showthread.php?tid=51200) |
How to check the photo is selected when try to upload a photo - El Forum - 04-24-2012 [eluser]Zulkifli Said[/eluser] hi, i make a form to upload a text and a photo(* where optional to upload photo). this my code in view: Code: <input type="text" name="firstname" /> THE QUESTION IS: how i can check the user upload/browse/select a photo/file or not?? my code like on controller like this: Code: $data['name'] = $this->input->post('firstname',TRUE); But, i found the error... if i not select a photo , the output is "you select a photo/file"; and if i select a photo , the output is "you select a photo/file"; i think the error is 1. $data['photo'] = $this->input->post('userfile',TRUE); 2. if(!isset($data['photo'])) please give me a solution.. thanks,,, How to check the photo is selected when try to upload a photo - El Forum - 04-24-2012 [eluser]tastebuds[/eluser] try using display_errors() function from the upload library here is the snippet of code from user guide http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html Code: <?php How to check the photo is selected when try to upload a photo - El Forum - 04-24-2012 [eluser]boltsabre[/eluser] Your making a variable, $data['photo'], and assigning it the value of the post. Even if the post input (image) is empty, your variable $data['photo'] still exists!!! Change to [code] if(!isset($data['photo']) || $data['photo'] == false){ ... }else{ ... } How to check the photo is selected when try to upload a photo - El Forum - 04-24-2012 [eluser]Zulkifli Said[/eluser] thanks for reply... my problem is solving i try using Code: if($_FILES['userfile']['error'] === 0 ){} or Code: if($_FILES['userfile']['name']){} How to check the photo is selected when try to upload a photo - El Forum - 04-24-2012 [eluser]boltsabre[/eluser] no worries, at least you now know that you cant make a variable and then check isset() against it!!! However, that may change in CI3, check this out: http://ellislab.com/forums/viewthread/215833/ But yeah, currently post variables return false if not set, when more than likely they should return null. Try this just for your own knowledge: Code: $var = false; |