我有一个PHP页面,它使用GET参数创建JPEG。我想让用户能够下载该页面的输出JPEG文件。我该怎么做?
非常基本:
<?php
header('Content-type: image/jpeg');
readfile('cutepuppies.jpg');
设置标题:
// Set the content type header - in this case image/jpeg
header('Content-Type: image/jpeg');
至少设置Content-Type标头-
header('Content-Type: image/jpeg');
一种方法是利用imagejpeg功能-
http://php.net/manual/en/function.imagejpeg.php
像往常一样从php返回输出,但请确保在任何其他输出之前发送一些jpeg的内容类型标头。
<?php header("Content-type: image/jpeg"); ?>