简体   繁体   中英

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.

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 .

Is it possible to do it ??

You can't get any values in PHP variable, because PHP is a Server side scripting language.

You need JavaScript, not PHP.

var screenWidth = window.screen.width,
var screenHeight = window.screen.height;

You can then send it to the server via Ajax (with an XmlHttpRequest ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM