Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 图像未正确保存_Php_Image_Text - Fatal编程技术网

Php 图像未正确保存

Php 图像未正确保存,php,image,text,Php,Image,Text,这是我正在制作的项目的链接: 很简单,您可以键入任何内容并按submit,然后转到下一页并在图片上显示文本。一切都很好,但当我右键单击图片并尝试保存它时,扩展名会像“picture.php.jpe”一样奇怪 图片生成页面代码如下所示 <?php //Set the Content Type header('Content-type: image/jpeg'); // Create Image From Existing File $jpg_image = imagecreatefromj

这是我正在制作的项目的链接:

很简单,您可以键入任何内容并按submit,然后转到下一页并在图片上显示文本。一切都很好,但当我右键单击图片并尝试保存它时,扩展名会像“picture.php.jpe”一样奇怪

图片生成页面代码如下所示

<?php
//Set the Content Type
header('Content-type: image/jpeg');

// Create Image From Existing File
$jpg_image = imagecreatefromjpeg('vote.jpg');

// Allocate A Color For The Text
$white = imagecolorallocate($jpg_image, 47, 45, 46);

// Set Path to Font File
$font_path = 'MISTRAL.TTF';

// Set Text to Be Printed On Image
$text = $_POST['name'];

// Print Text On Image
imagettftext($jpg_image, 75, 0, 500, 130, $white, $font_path, $text);

// Send Image to Browser
imagejpeg($jpg_image);

// Clear Memory
imagedestroy($jpg_image);
?> 

这里的解决方案是
内容配置
,但具体需要什么取决于用户界面的工作方式

您要设置:

header('Content-Disposition: %token%; filename="%name_of_file%"');
其中:

  • %name\u of_file%
    是您希望用户看到的文件的名称

  • %token%
    附件
    内联
    之一。如果将其设置为
    附件
    ,将立即提示用户下载该文件,浏览器将不会像当前那样显示图像。如果设置了“内联”,用户将在浏览器窗格中显示当前的图像,他们需要右键单击->另存为以保存图像

在决定使用哪个标题之前,您需要决定UI的工作方式

为清楚起见,以下是几个具体示例:

// Prompt the user to save the file immediately
header('Content-Disposition: attachment; filename="file.jpg"');

// OR

// Display the image to the user and ask them to manually save it
header('Content-Disposition: inline; filename="file.jpg"');

值得注意的是,IIRC,IE的旧版本在
inline
方面存在问题,因为他们没有注意到建议的文件名。但是,可以通过向
内容类型:
添加
name=”“
标记来解决此问题。这违反了标准,但也相当无害。

这里的解决方案是
内容处理
,但具体需要什么取决于用户界面的工作方式

您要设置:

header('Content-Disposition: %token%; filename="%name_of_file%"');
其中:

  • %name\u of_file%
    是您希望用户看到的文件的名称

  • %token%
    附件
    内联
    之一。如果将其设置为
    附件
    ,将立即提示用户下载该文件,浏览器将不会像当前那样显示图像。如果设置了“内联”,用户将在浏览器窗格中显示当前的图像,他们需要右键单击->另存为以保存图像

在决定使用哪个标题之前,您需要决定UI的工作方式

为清楚起见,以下是几个具体示例:

// Prompt the user to save the file immediately
header('Content-Disposition: attachment; filename="file.jpg"');

// OR

// Display the image to the user and ask them to manually save it
header('Content-Disposition: inline; filename="file.jpg"');

值得注意的是,IIRC,IE的旧版本在
inline
方面存在问题,因为他们没有注意到建议的文件名。但是,可以通过向
内容类型:
添加
name=”“
标记来解决此问题。这违反了标准,但也相当无害。

强制浏览器下载它…你能告诉我怎么做吗?我用Firefox尝试过,它将图片保存为
picture.php.jpg
@user2021236,DaveRandom发布了一个带有该代码的答案:)强制浏览器下载它…你能告诉我怎么做吗?我用Firefox尝试过,它将图片保存为
picture.php.jpg
@user2021236,DaveRandom发布了一个带有该代码的答案:)你先生很棒,谢谢:)你先生很棒,谢谢:)