Reputation: 26598
I am trying to download an image with file_get_contents PHP's function.
It receive an urlencode(url) via GET and return the content. This is the code:
<?php
$url=($_GET["url"]);
$url2 = ("http://www.liberoquotidiano.it/resizer.jsp?w=500&h=-1&maximize=true&img=upload/cut1372677360319.jpg&filetype=image.jpg");
echo "<br>Url 1 is via GET <br> Url2 is a variable instantiated in the script and its value is manually inserted.";
echo "<br>file_get_contents Url2 work, but with url1 not,althought the url content is the same. ";
echo "<br>1.url= ".$url;
echo "<br>2.url= ".$url2;
$r=strcmp($url2,$url);
if($r==0){
echo "correct";
}else{
echo "<br><br>string compare with url and url2 return ".$r;
}
echo "<br><br>launch: file_get_contents(url) => ";
$image_data = file_get_contents($url);
echo $image_data;
?>
url and url2 are the same but php strcmp code return 1, and not 0...I don't understand why. If I launch
file_get_contents($url);
it don't work and I haven't returned any value. If I launch
file_get_contents($url2);
it correctly work.
The curiousness is that url and url2 contains the same value, but the results differ.
This is the link at the script: http://www.clouderize.it/michele/get_cont.php?url=http%3A%2F%2Fwww.liberoquotidiano.it%2Fresizer.jsp%3Fw%3D500%26amp%3Bh%3D-1%26amp%3Bmaximize%3Dtrue%26amp%3Bimg%3Dupload%2Fcut1366795446185.jpg%26amp%3Bfiletype%3Dimage.jpg
What may be the problem? Thank you a lot.
Upvotes: 0
Views: 875
Reputation: 26598
Oks the problem is that in url there are some & I have substituted these with &.
$src=str_replace("&", "&", $src);
Upvotes: 0
Reputation: 369
$url = $_GET['url];
Are you using any html sort of things in the form from which you are fetching url. Is it there that user is entering url with html tags too or you are including some html tags with the url. Because, if strcmp is not giving 0 as output, it means that both url strings are not equal. There must be something which is causing the issue. And it can be html tags. Just check it once.
Upvotes: 1