Example #1
0
 function fileError($file_name, $file_size)
 {
     $err = '';
     if (!($file_name && $file_size)) {
         $err = 'Both filename and size are required: : ' . $file_name . ', ' . $file_size;
     }
     if (!$err) {
         $mime = mime_from_path($file_name);
         if (!$mime) {
             $err = 'Could not determine mime type of file: ' . $file_name;
         }
     }
     if (!$err) {
         $type = type_from_mime($mime);
         switch ($type) {
             case 'audio':
             case 'video':
             case 'image':
                 break;
             default:
                 $err = 'Only audio, image and video files are supported: ' . $type;
         }
     }
     if (!$err) {
         $uc_type = ucwords($type);
         $max = $this->getOption('File' . $uc_type . 'MaxSize');
         if ($max) {
             $file_megs = round($file_size / (1024 * 1024));
             if ($file_megs > $max) {
                 $err = $uc_type . ' files must be less than ' . $max . ' meg';
             }
         }
     }
     return $err;
 }
function type_from_path($path)
{
    $result = FALSE;
    if ($path) {
        $mime = mime_from_path($path);
        if ($mime) {
            $result = type_from_mime($mime);
        }
    }
    return $result;
}