Page 1 of 1
Checking height and Width on image
Posted: Mon Aug 07, 2006 4:10 pm
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).
Posted: Mon Aug 07, 2006 4:29 pm
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
Posted: Mon Aug 07, 2006 4:32 pm
by webproject
i know this, but, will it work on computer's image? (c:/...../img.jpg)
Posted: Mon Aug 07, 2006 4:35 pm
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
Posted: Mon Aug 07, 2006 4:42 pm
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.
Posted: Mon Aug 07, 2006 4:53 pm
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...
Posted: Tue Aug 08, 2006 1:45 am
by webproject
You mean, upload the file after validating the image's ext, and after i'll upload it, then check?
Posted: Tue Aug 08, 2006 10:41 am
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().