Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I have a website running on https. I have to load images from external server (external domain) which doesn't have https, but single http protocol.

Is there's any way to handle proxy for http images via PHP or Node? So I can render images like this:

<img src="https://domain.com/proxy?url=http://externaldomain.com/image.jpg" />

The idea is to avoid saving images on local, but only display them.

When I try to render http served images inside https domain, I get this console message:

The page at https://domain.com/ displayed insecure content from http://externaldomain.com/image.jpg.

As well, my SSL (/https) lock icon inside address bar becomes grey.

share|improve this question

3 Answers 3

You should first download them using php cURL library. If you don't want to store images on hard drive. You can add them as data URIs in the src attribute.

share|improve this answer

something like this should work:

<?php
    header('Content-type: image/jpeg;');
    $p = "http://i.imgur.com/jB3xD75.jpg";
    $a = file_get_contents($p);
    echo $a;
?>
share|improve this answer

You can use node, which will just pipe the image instead of loading the whole image into memory before sending to the client (like file_get_contents would do in php). Using request in this example for simplicity in streaming:

var https = require('https');
var url = require('url');
var request = require('request');

var server = https.createServer(function (req, res) {
  var queryData = url.parse(req.url, true).query;

  if (queryData.url) {
    var x = request(queryData.url);
    req.pipe(x).pipe(res);
  } else {
    res.writeHead(400, {"Content-Type": "text/plain"});
    res.end("No url");
  }
});

// Listen on port 443
server.listen(443);
share|improve this answer
    
I'll try it and see if it works for me. – manakor Jun 17 '13 at 11:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.