试图仅为Android用户显示图像,但我不想为其使用任何重定向。在strstr匹配上显示图像
到目前为止,我有这个,但是它使用了重定向的header()。
if (strstr($_SERVER['HTTP_USER_AGENT'],"Android")) {
header("Location: app.png");
}
试图仅为Android用户显示图像,但我不想为其使用任何重定向。在strstr匹配上显示图像
到目前为止,我有这个,但是它使用了重定向的header()。
if (strstr($_SERVER['HTTP_USER_AGENT'],"Android")) {
header("Location: app.png");
}
只需使用readfile即可在页面中输出图像。确保发送正确的标题。
例如:
if(strstr($_SERVER['HTTP_USER_AGENT',"Android"))
{
header('content-type: application/png'); //Let the client know its a png.
readfile('app.png');
}
这种方式使用Android将导致返回原始图像专页的要求而作出。如果您想'强制'客户端下载图片,请发送content-disposition
标题。
这取决于你想要做什么。 如果要在HTML文档中显示图像,为什么不使用这种类型的代码?
if (strstr($_SERVER['HTTP_USER_AGENT'],"Android")) {
echo '<img src="app.png"/>';
}
很好,谢谢(我会接受一次) –