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-6928d783b8692793825806/] with [crayon-6928d783b8699797385670/]
[crayon-6928d783b88bd026875895/] Output the random string with the call below: [crayon-6928d783b88c2763850218/]
Note: from WordPress Use it like this: [crayon-6928d783b8b18415212794/] Code: [crayon-6928d783b8b1f525435018/]
[crayon-6928d783b903c513785759/] or [crayon-6928d783b9041639629234/]