示例#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;
 }
示例#2
0
 function _put($options = array())
 {
     $result = '';
     $to_path = empty($options['path']) ? '' : $options['path'];
     $from_path = empty($options['url']) ? '' : $options['url'];
     if (!($to_path && $from_path)) {
         throw new InvalidArgumentException('Send array with url and path keys');
     }
     // if the next character is also a slash, then we're talking an absolute path
     $relative = substr($to_path, 0, 1) != '/';
     $mime = empty($options['mime']) ? '' : $options['mime'];
     if (empty($mime)) {
         $mime = mime_from_path($from_path);
     }
     //if (substr($to_path, 0, 1) == '/') $to_path = substr($to_path, 1);
     $extract = $mime == mime_from_extension('tgz');
     if ($extract) {
         throw new RuntimeException("CoderArchiveExtension not supported with File::System");
     }
     if (!safe_path($to_path)) {
         throw new RuntimeException('Could not create path: ' . $to_path);
     }
     $file = basename($from_path);
     if (!@rename($from_path, $to_path)) {
         throw new RuntimeException("Could not rename from: {$from_path} to: {$to_path}");
     }
     if ($this->getOption('Verbose')) {
         $this->log("Renamed {$from_path} to {$to_path}");
     }
     @chmod($to_path, 0777);
     // TODO: fix this terrible kludge that allows ftp user to delete files
     //@chmod(dirname($to_path), 0777);
     //@chmod(dirname(dirname($to_path)), 0777);
 }
function type_from_path($path)
{
    $result = FALSE;
    if ($path) {
        $mime = mime_from_path($path);
        if ($mime) {
            $result = type_from_mime($mime);
        }
    }
    return $result;
}
 function service_import_init($import, $config = array())
 {
     $result = array();
     if (!$config) {
         $config = config_get();
     }
     log_file(print_r($import, 1), $config);
     $err = config_error($config);
     // should wind up calling __service_load
     if (!$err) {
         $function_name = $config['file'] . '_file_import_init';
         if (!function_exists($function_name)) {
             $err = $function_name . ' is not defined';
         }
     }
     if (!$err && empty($import['size'])) {
         $err = 'Import option size required';
     }
     if (!$err && empty($import['file'])) {
         $err = 'Import option file required';
     }
     if (!$err && empty($import['extension'])) {
         $import['extension'] = file_extension($import['file']);
         if (!$import['extension']) {
             $err = 'Import option extension required';
         }
     }
     if (!$err && empty($import['mime'])) {
         $import['mime'] = mime_from_path($import['file']);
         if (!$import['mime']) {
             $err = 'Import option mime required';
         }
     }
     if (!$err && empty($import['type'])) {
         $import['type'] = mime_type($import['mime']);
         if (!$import['type']) {
             $err = 'Import option type required';
         } else {
             switch ($import['type']) {
                 case 'audio':
                 case 'video':
                 case 'image':
                     break;
                 default:
                     $err = 'Import type ' . $import['type'] . ' unsupported';
             }
         }
     }
     if (!$err) {
         // enforce size limit from configuration, if defined
         $max = empty($config["max_meg_{$import['type']}"]) ? '' : $config["max_meg_{$import['type']}"];
         if ($max) {
             $file_megs = round($import['size'] / (1024 * 1024));
             if ($file_megs > $max) {
                 $err = $import['type'] . ' files must be less than ' . $max . ' meg';
             }
         }
     }
     if (!$err && empty($import['label'])) {
         $import['label'] = $import['file'];
     }
     //$err = $function_name;
     if (!$err) {
         $result = $function_name($import, $config);
     }
     if ($err) {
         $result['error'] = $err;
     }
     return $result;
 }
            default:
                $err = "Unknown upload error";
                break;
        }
    } else {
        if (!is_uploaded_file($file['tmp_name'])) {
            $err = 'Error uploading your file';
        }
    }
}
if (!$err) {
    // make sure we can determine mime type and extension from file name
    $file_name = stripslashes($file['name']);
    $file_size = $file['size'];
    $file_extension = file_extension($file_name);
    $mime = mime_from_path($file_name);
    if (!($mime && $file_extension)) {
        $err = 'Could not determine mime type or extension';
    }
}
if (!$err) {
    // make sure mime type is supported
    $file_type = mime_type($mime);
    switch ($file_type) {
        case 'audio':
        case 'video':
        case 'image':
            break;
        default:
            $err = 'Only audio, image and video files supported';
    }
示例#6
0
 function _put($options = array())
 {
     $access_key_id = $this->getOption('AWSAccessKeyID');
     $secret_access_key = $this->getOption('AWSSecretAccessKey');
     $to_path = empty($options['path']) ? '' : $options['path'];
     $from_path = empty($options['url']) ? '' : $options['url'];
     $mime = empty($options['mime']) ? '' : $options['mime'];
     if (!($access_key_id && $secret_access_key)) {
         throw new UnexpectedValueException('Configuration options AWSAccessKeyID, AWSSecretAccessKey, SQSQueueURL required');
     }
     if (!($to_path && $from_path)) {
         throw new InvalidArgumentException('Send array with url and path keys');
     }
     if (substr($to_path, 0, 1) == '/') {
         $to_path = substr($options['path'], 1);
     }
     if (empty($mime)) {
         $mime = mime_from_path($from_path);
     }
     $result = s3_put_file($access_key_id, $secret_access_key, $to_path, $from_path, $mime);
     if (!$result) {
         throw new RuntimeException('Could not put S3 file: ' . $to_path);
     }
     if ($this->getOption('Verbose')) {
         $this->log("Put S3 file: {$to_path}");
     }
 }