是否可以使用css媒体查询获取移动设备的大小并将其发送到php变量

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).