Hi,
I am working on my proxy script again and realized that images can't load directly because they are blocked! Now to get this to work, I need to replace all of those URLs with another one. I have a secondary script that loads an image onto my server, and echos the result. This is what should appear in the proxy.php file:
<img src="http://www.johninteractive.net/proxy/proxyimage.php?url=FULL _URL__OF_IMAGE_HERE
However, I need to get that URL replace with my URL, followed by the FULL_URL_HERE part. Get what I'm saying? I made a regex expression to try to solve this issue:
[^0-9A-Za-z]+[A-Za-z]+(.jpg|.png|.gif|.bmp)
But it doesn't work.
Can somebody tell me a regex code that will replace a full URL of an image (bmp, jpg, png, gif, etc.) with my URL?:
http://www.johninteractive.net/proxy/proxyimage.php?url=ORIGINAL_URL
Thanks.
Here is the proxy.php code:
<form action="proxy.php" method="GET">
<input type="text" name="url" size="40" value="Enter URL here"><br>
<input type="submit" value="Browse Anonymously"><hr>
</form>
<?php
$url = $_GET['url'];
$sourcecode = file_get_contents($url);
function trueUrl($text, $url)
{
$search = array(
'#((?:href|src)=(["\']))(/.*)(?:\2)#isU',
'#((?:href|src)=(["\']))([^/][^:]*)(?:\2)#isU'
);
$replace = array(
'\1'.array_shift(preg_split('#(?<!/)/(?!/)#', $url)).'\3\2',
'\1'.dirname($url).'/\3\2'
);
return(preg_replace($search, $replace, $text));
}
trueUrl($sourcecode, $url);
$pattern = "/[^a-z]+[a-z]+(.jpg|.png|.gif|.bmp)/";
$replacement = "http://www.johninteractive.net/proxy/proxyimage.php?url=$0";
preg_replace($pattern, $replacement, $sourcecode);
echo $sourcecode;
?>
Here is the proxyimage.php file:
<?php
$url = $_GET['url'];
$handle = imagecreatefromgd($url);
header("Content-type: image/jpg");
imagejpg($handle);
imagedestroy($handle);
?>