# php upload file restrictions



## swoosieque (May 14, 2008)

Hi, 
I'm so glad that I found you guys! I was looking for a script so that I could add a file upload capability to my website. Downloaded a php script from here and it works. However, now that I've got that working, I want to make sure that I can limit the type of file (jpg or bmp) as well as the size of the file. Can you help me with that?

Also, I want to make sure that the folder where the files are uploaded has a size restriction on it also, I'm supposing that I just do that from my cpanel file manager, correct?

Thanks loads!!
Susie


----------



## Redcore (Aug 14, 2007)

I've made a few of these - whipped this up really quick.


```
<?php

if(isset($_POST['upload']))
	{
	$fileName = $_FILES['userfile']['name'];
	$fileSize = $_FILES['userfile']['size'];
	$fileType = $_FILES['userfile']['type'];
	
	list($width, $height, $type, $attr) = getimagesize($tmpName);
	
	if($width>600 || $height>500) // if width is over 600 or height is over 500, kill it
		{
		echo $fileName . "'s dimensions exceed the 600x500 pixel limit.";
		die();
		}
	
	if(!(
		$fileType=='image/jpeg' ||
		$fileType=='image/png' ||
		$fileType=='image/gif' ||
		$fileType=='image/bmp'
		)) // if file does not equal these types, kill it
		{
		echo $fileType . " is not an acceptable format.";
		die();
		}
		
	if($fileSize>'350000') // if size is larger than 350KB, kill it
		{
		echo $fileName . " is over 350KB. Please make it smaller.";
		die();
		}
}

?>
```


----------

