0

i want to read .ico-Images from a Website, store the Information to the Database and show the Images later on a global Website.

I have managed to save the images in a string into the Database. The step to show the Images on a Website is my problem.

For reading the Contents:

$data=file_get_contents("http://www.google.com/favicon.ico");
$data = base64_encode($data);  

What is the right way to show that image in a single div on a website?

Fesp

Fesp
  • 127
  • 1
  • 13
  • 1
    Don't save files in a database. Save them on the file system, and store the path to it in the database. – Madara's Ghost May 08 '12 at 17:25
  • Take a look at this wikipedia article. http://en.wikipedia.org/wiki/Data_URI_scheme You can use the encoded string as image source – sofl May 08 '12 at 17:32

1 Answers1

0

You basically need to tell your script to output the content as an ico type.

<?php 
//Getting your image
$data=file_get_contents("http://www.google.com/favicon.ico");
$data = base64_encode($data);  

//If your storing in the db then you do the query ect togo get the data string

//Then echo out like this
header('Content-Type: image/vnd.microsoft.icon');
echo base64_decode($data);
?>

Remember you cant output anything before setting the header so perhaps you will need a seperate script to grab the file and ouput so

<img src="get_ico.php?id=1"/>

Then in get_ico.php

<?php 
//Connect db ect

//Query db for $_GET['id']

//Then echo out like this
header('Content-Type: image/vnd.microsoft.icon');
echo base64_decode($row['image_data']);
?>
Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106