I have two domains sharing the same server. One of them, site_1.com, holding images at directory /images and the other one site, site_2.com, must to show those images. I have the following code at site_2:
<html>
<body>
<img src="http://site_1.com/images/img.png" />
</body>
</html>
Result: It didn't work. After reading a lot of answers and comment here and other forums I applied their sugges of using for example an api at site_1 like this:
/api/get_image.php at site_1.com:
<?php
$file_name = $_GET['file_name'];
$url = 'http://site_1.com/images/'.$file_name;
header('Content-type: image/png');
imagepng(imagecreatefrompng($url));
?>
And call the api at site_2.com like this:
<html>
<body>
<img src='http://site_1.com/api/get_image.php?file_name='img.png' />
</body>
</html>
It didn't work. Another way using file_get_contens():
<?php
$file_name = $_GET['file_name'];
$url = 'http://site_1.com/images/'.$file_name;
$img = file_get_contents($url) ;
echo $img ;
?>
It didn't work. Another way using CURL library:
<?php
$file_name = $_GET['file_name'];
$url = 'http://site_1.com/images/'.$file_name;
//
$ch = curl_init();
$timeout = 0;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$image = curl_exec($ch);
curl_close($ch);
echo $image ;
?>
It didn't work.
It's problably that I'm doing something wrong but I don't know what is. By the way, allow_url_fopen is ON and may be I have to active some other flag in some configuration file of apache or php. Please, could anybody tell me where is the problem? I appreciate any help.