Jump to content

Image return question


projectgoldfish

Recommended Posts

Currently im taking this old piece of code

 

$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;
    } 

 

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


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;
    }
} 

 

 

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
include ("../../../include/fetchImage.php");
?> 
<img src="<?php fetchImage("e493cac401eab12d8a9ebf989a0efd3ec47e31601.jpg", 1) ?>"    id=\"imgTop\" onmouseover=\"rollover(0)\">

 

 

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?

Link to comment
https://forums.phpfreaks.com/topic/42705-image-return-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.