Page 1 of 1

fopen issue [SOLVED]

Posted: Mon Dec 26, 2005 11:12 am
by Jade
Hey there,

I was wondering if anyone knows how to workaround an fopen issue I've been having. Users on my website can link to photos, and if the photo isn't there then of course I get an fopen message: fopen(http://www.spendthriftfarm.com/Photos/m ... -brown.jpg): failed to open stream: HTTP request failed! HTTP/1.1 404

that everyone sees. Is there any good way to check if the photo is there before I call fopen so I don't have this issue? I've tried things like this but nothing seems to be working

Code: Select all

$fp = fopen($file, 'r');

if ($fp)
 ;//display photo
else
 ; //photo not found

Posted: Mon Dec 26, 2005 11:17 am
by josh

Code: Select all

if(file_exists('file')) {

// open it
} else {
echo 'technical difficulties';
}
you should also log errors instead of displaying them, avoid this issue all together

Another way to temporarily suppresss errors is with @

Code: Select all

@fopen('file');
will never show an error

Posted: Mon Dec 26, 2005 11:33 am
by Jade
file_exists($file) never seems to work for me, but supressing the warning did. Thanks.

Jade

Posted: Mon Dec 26, 2005 11:35 am
by josh
Post code of where file_exists() didn't work.. suppressing the error isn't "wrong" per 'se but you'll be better off doing it the "right" way


also try calling
clearstatcache () right before the call to file_exists()