Dan Rogers - 2009-09-07

I wanted to limit file types for upload.

I came up with this after a lot of looking and not finding anything on the forums.

In Processor.php I added this"

session_start();
if( ($_SESSION['security_code']==$_POST['security_code']) && (!empty($_POST['security_code'])) ) {
// File upload handling
if($_FILES['field_3']['name']!=''){
$field_3_filename = "file_3_".date("sihdmY").substr($_FILES['field_3']['name'],strlen($_FILES['field_3']['name'])-4);
if(!move_uploaded_file($_FILES['field_3']['tmp_name'], "./files/".$field_3_filename)){
die("File " .  $_FILES['field_3']['name'] . " was not uploaded.");
}
}
//an array that contains allowed extensions only.
$allowed[] = 'jpg';
$allowed[] = 'gif';
$allowed[] = 'doc';
$allowed[] = 'rtf';
$allowed[] = 'pdf';
$allowed[] = 'jpeg';

//we get the extension from the file name !
$ext = substr($HTTP_POST_FILES['file']['name'], 0, -4);

//now start a loop to look at extension and compare it
//to the allowed ones !
for ($i=0; $i<count($allowed); $i++) {
  if ($ext !== $allowed[$i]) {
     die('This file type is not allowed! Go back and try again with allowed file types jpg jpeg gif png pdf doc rtf! If you want to use other file type email Webmaster directly!');

Works great for me!
Dan