5

I'm trying to determine if I should just directly

1) have PHP fetch an image binary and output (with header as image-type) image, eg:

/* $image = ... insert curl function to fetch image */

header('Content-Type: image/png');

echo $image;

or if I should have

2) a header redirect to the URL path of the image

header('Location: http://domain.com/pathtoimage/image.png');

Some initial questions:

In the first, would that amount to any overhead with PHP having to have the image in memory in order to output it?

In the second, would this lead to any errors on clients that somehow cannot follow the PHP header redirect?

4

1 回答 1

0

我反对标头 -> 位置解决方案,因为您将向服务器添加额外的请求。试试这个解决方案:

if (file_exists($file)) {
        header('Content-Type: image/png');
        readfile($file);
        exit;
    }

此解决方案应具有最小的开销和内存占用。

于 2013-04-02T12:58:05.790 回答