Welcome Guest, Not a member yet? Register   Sign In
How to accept an empty input value in CI?
#1

(This post was last modified: 04-14-2022, 04:37 AM by luckmoshy.)

Hi all, I want my app to accept an empty value in the input file uploader How?


PHP Code:
<?= form_open_multipart('upload/upload'?>

<input type="file" name="userfile" size="20" />/*I want to accept if user did not pick up an image*/


<input type="submit" value="upload" />

</form> 



PHP Code:
$file $this->request->getFile('userfile');*I want to accept if user did not pick up an image*/

  if (
$file->isValid() && ! $file->hasMoved()) {

   
$newName $file->getRandomName();/*Here it generate an error that Undefined variable $newName  but if there is file ok */
  
$file->move(WRITEPATH 'uploads'$newName);
}

'savein'=>$newName,/*Modal*/ 
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#2

Could you check empty() on the POST var?
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply
#3

what about an isset() check? 
PHP Code:
$file $this->request->getFile('userfile');

if(isset(
$file)){..things go on..} 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB