• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use one time library instead of two time

As I understand correctly from this code I ask one time "image_upload" if have error and two time when everything is ok! so first time I check for error and the second chtck / get data to variable. Is there a chance to check for error and if no get data, not to ask two time?

if (!$this->image_upload_lib->image_upload($config)) {
                    $error_status = "error";
                    $error_msg = $this->image_upload_lib->get_error_message();
} else {          
      $image_name = $this->image_upload_lib->image_upload($config);

Just want to improve my code and get more knowledge.

Thank you !

Since "image_upload_lib" is not a standard CI library, can't really say for sure what's correct for it specifically. But that's pretty redundant code - you should perform the upload once, then check if it was successful. The CI File Upload library has an example of how it handles uploads.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.