当前位置: 首页>>代码示例>>PHP>>正文


PHP file::mime方法代码示例

本文整理汇总了PHP中file::mime方法的典型用法代码示例。如果您正苦于以下问题:PHP file::mime方法的具体用法?PHP file::mime怎么用?PHP file::mime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在file的用法示例。


在下文中一共展示了file::mime方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: render

 /**
  * undocumented function
  *
  * @param string $path 
  * @return void
  * @author Andy Bennett
  */
 protected function render($path, $download = false, $orig_name = null)
 {
     Kohana::close_buffers(false);
     if (is_null($orig_name)) {
         $orig_name = basename($path);
     }
     $file_type = uploads::check_filetype(file::mime($path), $path);
     header('Content-type: ' . $file_type);
     if (!file::is_image($file_type) or $download) {
         header('Content-Disposition: attachment; filename="' . $orig_name . '"');
     }
     header("Content-Length: " . filesize($path));
     readfile($path);
     exit;
 }
开发者ID:AsteriaGamer,项目名称:steamdriven-kohana,代码行数:22,代码来源:Files.php

示例2: contentType

 public function contentType()
 {
     switch ($this->get('type')) {
         case 'wav':
             return 'audio/x-wav';
         case 'ogg':
             return 'audio/ogg';
         case 'mp1':
         case 'mp3':
             return 'audio/mpeg';
         default:
             return file::mime($this->filepath(TRUE));
     }
 }
开发者ID:swk,项目名称:bluebox,代码行数:14,代码来源:MediaFile.php

示例3: rule_allow

 public function rule_allow()
 {
     if (empty($this->upload['tmp_name']) or count($types = func_get_args()) == 0) {
         return;
     }
     if (($mime = file::mime($this->upload['tmp_name'])) === FALSE) {
         // Trust the browser
         $mime = $this->upload['type'];
     }
     // Allow nothing by default
     $allow = FALSE;
     foreach ($types as $type) {
         // Load the mime types
         $type = Kohana::config('mimes.' . $type);
         if (is_array($type) and in_array($mime, $type)) {
             // Type is valid
             $allow = TRUE;
             break;
         }
     }
     if ($allow === FALSE) {
         $this->errors['invalid_type'] = TRUE;
     }
 }
开发者ID:xafr,项目名称:gallery3,代码行数:24,代码来源:Form_Upload.php

示例4: rule_allow

 public function rule_allow()
 {
     if (empty($this->upload['tmp_name']) or count($types = func_get_args()) == 0) {
         return;
     }
     if (($mime = file::mime($this->upload['tmp_name'])) === NO) {
         // Trust the browser
         $mime = $this->upload['type'];
     }
     // Clean up charset garbage
     $mime = arr::get(explode(';', $mime), 0);
     // Allow nothing by default
     $allow = NO;
     foreach ($types as $type) {
         // Load the mime types
         $type = Eight::config('mimes.' . $type);
         if (is_array($type) and in_array($mime, $type)) {
             // Type is valid
             $allow = YES;
             break;
         }
     }
     if ($allow === NO) {
         $this->errors['invalid_type'] = YES;
     }
 }
开发者ID:enormego,项目名称:EightPHP,代码行数:26,代码来源:upload.php

示例5: rows

 public static function rows($item)
 {
     // print Kohana::debug($item);
     $output = '';
     foreach ($item->as_array() as $column_name => $column_value) {
         if ($column_name === 'id') {
             continue;
         }
         $output .= '<li class="row">';
         $output .= form::label($column_name, self::label($item, $column_name));
         if (empty($item->table_columns[$column_name]['null'])) {
             $required = 'required';
         } else {
             $required = NULL;
         }
         // print_r($item->table_columns[$column_name]);
         switch ($item->table_columns[$column_name]['type']) {
             case 'boolean':
                 if ($column_value) {
                     $checked = TRUE;
                 } else {
                     $checked = FALSE;
                 }
                 $output .= form::checkbox($column_name, $column_value, $checked, 'class="checkbox ' . $required . '"');
                 break;
             case 'string':
                 if (empty($item->table_columns[$column_name]['length'])) {
                     if (empty($item->table_columns[$column_name]['format'])) {
                         $output .= form::textarea($column_name, $column_value);
                     } else {
                         $output .= form::input($column_name, $column_value, 'class="date ' . $required . '"');
                     }
                 } else {
                     if (array_key_exists('binary', $item->table_columns[$column_name])) {
                         if ($column_value) {
                             $checked = TRUE;
                         } else {
                             $checked = FALSE;
                         }
                         $output .= form::checkbox($column_name, $column_value, $checked, 'class="checkbox ' . $required . '"');
                     } else {
                         if (property_exists($item, 'admin') && array_key_exists($column_name, $item->admin) && $item->admin[$column_name]['type'] === 'file') {
                             $attributes = array('name' => $column_name);
                             $output .= form::upload($attributes, $column_value);
                             $file_name = basename($column_value);
                             $upload_to = '/';
                             if (array_key_exists('upload_to', $item->admin[$column_name])) {
                                 $upload_to = '/' . $item->admin[$column_name]['upload_to'] . '/';
                             }
                             $link = '/' . Kohana::config('upload.relative_path') . $upload_to . $file_name;
                             $full_file_path = rtrim(DOCROOT, '/') . $column_value;
                             $file_type = explode('/', file::mime($full_file_path));
                             $file_type = $file_type[0];
                             // print Kohana::debug($link);
                             if ($file_type == 'image') {
                                 $image_source = $link;
                                 $file_data = pathinfo($full_file_path);
                                 $thumb = $file_data['dirname'] . '/' . $file_data['filename'] . '_small.' . $file_data['extension'];
                                 if (file_exists($thumb)) {
                                     $image_source = '/' . Kohana::config('upload.relative_path') . $upload_to . $file_data['filename'] . '_small.' . $file_data['extension'];
                                 }
                                 $output .= '<div class="picture-container">' . html::anchor($link, html::image(array('src' => $image_source, 'width' => 100)), array('target' => '_blank')) . '</div>';
                             } else {
                                 $output .= html::anchor($link, $file_name, array('target' => '_blank'));
                             }
                         } else {
                             $output .= form::input($column_name, $column_value, 'class="' . $required . '" size="' . $item->table_columns[$column_name]['length'] . '" maxlength="' . $item->table_columns[$column_name]['length'] . '"');
                             $output .= '<div class="hint">Maximum length is ' . $item->table_columns[$column_name]['length'] . '.</div>';
                         }
                     }
                 }
                 break;
             case 'int':
                 if (array_key_exists('max', $item->table_columns[$column_name]) and $item->table_columns[$column_name]['max'] == 127) {
                     if ($column_value) {
                         $checked = TRUE;
                     } else {
                         $checked = FALSE;
                     }
                     $output .= form::checkbox($column_name, $column_value, $checked, 'class="checkbox ' . $required . '"');
                     break;
                 }
                 $belongs_to = FALSE;
                 $model_name = '';
                 $selection = array();
                 foreach (array_values($item->belongs_to) as $model_name) {
                     if ($model_name . '_id' == $column_name) {
                         $belongs_to = TRUE;
                     }
                 }
                 if ($belongs_to) {
                     preg_match('/(\\w+)_id/', $column_name, $matcher);
                     $model_name = $matcher[1];
                     $selection = array();
                     $current_model = ORM::factory($model_name);
                     $objects = $current_model->find_all();
                     foreach ($objects as $object) {
                         $selection[$object->id] = (string) $object;
                     }
                     // Check if we have has_one relation
//.........这里部分代码省略.........
开发者ID:actuosus,项目名称:kohana_admin,代码行数:101,代码来源:form_generator.php

示例6: download

 static function download($file, $name)
 {
     header("Content-disposition:attachment;filename={$name}");
     header('Content-type:' + file::mime($file));
     readfile($file);
 }
开发者ID:reang,项目名称:Dingo-Framework,代码行数:6,代码来源:file.php

示例7: rule_allow

 public function rule_allow()
 {
     if (empty($this->upload['tmp_name']) or count($types = func_get_args()) == 0) {
         return;
     }
     if (($mime = file::mime($this->upload['tmp_name'])) === FALSE) {
         // Trust the browser
         $mime = $this->upload['type'];
     }
     // Get rid of the ";charset=binary" that can occasionally occur and is
     // legal via RFC2045
     $mime = preg_replace('/; charset=binary/', '', $mime);
     // Allow nothing by default
     $allow = FALSE;
     foreach ($types as $type) {
         // Load the mime types
         $type = Kohana::config('mimes.' . $type);
         if (is_array($type) and in_array($mime, $type)) {
             // Type is valid
             $allow = TRUE;
             break;
         }
     }
     if ($allow === FALSE) {
         $this->errors['invalid_type'] = TRUE;
     }
 }
开发者ID:JasonWiki,项目名称:docs,代码行数:27,代码来源:Form_Upload.php

示例8: _image_upload

 protected function _image_upload($gallery)
 {
     if (request::is_ajax()) {
         $this->_use_json_errors();
     }
     if ($gallery->id == 0) {
         return View::global_error('Invalid Gallery id');
     }
     if (isset($_POST['username']) && isset($_POST['password'])) {
         Auth::instance()->login($_POST['username'], $_POST['password']);
     }
     if (!Auth::instance()->logged_in('login')) {
         return View::global_error('Image upload requires login');
     }
     if ($gallery->user_id != 0 && $gallery->user_id != Auth::instance()->get_user()->id) {
         return View::global_error('User not gallery owner');
     }
     if (empty($_FILES['file'])) {
         return View::global_error('Error with upload');
     }
     if ($this->input->post('name') == '') {
         View::global_error('Missing Image Name');
     }
     if ($_FILES['file']['name'] == '') {
         View::global_error('Missing File');
     }
     if (View::errors_set()) {
         return;
     }
     $image = ORM::factory('image');
     $image->gallery_id = $gallery->id;
     $image->name = $this->input->post('name');
     $image->mime = file::mime($_FILES['file']['tmp_name']);
     $image->description = $_FILES['file']['name'];
     $image->size = $_FILES['file']['size'];
     $image->uploaded_on = time();
     $image->uploaded_by = Auth::instance()->get_user()->id;
     if (!$image->validate()) {
         return View::global_error('Error validating Image');
     }
     if (!$image->move_uploaded_file($_FILES['file']['tmp_name'])) {
         return View::global_error('Error moving Image');
     }
     if (!$image->save()) {
         return View::global_error('Error saving Image');
     }
     if (!$image->generate_thumb()) {
         return View::global_error('Error generating thumb');
     }
     $_POST = array();
     if (request::is_ajax()) {
         die(json_encode(array('result' => 'OK', 'id' => $image->id, 'name' => $image->name, 'url' => $image->generate_url())));
     }
 }
开发者ID:kfdm-archive,项目名称:dev.kfdm.net,代码行数:54,代码来源:gallery.php


注:本文中的file::mime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。