本文整理汇总了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;
}
示例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));
}
}
示例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;
}
}
示例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;
}
}
示例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
//.........这里部分代码省略.........
示例6: download
static function download($file, $name)
{
header("Content-disposition:attachment;filename={$name}");
header('Content-type:' + file::mime($file));
readfile($file);
}
示例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;
}
}
示例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())));
}
}