drgzmmy6379 2011-09-20 14:44
浏览 207

为什么图像请求生成302?

I'm using PHP to generate the following image element:

<img id="uploaded-image" src="http://localhost/gonzo/plans/image/123/tablemap.png" />

This image URL is routed through my PHP MVC framework to the following function, which grabs the image from my db and prints it:

    public function image($hexCode='',$fileName) {

    if (!$this->validRequest('get')) return false;

    Framework::loadModel('plan_model.php');
    $plan = new PlanModel();

            // Return image data from Blob field in db.
    $image = $plan->getImage('123');

    if ($image) {
        header("Content-Type: image/png");
        print $image;
        die;
    } else {
        echo 'error';
    }
}

The request generates a 302, with the wrong location and content-type headers:

enter image description here

The browser does not display the image where this image tag is on the page. But, when the image URL is typed directly into the address bar, the image is displayed.

Why would my server be generating a 302 when loading the image into an tag, but generating a 200 when the image URL is typed directly into the address bar? I'm running Apache on Windows.

  • 写回答

2条回答 默认 最新

  • dongshengheng1013 2011-09-20 14:51
    关注

    The described behavior isn't possible at all - since the server doesn't know a bit about how an URL is embedded in a web-page.

    Provide more details of the actual call of the PHP-script: Print environmental details - $_GET, $_POST and $_SERVER - to a log file.

    It might be helpful to register a tick-function and trace each executed statement to a log-file.

    Check your PHP sources.

    评论

报告相同问题?