You are here: Re: Img src Code works in Firefox but broken in IE « PHP Language « IT news, forums, messages
Re: Img src Code works in Firefox but broken in IE

Posted by JP on 09/05/05 16:12

Hi Stefan,

Thanks for the suggestion. In fact, this is how I have implemented it
at the moment i.e. I pass the primary key of the thumbnail image to a
php script that queries the image off the mysql db and displays it and
it works in both IE and Firefox.

Thing is though, this means I am doing 50 separate mysql query calls
(one for each image) just to load one page and it just really bugs me
because I know I can get an array containing all 50 images in a one hit
query.

In terms of performance when I use the (one hit query -> 50 images in
one array with echo '<img src="data:image/png;base64,'.$encoded.' ">';)
method in Firefox the page loads up nice and quick.

But if I use the (pass the key and have one mysql query for every image)
it is very slow - especially during the day (but not too bad at night).

I think it's coming down to two choices :

1) Use the write to file method that you suggested which is almost
certainly bullet proof for every browser and probably ok for loading speed.

2) Test which browser the user is using (at the moment I don't know how
to do this as I am new to PHP)
- if they are using Firefox use the super fast (echo '<img
src="data:image/png;base64,'.$encoded.' ">';) method and

- if they are using Internet Explorer use either method (1) or keep it
as it is i.e. (pass the key and have a mysql query for every image).

I know this discriminates against IE users but what else can I do :)

Any other suggestions greatly appreciated.

Cheers,
JP




Stefan Rybacki wrote:
> JP wrote:
>
>> Hi Stefan,
>>
>> I know I could do this (write to a temp file) but I was hoping to
>> avoid this step if at all possible. The page at the moment displays
>> about 50 thumb images (and there will be more) and I would have to do
>> write out every image. Obviously this would increase the page load
>> time (though I don't know by how much) and I am trying to keep the
>> loading time as low as possible.
>>
>
> You don't. Imagine 50 pictures saved in compressed png format and 50
> pictures saved in base64 format? Which will take more time to load? If
> you don't want to save the images temporary what about this:
>
> echo '<img src="temp/thumb.php?pic=xxx">';
>
> thumb.php:
>
> //get the id of the picture
> $pic=(int)$_REQUEST['pic']
>
> //load picture from database and store in $image
> ...
>
> header("image/png");
> echo $image;
>
>
> Stefan
>
>> Cheers
>> JP
>>
>> Stefan Rybacki wrote:
>>
>>> JP wrote:
>>>
>>>> Hi,
>>>>
>>>> I need to use the <img src tag to output a variable of an image and
>>>> so I borrowed a piece of code I found on the php.net website under
>>>> the documentation for the function base64_encode().
>>>>
>>>> http://uk2.php.net/manual/en/function.base64-encode.php
>>>>
>>>> This worked perfectly well under firefox but I just get a broken
>>>> image using Internet Explorer. I looked again and on the php.net
>>>> website (again under the base64_encode() notes someone stated ...
>>>>
>>>> "To embed binary contents in ascii text based html file for IE, you
>>>> need use MIME multipart."
>>>>
>>>> Does anyone know how to do this.
>>>>
>>>> Cheers
>>>>
>>>> JP
>>>>
>>>> //Code that works under firefox but breaks IE
>>>> <?
>>>> //get a thumbnail from a mysql database into a variable
>>>> $thumbnail_image = $row['thumb_image'] ; //
>>>>
>>>> //encode the variable
>>>> $encoded = chunk_split(base64_encode($thumbnail_image));
>>>>
>>>> //then echo to browser as:
>>>> echo '<img src="data:image/png;base64,'.$encoded.' ">';
>>>> ?>
>>>
>>>
>>>
>>>
>>> Why this complicated? Just store the image into a temporary folder or
>>> similar and link to it.
>>>
>>> echo '<img src="temp/pic.png">';
>>>
>>> Stefan

 

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

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