允许用户以JPEG格式下载PHP页面

时间:2012-01-10 19:27:29

标签: php image

我有一个PHP页面,它使用GET参数创建JPEG。我想允许用户能够将该页面的输出下载为JPEG文件。我怎么能这样做?

4 个答案:

答案 0 :(得分:5)

非常基本:

<?php
header('Content-type: image/jpeg');
readfile('cutepuppies.jpg');

答案 1 :(得分:1)

像往常一样从php回显输出,但请确保在任何其他输出之前发送一些jpeg的内容类型标题。

<?php header("Content-type: image/jpeg"); ?>

答案 2 :(得分:1)

设置header

// Set the content type header - in this case image/jpeg
header('Content-Type: image/jpeg');

答案 3 :(得分:1)

至少设置Content-Type标题 -

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

一种方法是使用imagejpeg函数 -

http://php.net/manual/en/function.imagejpeg.php