Link to home
Start Free TrialLog in
Avatar of avo42
avo42

asked on

Upload picture check size

Hi all

can anyone please give me an example

on my page i have a browse button and code to upload a image to my server (see code bellow)

what i would like to do is ammend this code so that it will check the size is NOT bigger than 450 px wide and 450 px high

if it is to return a false

if its within 450 x 450 to return a true

all help appriciated

[CODE]
      //add image
            $uploaddir = $_SERVER['DOCUMENT_ROOT'] . '/'.$cats.'/fur/images/';
//            
            $filename = $_FILES['image']['name'];
            $uploadfile = $uploaddir . $_FILES['image']['name'];
          if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile)) {
            rename ($uploadfile, $uploaddir . $last_id . ".jpg");
            chmod ($uploaddir . $last_id . ".jpg", intval(0644, 8));
            }
[/CODE]
Avatar of 0xC0DEB07
0xC0DEB07

Hi

Try this one

<?php
...

function isSizeGood($fname){
      
      $arr = getimagesize($fname);
      
      if($arr[0]<450 && $arr[1]<450)
            return true;
      return false;
}
...
?>      

You can check out the php documentation  for more info on getimagesize()
Hope this helps
Avatar of avo42

ASKER

Hi Thanks


That will work good if the file is allready on my server .
but how would i do it via this form

<form id="form1" name="form1" method="post" action="<?=$PHP_SELF?>">
<table width="500" border="0">
  <tr>
    <td width="236"><input name="image" type="file" id="image" /></td>
    <td width="254">
        <input type="submit" name="Submit" value="Submit" />
    </td>
  </tr>
</table>
</form>

thanks again all help appriciated
ASKER CERTIFIED SOLUTION
Avatar of 0xC0DEB07
0xC0DEB07

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial