PDA

View Full Version : Php Help Needed ASAP.



lMattz
06-07-2006, 06:59 PM
I was wondering do you know how to restrict the image if it does not complie with the dimensions i want to set.

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

Ty

- Matt

tularis
09-07-2006, 03:41 PM
Use "if" statements in the php file or add a new variable in the form.

Use something like

<input type="hidden" name "MAX_DIMENSIONS" width="100" height="100" value="MAX_IMAGE" />

and then get the php file to check the dimensions do not exceed the values above :P

nets
09-07-2006, 04:12 PM
It isn't very secure storing restrictions etc. in hidden fields, as malicious users could change these values. Your best option would be to have the restrictions stored in a variable inside your PHP script, and then checking the size of the image (http://uk.php.net/getimagesize) against the limitations you've set.

Eric30
10-07-2006, 01:21 PM
You need to do it in the PHP, not the HTML form.

Something like this:


$max_height = "100";
$max_width = "100";
if ($max_width && $max_height) {
list($width, $height, $type, $w) = getimagesize($_FILES['file']['tmp_name']);
if($width > $max_width || $height > $max_height){
print "File height and/or width are too big!";
exit;
}
}

Want to hide these adverts? Register an account for free!