php - 如何为用 PHP 生成的图像设置默认名称 'save-as'?

标签 php header

这是我的代码。

<?php
function generate_card($card_number='',$card_price='',$card_expire='',$image_path='',$font_path)
{
    // store image on variable //
    $image = imagecreatefrompng($image_path);

    // some text color
    $color = imagecolorallocate($image, 255, 255, 0);

    // print card price //
    imagettftext($image, 15, 0, 200, 40, $color, $font_path, $card_price);
    // print card number //
    imagettftext($image, 15, 0, 15, 85, $color, $font_path, $card_number);
    // print expiry date //
    imagettftext($image, 12, 0, 145, 155, $color, $font_path, $card_expire);

    header('Content-type:image/png');
    imagepng($image);
    imagedestroy($image); 
}
generate_card('1234 5678 9101 1121','$200','12/13','card.png','verdana.ttf');
?>

我正在生成 visa 礼品卡,图像也已创建并显示在页面上。但我的问题是,当我想在 Mozilla 中保存此图像时,它给出了“page_name.png”,而在 IE 中,它给出了“Untitled”。 我如何在保存时给出自己的名字,如“visa_gift_01.png”。

最佳答案

阅读此 document 它解释了如何修改 http header

header('Content-Disposition:attachment;filename="visa_gift_01.png"');

关于php - 如何为用 PHP 生成的图像设置默认名称 'save-as'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4202862/

相关文章:

PHP header - 内容类型 : image/jpeg - Not working for Internet Explorer

php - 如何压缩整个目录并使用php下载

php - PHP数据表的 overflow hidden

php - Laravel beyondcode websockets 不连接

javascript - 通过链接将多个用户发送到同一个谷歌视频群聊(在新窗口中)

html - 设置正文背景时标题隐藏

c++ - 在 C++ 中找不到枚举头文件

php - UTF-8 内容类型元标记会减慢页面加载速度,为什么?

sleep 和循环期间的 PHP 内存使用情况

php - 读取路由函数中的 Blade 变量