You should first test the existence of a file by file_exists().
try { $fileName = 'uploads/Team/img/'.$team_id.'.png'; if ( !file_exists($fileName) ) { throw new Exception('File not found.'); } $fp = fopen($fileName, "rb"); if ( !$fp ) { throw new Exception('File open failed.'); } $str = stream_get_contents($fp); fclose($fp); // send success JSON } catch ( Exception $e ) { // send error message if you can }
or simple solution without exceptions:
$fileName = 'uploads/Team/img/'.$team_id.'.png'; if ( file_exists($fileName) && ($fp = fopen($fileName, "rb"))!==false ) { $str = stream_get_contents($fp); fclose($fp); // send success JSON } else { // send error message if you can }
Other than caching every hour, or every week, you may cache according to file data.…
To get host url of current server simply replace application\config\config.php [crayon-662e707f809a8104517357/] with [crayon-662e707f809ae814729938/]
[crayon-662e707f80b26903821815/] Output the random string with the call below: [crayon-662e707f80b2d871561613/]
Note: from WordPress Use it like this: [crayon-662e707f80c8e549257231/] Code: [crayon-662e707f80c93711618819/]
[crayon-662e707f80f60505488801/] or [crayon-662e707f80f66563697296/]