I have a simple php code which loads an external XML file and loads the pictures URL’s into my database.
Then I take the URL’s and display them on my site.
The problem is that I end up loading pictures from other websites on my site, which affect loading time – loading 20 pictures per page now.
So I am thinking, Is there a way to store the image completely into my database, instead of just the URL?
Here is the code:
$myfeed = 'xmlfeed.xml';
$myfeed_xml = simplexml_load_file($myfeed);
foreach($myfeed_xml->info as $myinfo){
$pic0 = $myinfo->picture_url[0];
$pic1 = $myinfo->picture_url[1];
$pic2 = $myinfo->picture_url[2];
$pic3 = $myinfo->picture_url[3];
$pic4 = $myinfo->picture_url[4];
if($pic0 != ''){
mysql_query("INSERT INTO ".$table." (pic0, pic1, pic2, pic3, pic4) VALUES ('$pic0', '$pic1', '$pic2', '$pic3', '$pic4')", $dbh);
}
}
Thank you!
Why not download them all on your server, and update the DB with the links from your server? As long as copyright policie(s) are okay with it…
So what the code above does is simply goes through all the 3rd party links in your DB and downloads their content (images) to your server. Then you can simply update the DB with your own link to the specific image. Simple. But as I previously mentioned, check copyright licenses first as I’m sure you don’t want to be getting into trouble now, hm?