Avatar

doc and pdf upload possibility (Features)

by Micha ⌂, Monday, November 02, 2009, 16:40 (5288 days ago) @ Eelco

Hi,

I've changed the swtich to above, but still outputs false.

The switch in line 84ff? No you are to fast! We still standing at line 20:

$image_info = $_FILES['probe']['size'];

In the following restriction you check if (!is_array($image_info) || ... ), because getimagesize() returns an array. See Your code above, you do not use getimagesize(), you are using $_FILES['probe']['size'].

Thus $image_info is not an array, it is a simple integer --> $errors[] = 'invalid_file_format';.

Use a function like the following to check the extension:

function endsWith( $str, $sub ) {   
  return ( substr( $str, strlen( $str ) - strlen( $sub ) ) === $sub );
}

Warning: !!!This function only check the extension string!!!!

We start in line 20

 
unset($errors);
$image_info = getimagesize($_FILES['probe']['tmp_name']);
 
$isAddionalAcceptedFile = false; // a simple flag
// we want zip and pdf files
if (endsWith($_FILES['probe']['name'], ".zip") || endsWith($_FILES['probe']['name'], ".pdf") {
  // it is an file that ends with zip or pdf --> true
  $isAddionalAcceptedFile = true;
}
elseif(!is_array($image_info) || $image_info[2] != 1 && $image_info[2] != 2 && $image_info[2] != 3) $errors[] = 'invalid_file_format';

the next changes are at line 112ff:

 
//....
else
       {
        @move_uploaded_file($_FILES['probe']['tmp_name'], $uploaded_images_path.$filename) or $errors[] = 'upload_error';
       }
     }
 
//Move to directory
if ($isAddionalAcceptedFile) {
  unset($errors); 
  @move_uploaded_file($_FILES['probe']['tmp_name'], $uploaded_images_path.$_FILES['probe']['name']) or $errors[] = 'upload_error';
 
}
 
 
 
    if(empty($errors))
     {
      @chmod($uploaded_images_path.$filename, 0644);
      $smarty->assign('uploaded_file',$filename);
     }
    else 
     {
      $smarty->assign('errors',$errors);
      $smarty->assign('form',true);
     } 
   }

I do not try it out! Maybe, it is a quick & dirty solution!

regards Milo

--
applied-geodesy.org - OpenSource Least-Squares Adjustment Software for Geodetic Sciences

locked
14401 views

Complete thread:

 RSS Feed of thread