Currently im taking this old piece of code
[PHP]
$fileName = $_GET["file"];
$full = $_GET["full"];
$ext = substr(strrchr($fileName, "."), 1);
$path = "../../../include/images/mini/";
if($full)
$path = "../../../include/images/full/";
else
$path = "../../../include/images/mini/";
if(substr_compare($_SERVER["HTTP_REFERER"], $_SERVER["SERVER_NAME"], 0, strlen($_SERVER["SERVER_NAME"]))){
//echo "<br>".$path.$fileName."<br>";
$size = getimagesize($path.$fileName);
$fp = fopen($path.$fileName, "rb");
if ($size && $fp) {
header("Content-type: {$size['mime']}");
fpassthru($fp);
exit;
} else {
echo "Unable to find file to open";
// error
}
}else{
return null;
}[/PHP]
And modify it into a funciton that will later be oved into a class. The code above runs perfectly when run by itself or via <img src="Linktothatcode?file">
However when modified into
[PHP] function fetchImage($fileName, $full){
$ext = substr(strrchr($fileName, "."), 1);
$path = "../../../include/images/mini/";
if($full)
$path = "../../../include/images/full/";
else
$path = "../../../include/images/mini/";
if(substr_compare($_SERVER["HTTP_REFERER"], $_SERVER["SERVER_NAME"], 0, strlen($_SERVER["SERVER_NAME"]))){
//echo "<br>".$path.$fileName."<br>";
$size = getimagesize($path.$fileName);
$fp = fopen($path.$fileName, "rb");
if ($size && $fp) {
header("Content-type: {$size['mime']}");
fpassthru($fp);
exit;
} else {
echo "Unable to find file to open";
// error
}
}else{
return null;
}
}[/PHP]
All that prints to the test document is the called url.
The html of the document shows the <img src="the_ascii_representation_of_the_images_binary ">
Here is the code for the test document.
[PHP]
<?php
include ("../../../include/fetchImage.php");
?>
<img src="<?php fetchImage("e493cac401eab12d8a9ebf989a0efd3ec47e31 601.jpg", 1) ?>" id=\"imgTop\" onmouseover=\"rollover(0)\">[/PHP]
I have assured that all files exist in the directories that im specifying.
What is so different about the 2 different fetching methods that would cause such a differerence in result?