use*_*049 5 php substr http-headers
处理我显示的图像的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)
小智 10
我只是用它,只是表明它是一个图像,但没有指定图像类型.
header("Content-type: image");
Run Code Online (Sandbox Code Playgroud)
无论文件类型如何,它似乎都工作得很好.我测试了IE,Firefox,Safari和Android浏览器.