小编use*_*049的帖子

设置标题(content-type:image/<ANY IMG FORMAT>)

处理我显示的图像的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);
}
Run Code Online (Sandbox Code Playgroud)

php substr http-headers

5
推荐指数
2
解决办法
4万
查看次数

标签 统计

http-headers ×1

php ×1

substr ×1