php - CakePHP, triple equal signs misunderstanding -


hi i'm making tutorial cakephp , got stuck when @ if statement.

please @ if statement triple equal signs.

class item extends appmodel{ protected function _processfile(){     $file = $this->data['item']['file'];     if($file['error'] === upload_err_ok){         $name = md5($file['name']);         $path = www_root.'files'.ds.$name;         if(is_uploaded_file($file['tmp_name']) &&             move_uploaded_file($file['tmp_name'],$path)){              $this->data['item']['title_img'] = '/files/'.$name;             unset($this->data['item']['file']);             return true;         }     }     return false; 

here question

why if statement when makes error uploading file executes rest of codes upload file?

should rest of codes placed @ "return false;"?

please let me know missed understand if statement.

thank guys

this basic php , not related cakephp: see http://php.net/manual/en/language.operators.comparison.php , link http://php.net/manual/en/types.comparisons.php.

$a == $b    equal       true if $a equal $b after type juggling. $a === $b   identical   true if $a equal $b, , of same type. 

you're doing comparison based on type, try == instead of ===. php not strict typed language that's why have == , ===.

some extras:

  • instead $this->data['item'] use $this->data[$this->alias] in models.
  • follow cakephp coding conventions
  • you should not check if file uploaded handle error cases

and if don't want re-invent wheel can checkout filestorage plugin or take @ it's code.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -