gpt4 book ai didi

php - 设置 header (内容类型 : image/)

转载 作者:可可西里 更新时间:2023-11-01 13:36:19 24 4
gpt4 key购买 nike

处理我显示的图像的 php 文件只允许一种图像格式,.jpg、.png、.bmp 等,但不是全部。 imageName 存储数据库中存储的图像的文件名,包括其格式。这是我的代码,到目前为止它还不起作用,我不确定是否允许这样做。你能帮我解决一下吗?

$con = mysqli_connect("localhost","root","","tickets");
$ticket = 109;
$result = mysqli_query($con,"SELECT image, imageName FROM tix WHERE tktNum=$ticket");


while($row = mysqli_fetch_array($result))
{
$image = $row['image'];
$imageName = $row['imageName'];
$format = substr( $imageName, -3 ); //gets the last 3 chars of the file name, ex: "photo1.png" gets the ".png" part
header('content-type: image/' . $format);
}

最佳答案

我只是用了这个,只是指明它是一个图像,但没有指定图像类型。

header("Content-type: image");

无论文件类型如何,它似乎都能正常工作。我使用 IE、Firefox、Safari 和 Android 浏览器进行了测试。

关于php - 设置 header (内容类型 : image/<ANY IMG FORMAT>),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23820011/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com