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_compa re($_SERVER["HTTP_REFER ER"], $_SERVER["SERVER_NAM E"], 0, strlen($_SERVER["SERVER_NAM E"]))){
//echo "<br>".$path.$f ileName."<br>";
$size = getimagesize($p ath.$fileName);
$fp = fopen($path.$fi leName, "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="Linktothat code?file">
However when modified into
[PHP] function fetchImage($fil eName, $full){
$ext = substr(strrchr( $fileName, "."), 1);
$path = "../../../include/images/mini/";
if($full)
$path = "../../../include/images/full/";
else
$path = "../../../include/images/mini/";
if(substr_compa re($_SERVER["HTTP_REFER ER"], $_SERVER["SERVER_NAM E"], 0, strlen($_SERVER["SERVER_NAM E"]))){
//echo "<br>".$path.$f ileName."<br>";
$size = getimagesize($p ath.$fileName);
$fp = fopen($path.$fi leName, "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_b inary">
Here is the code for the test document.
[PHP]
<?php
include ("../../../include/fetchImage.php" );
?>
<img src="<?php fetchImage("e49 3cac401eab12d8a 9ebf989a0efd3ec 47e31601.jpg", 1) ?>" id=\"imgTop\" onmouseover=\"r ollover(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?
[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_compa re($_SERVER["HTTP_REFER ER"], $_SERVER["SERVER_NAM E"], 0, strlen($_SERVER["SERVER_NAM E"]))){
//echo "<br>".$path.$f ileName."<br>";
$size = getimagesize($p ath.$fileName);
$fp = fopen($path.$fi leName, "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="Linktothat code?file">
However when modified into
[PHP] function fetchImage($fil eName, $full){
$ext = substr(strrchr( $fileName, "."), 1);
$path = "../../../include/images/mini/";
if($full)
$path = "../../../include/images/full/";
else
$path = "../../../include/images/mini/";
if(substr_compa re($_SERVER["HTTP_REFER ER"], $_SERVER["SERVER_NAM E"], 0, strlen($_SERVER["SERVER_NAM E"]))){
//echo "<br>".$path.$f ileName."<br>";
$size = getimagesize($p ath.$fileName);
$fp = fopen($path.$fi leName, "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_b inary">
Here is the code for the test document.
[PHP]
<?php
include ("../../../include/fetchImage.php" );
?>
<img src="<?php fetchImage("e49 3cac401eab12d8a 9ebf989a0efd3ec 47e31601.jpg", 1) ?>" id=\"imgTop\" onmouseover=\"r ollover(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?
Comment