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($_FILE S['image'] ['tmp_name '], $uploadfile)) {
rename ($uploadfile, $uploaddir . $last_id . ".jpg");
chmod ($uploaddir . $last_id . ".jpg", intval(0644, 8));
}
[/CODE]
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($_FILE
rename ($uploadfile, $uploaddir . $last_id . ".jpg");
chmod ($uploaddir . $last_id . ".jpg", intval(0644, 8));
}
[/CODE]
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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