[英]Is it possible to get the size of the mobile device using css media query and send it to php variable
I am redesigning a website which is currently a desktop version to mobile website. 我正在重新设计一个网站,该网站目前是移动网站的桌面版本。
My question is that I have to resize the images according to the screen width of the device . 我的问题是我必须根据设备的屏幕宽度调整图像大小。 i understand that we can do this using media query .
我知道我们可以使用媒体查询来做到这一点。
But the thing is that there is this function in my website which resize the images and save in a directory from where we get the images accordingly for our website because our website is dynamic and people keep posting adds with weird image sizes. 但事实是,我的网站中有此功能,可以调整图像大小并保存在目录中,以便从中获取相应的网站图像,因为我们的网站是动态的,人们不断发布带有怪异图像尺寸的添加内容。
for example the function is like this 例如功能是这样的
$whsize=$this->getSizeImage($id_item,$height,$width,basename($imag[0]))
in the and we just give the values of height and width ourself for now I have given 480 px for both for the mobile device. 在中,我们仅给出自己的高度和宽度值,现在我已经为移动设备给出了480像素。
But when the screen resolution is less than that the image is not in its proper dimension so I wanted to get the width of the screen and call this function getSizeImage() to redo the right size . 但是,当屏幕分辨率小于图像分辨率时,我想获取屏幕的宽度并调用此函数getSizeImage()以重做正确的尺寸。
Is it possible to do it ?? 有可能做到吗?
You can't get any values in PHP variable, because PHP is a Server side scripting language. 您无法在PHP变量中获取任何值,因为PHP是服务器端脚本语言。
You need JavaScript, not PHP. 您需要JavaScript,而不是PHP。
var screenWidth = window.screen.width,
var screenHeight = window.screen.height;
You can then send it to the server via Ajax (with an XmlHttpRequest
). 然后,您可以通过Ajax(带有
XmlHttpRequest
)将其发送到服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.