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-679fd5061e148127023190/] with [crayon-679fd5061e14e048123362/]
[crayon-679fd5061e2d3513193983/] Output the random string with the call below: [crayon-679fd5061e2d8890840973/]
Note: from WordPress Use it like this: [crayon-679fd5061e3fd186986583/] Code: [crayon-679fd5061e402635036056/]
[crayon-679fd5061e7f5134427249/] or [crayon-679fd5061e7fb609718313/]