【发布时间】:2014-05-23 02:20:50
【问题描述】:
处理我显示的图像的 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);
}
【问题讨论】:
-
应该是 substr -3 而不是 -4
-
文件扩展名并不总是等于次要 MIME 类型。
-
是的,我注意到了 -4,我已经把它改成了 -3
标签: php http-headers substr