To output error logs to file, “log_errors” must be “On” in php.ini.
1 2 3 4 5 6 |
if($debug_mode == true){ error_reporting(E_ALL); ini_set('display_errors',1); ini_set('display_startup_errors',1); ini_set('log_errors',1); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
error_reporting(E_ALL); set_error_handler('error_handler'); function error_handler($no, $msg, $filename, $line){ $p = 'error_log.txt'; $handle = fopen($p, 'w+'); fwrite($handle, 'File name:' . $filename . PHP_EOL); fwrite($handle, 'Line:' . $line . PHP_EOL); fwrite($handle, 'Msg:' . $msg . PHP_EOL); echo $line . ": " . $msg; exit(); } //trigger_error('cat:' . $cat, E_USER_ERROR); |
1 2 3 4 5 6 7 8 9 |
try{ move_uploaded_file($this->file["tmp_name"], $new_file); //throw new Exception('Custom error'); }catch(Exception $ex){ echo 'Message: ' . $ex->getMessage() . '<br/>'; echo 'Code: ' . $ex->getCode() . '<br/>'; echo 'File: ' . $ex->getFile() . '<br/>'; echo 'Line: ' . $ex->getLine() . '<br/>'; } |