added error handling on fread and file_get_contents.