php 直接将字符串下载为文本文件

<?php
    $text="字符串直接下载";
    $fileName="qwert.txt";
    header("Content-Type: application/txt");
    header("Content-Disposition: attachment; filename=".$fileName);
    echo $text;
?>

http://blog.csdn.net/u010384444/article/details/51769044

 

类似地,也可以直接将内存中的图片直接下载为图片文件。关键是先设置头信息,再echo内容。

$fileres = file_get_contents('d:/a.jpg');
header('Content-type: image/jpeg');
echo $fileres;

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

<?php
    $image=imagecreatetruecolor(100,100);
    $red=imagecolorallocate($image,0xff,0x00,0x00);
    imagefill($image,0,0,$red);
    header('Content-type:image/png');
    imagepng($image);
    imagedestroy($image);
?>

 

header("Content-type: plain/text;charset=utf-8");
header("Content-type: text/html;charset=utf-8");
header("Content-type: application/json;charset=utf-8");

 

posted @ 2018-02-28 15:54  sky20080101  阅读(684)  评论(0)    收藏  举报