get_mimetype() public static method

public static get_mimetype ( $ext )
Exemplo n.º 1
0
 public function uploadOSS($input_file_field = 'pic', $save_dir = 'pic', $ext = 'jpg')
 {
     $file_path = $_FILES[$input_file_field]["tmp_name"];
     if (!$file_path) {
         FLogger::write('tmp_name为空', 'update_mumu');
         return '';
     }
     $file_md5 = md5_file($file_path);
     $_file_path_info = pathinfo($_FILES[$input_file_field]['name']);
     $file_ext = strtolower($_file_path_info['extension']);
     if (!$file_ext) {
         $this->get_extension($file_path);
     }
     if (!$file_ext) {
         $file_ext = $ext;
     }
     $content_type = MimeTypes::get_mimetype(strtolower($file_ext));
     $object = 'oss/' . $save_dir . '/' . date('Ym/d/His') . rand(10000, 99999) . '.' . $file_ext;
     $flag = $this->oss->upload_by_file($this->bucket, 'uploads/' . $object, $file_path, $content_type);
     if (!$flag) {
         $object = '';
     }
     $data = array('object' => $object, 'md5' => $file_md5);
     return $data;
 }
Exemplo n.º 2
0
 public function uploadOSS($input_file_field = 'pic', $save_dir = 'pic', $ext = 'jpg')
 {
     $file_path = $_FILES[$input_file_field]["tmp_name"];
     if (!$file_path) {
         return '';
     }
     $_file_path_info = pathinfo($_FILES[$input_file_field]['name']);
     $file_ext = strtolower($_file_path_info['extension']);
     if (!$file_ext) {
         $this->get_extension($file_path);
     }
     if (!$file_ext) {
         $file_ext = $ext;
     }
     $content_type = MimeTypes::get_mimetype(strtolower($file_ext));
     $object = 'oss/' . $save_dir . '/' . date('Ym/d/His') . rand(10000, 99999) . '.' . $file_ext;
     $flag = $this->oss->upload_by_file($this->bucket, 'uploads/' . $object, $file_path, $content_type);
     if ($flag) {
         return $object;
     } else {
         return '';
     }
 }
Exemplo n.º 3
0
 /**
  * 上传文件,适合比较大的文件
  * @param string $bucket (Required)
  * @param string $object (Required)
  * @param string $file (Required)
  * @param array $options (Optional)
  * @author xiaobing.meng@alibaba-inc.com
  * @since 2012-02-28
  * @return ResponseCore
  */
 public function upload_file_by_file($bucket, $object, $file, $options = NULL)
 {
     //options
     $this->validate_options($options);
     if (!$options) {
         $options = array();
     }
     //bucket
     $this->is_empty($bucket, OSS_BUCKET_IS_NOT_ALLOWED_EMPTY);
     //object
     $this->is_empty($object, OSS_OBJECT_IS_NOT_ALLOWED_EMPTY);
     //file
     $this->is_empty($file, OSS_FILE_PATH_IS_NOT_ALLOWED_EMPTY);
     if ($this->chk_chinese($file)) {
         $file = iconv('utf-8', 'gbk', $file);
     }
     $options[self::OSS_FILE_UPLOAD] = $file;
     if (!file_exists($options[self::OSS_FILE_UPLOAD])) {
         throw new OSS_Exception($options[self::OSS_FILE_UPLOAD] . OSS_FILE_NOT_EXIST);
     }
     $filesize = filesize($options[self::OSS_FILE_UPLOAD]);
     $partsize = 1024 * 1024;
     //默认为 1M
     $extension = explode('.', $object);
     $ext = array_pop($extension);
     $content_type = MimeTypes::get_mimetype(strtolower($ext));
     $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
     $options[self::OSS_BUCKET] = $bucket;
     $options[self::OSS_OBJECT] = $object;
     $options[self::OSS_CONTENT_TYPE] = $content_type;
     $options[self::OSS_CONTENT_LENGTH] = $filesize;
     $response = $this->auth($options);
     return $response;
 }
Exemplo n.º 4
0
 /**
  * 获取mimetype类型
  * @param string $object
  * @return string
  */
 private function get_mime_type($object)
 {
     $extension = explode('.', $object);
     $extension = array_pop($extension);
     $mime_type = MimeTypes::get_mimetype(strtolower($extension));
     return $mime_type;
 }