Forum Moderators: coopster
<?php
if (@fclose(@fopen("http://www.example.com", "r"))) {
print("File exists.");
} else {
print("File does not exist.");
}
?>
Also, the notes indicate that with PHP 5.0, file_exists() can be used with some url wrappers, which might make checking for the existance of remote files easier.
When it returns the wrong information, what does it tell you?
There is a single link of code that opens the file, closes it, and then checks to see if those functions returned true (operated correctly). Try removing the @ signs (so that errors are not supressed) and see what errors you receive.
Perhaps it's an issue with the network connection, where sometimes it can open the file and others it can't because the connection to the remote server cannot be made. I use fopen() on remote files all the time and have never really had any issues with it.
I am a complete newbie with php. I've tried to adapt the code below to pick up whether an image file exists, if so display it if not display a "no image exists" image instead.
The image file is picked up by using the article field and adding ".jpg" to it. Is this causing the problem, rather than having a dedicated image column in the database? Or is it just a syntax or bad coding error (Ihave tried using various double and single quotes within code).
If anyone has any ideas I'd be really grateful to hear them.
Thanks
<?php
$image= ("images/"$row_Recordset1['article']".jpg");
if (@fclose(@fopen("$image", "r"))) {
print("<img src='images/' $row_Recordset1['article'] '.jpg' border='1'>");
}
else {
print("<img src='images/noimage.jpg'>");
}
?>