You are here: Re: How to check remote file... « PHP Programming Language « IT news, forums, messages
Re: How to check remote file...

Posted by Jerry Stuckle on 08/18/06 12:01

sree wrote:
> Hi,
>
> No probs. I got the solution for this.
>
> that is,
>
> <?php
> $TheImage = "http://www.uk-present.co.uk/images/logo.gif";
> if (@fclose(@fopen("$TheImage", "r"))) {
> $TheImage = "$TheImage";
> }
> else {
> $TheImage = "http://www.uk-present.co.uk/images/120x60-noimage.gif";
> }
> ?>
>
> The first if loop tells you that the image exist, else it does not
> exist
>
>
>
> However it works only when the server gives you 404 error
>
>
>
> Chung Leong wrote:
>
>>sree wrote:
>>
>>>Hi,
>>>
>>>
>>> i want to check whether a file from remote server is existed or
>>>not.
>>>
>>>The file_exists() checks for local server only. But i want a function
>>>that checks the remote server.
>>>
>>>
>>>If anyone knows please help..
>>>
>>>thanks in advance...
>>>
>>>regards
>>>sree
>>
>>This will do the trick:
>>
>>if(@fopen($url, "rb")) {
>>}
>
>

You shouldn't call fclose() on a file handle which never opened. It's
an error - which you're hiding with the @. But the error still occurs,
is still logged and still takes system resources to handle. Better would be:

<?php
$TheImage = "http://www.uk-present.co.uk/images/logo.gif";
if (($fh = fopen("$TheImage", "r"))) {
$TheImage = "$TheImage";
fclose($fh);
}
else {
$TheImage = "http://www.uk-present.co.uk/images/120x60-noimage.gif";
}
?>

Generally, if you have to use '@' you should look at why you need to use it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация