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-68bb69d2a02ad459454582/] with [crayon-68bb69d2a02b3632746615/]
[crayon-68bb69d2a310e960482752/] Output the random string with the call below: [crayon-68bb69d2a311b231939057/]
Note: from WordPress Use it like this: [crayon-68bb69d2a355a677130439/] Code: [crayon-68bb69d2a3564103600400/]
[crayon-68bb69d2a3d57737970620/] or [crayon-68bb69d2a3d5e675651076/]