S
S
Scrooge_McDuck2021-11-24 23:30:26
PHP
Scrooge_McDuck, 2021-11-24 23:30:26

How do I check if the image matches the width and height?

In my case, when loading an image, there is a check only in width, but how can I do it in height? For example, to upload images no larger than 468x60.

if(!is_dir($uploaddir)) mkdir($uploaddir, 0777);
    $type = explode('/', $_FILES[0]['type']);
    if($type[0] == 'image'){
        $extension = $type[1];
        if(in_array(exif_imagetype($_FILES[0]['tmp_name']),$ex)){
            $imagesize = getimagesize($_FILES[0]['tmp_name']);
            if($imagesize[0] <= 468){
                $name = hash_file('md5', $_FILES[0]['tmp_name']).'.'.$extension;
                $r = move_uploaded_file($_FILES[0]['tmp_name'], BASE_DIR.'/storage/banners/' . $name);
                if($r !== false){
                    $data['status'] = 'success';
                    $data['description'] = 'Файл успешно загружен';
                    $data['url'] = 'https://'.$_SERVER['HTTP_HOST'].'/storage/banners/'.$name;
                }else{
                    $data['status'] = 'error';
                    $data['description'] = 'Ошибка загрузки файла';
                }
            }else{
                $data['status'] = 'error';
                $data['description'] = 'Ширина изображения не должна превышать 468px;
            }
        }else{
            $data['status'] = 'error';
            $data['description'] = 'Это не изображение';
        }
    }else{
        $data['status'] = 'error';
        $data['description'] = 'Это не изображение';
    }

Answer the question

In order to leave comments, you need to log in

5 answer(s)
I
Ipatiev, 2021-11-25
@Fockker

And how long will this shame hang here?
For some of the moderators, is this also a very difficult question that requires a detailed answer?
Or maybe the hand missed, they wanted to delete the question, but the answer was deleted?
You can try again.

A
Alexander Tsymbal, 2015-04-05
@AlexanderTsymbal

use condition in media not min-width but max-width.
min-width - fires when your width is greater than the specified value.
and max-width is the maximum width at which this rule will fire. i.e. if the width is less than this value, the rule is triggered. If the width exceeds this value, then nothing happens!

E
ExpFront, 2015-04-09
@ExpFront

Try writing : media all and (min-width ....

@
@ostinred, 2015-05-06
_

media screen and (min-width: 768px) {} The
media rule needs borders, inside and out.

A
Alex Zi, 2015-09-23
@Zidkov

In my chrome, the 768px breakpoint only works at 560px. In mozilla devvelop everything works fine.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question