Checking height and Width on image

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
webproject
Forum Newbie
Posts: 7
Joined: Mon Aug 07, 2006 4:07 pm

Checking height and Width on image

Post by webproject »

Hello there =]

I recently got a project, but i kinda stuck..

I need to check if the image witch the user trying to upload is bigger then the limited (Height, Width).

My question is like this: how can i check image's height and width without upload it?




Tal (WebProject, my old user here is IAD).
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

Post by duk »

Code: Select all

<?php
list($width, $height, $type, $attr) = getimagesize("img/flag.jpg");
echo "<img src=\"img/flag.jpg\" $attr alt=\"getimagesize() example\" />";
?>
as you see in list, you can get the width height, by using getimagesize() function
webproject
Forum Newbie
Posts: 7
Joined: Mon Aug 07, 2006 4:07 pm

Post by webproject »

i know this, but, will it work on computer's image? (c:/...../img.jpg)
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

Post by duk »

if the user dont upload it how you know from 60 000 thousands of c:/.../img/*.jpg,*.gif,*.png wich image he is trying to upload... first he uploads then you manage... unless javascript can do it... i realyd ont know... but the problem is if the browser dont have javascript enabled
webproject
Forum Newbie
Posts: 7
Joined: Mon Aug 07, 2006 4:07 pm

Post by webproject »

i'm puting a "file" input, aftr he clicks the submit button, i have the url of th image, don't i?

Anyway 00:42 here in israel, good night, and thank you.
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

Post by duk »

i know what you mean...

1rst question is, if there is no javascript enabled

2nd i think that could be tricky... someone can bypass easly a javascript check for that.. the best way still... submit and then validate...
webproject
Forum Newbie
Posts: 7
Joined: Mon Aug 07, 2006 4:07 pm

Post by webproject »

You mean, upload the file after validating the image's ext, and after i'll upload it, then check?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Simple answer: you can't. The only way to goof with the filesystem like that would be to write an ActiveX plugin - even then it would only work in IE. By far the most common method is to allow the user to upload the image, then before you put the image into your system, check the filesize with getimagesize().
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply