How to check the photo is selected when try to upload a photo |
[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,,,
[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-gui...ading.html Code: <?php
[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{ ... }
[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']){}
[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; |
Welcome Guest, Not a member yet? Register Sign In |