I fear that you are implicitly saying that you are using file_get_contents() with a remote URL (http://...), because it makes nonsense talking about 404 for local filesystem.
In that case I don't think there are clean ways of doing that. Instead, use cURL, which allows you to examine carefully the HTTP response code (200, 302, 400, 404, etc..) and the returned http headers.
It also give you more control over timeouts, request parameters, headers, etc. which the URL-wrapper doesn't offer you.
If you really meant local files, you stat() or is_file(), is_readable() before using file_get_contents().
Main Topics
Browse All Topics





by: Rok-KraljPosted on 2008-01-16 at 15:41:04ID: 20677417
if (!file_get_contents($file) ) {
die('ERROR!');
}