Php 图像未正确保存
这是我正在制作的项目的链接: 很简单,您可以键入任何内容并按submit,然后转到下一页并在图片上显示文本。一切都很好,但当我右键单击图片并尝试保存它时,扩展名会像“picture.php.jpe”一样奇怪 图片生成页面代码如下所示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
<?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%
或附件
之一。如果将其设置为内联
,将立即提示用户下载该文件,浏览器将不会像当前那样显示图像。如果设置了“内联”,用户将在浏览器窗格中显示当前的图像,他们需要右键单击->另存为以保存图像附件
// 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%
或附件
之一。如果将其设置为内联
,将立即提示用户下载该文件,浏览器将不会像当前那样显示图像。如果设置了“内联”,用户将在浏览器窗格中显示当前的图像,他们需要右键单击->另存为以保存图像附件
// 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发布了一个带有该代码的答案:)你先生很棒,谢谢:)你先生很棒,谢谢:)