Page 1 of 1

How to add file type checking in this code

Posted: Wed Jun 23, 2004 3:31 am
by Calimero

Code: Select all

<?php

if(!empty($_FILES) && $_FILES['img1']['size'] < 200000 /* max size */ && $_FILES['img1']['size'] > 0) 
  move_uploaded_file($_FILES['img1']['tmp_name'], '/path/to/new/location/'.$_FILES['img1']['name']); 

?>
1) I need PHP to check if the file has the extension of bmp, gif, png, or jpg(jpeg), and if it returns true to continue with uploading.

2) image size is now number 200000, but in what units - is it 200kb or 200mb, I'm not sure so please, little help.

Thanks ahead !

Posted: Wed Jun 23, 2004 3:38 am
by feyd
use [php_man]getimagesize[/php_man]():

Code: Select all

if($imgdata = @getimagesize($_FILES['img1']['tmp_name']))
print_r($imgdata); // all the data inside the array
else
die('not a known image format');
the size is ALWAYS in bytes. so 200,000 is 200KB, roughly..