View Full Version : Loading external image bypassing SSL

Phil Jackson
10-14-2009, 08:38 AM
Morning all. I was wondering, as im at the hair pulling stage, how i can load an external image without causing SSL errors. I thought there might be a php solution, using maybe the GD lib but you need to declair the header but there is other info on page. Anyone any ideas?

Phil Jackson
10-14-2009, 09:16 AM
I've worked out a work around but not really the answer. uploading images that are viewed on the fly by working out the absolute path, get contents, if not exist, write to file then view in place by replacing the src.

10-14-2009, 02:07 PM
That's fairly easy to do, IMO.


// Uses URLs like lib.php?img=http://blah.com/blah.gif (URL ENCODED OF COURSE)

$file = isset($_GET['img']) && !empty($_GET['img']) ? $_GET['img'] : false;

if(!$file) {
echo 'Invalid IMG URL';

$ext = substr(strrchr($file, '.'), 1);

switch($ext) {
case 'jpg': case 'jpe': case 'jpeg':
$type = 'jpeg';
$type = $ext;

if(!in_array($ext, array('png', 'jpeg', 'gif', 'bmp'))) {
echo 'Invalid Image.';

header('Content-type: image/'. $type);

That's the method I use. If you want to add compression, you can add ob_start('ob_gzhandler'); to the beginning.

Doesn't even require a script to transfer files to your server. :)