Forum Moderators: coopster

Message Too Old, No Replies

How to include a remote image when loading locallly fails?

Change img's src property on the fly

         

tntpower

12:31 am on Feb 18, 2010 (gmt 0)

10+ Year Member



When loading a local image such as below fails,

<img src="/image/hello.gif" />


I would like to change image's src property on the fly so that the above tag will work in this way

<img src="http://example.com/image/hello.gif" />


Right now, I use


$fh = @fopen("http://example.com/image/hello.gif", rb);

if ($fh !== FALSE) {

header("Location: http://example.com/image/hello.gif");

......


The point is that I first need to know if such a remote file exists. If yes, then get it by using header function.

But it is pretty slow.

How can I improve the performance?

Thanks,

[edited by: dreamcatcher at 8:09 am (utc) on Feb 18, 2010]
[edit reason] use example.com, thanks. [/edit]

jatar_k

1:30 pm on Feb 18, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



If the slow load is just waiting for the remote image then there isn't much you can do.

you could try some other functions aside from fopen to see if that works, maybe getimagesize [ca.php.net] would be different, may not though