本文整理汇总了PHP中File::mime方法的典型用法代码示例。如果您正苦于以下问题:PHP File::mime方法的具体用法?PHP File::mime怎么用?PHP File::mime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File
的用法示例。
在下文中一共展示了File::mime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_download
public function action_download()
{
$id = $this->request->param('id');
$document = ORM::factory('document', $id);
$path = UPLOAD_PATH;
$filename = $path . $document->name;
if (!file_exists($filename) || file_exists($filename) && is_dir($filename)) {
Request::current()->redirect('error/not_found');
}
if (!$document->is_allowed()) {
Request::current()->redirect('error/access_denied');
}
$download_name = str_replace(substr(basename($filename), 0, 13), '', basename($filename));
//to remove the uniqid prepended to the filename
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: " . File::mime($filename));
header("Content-Disposition: attachment; filename=" . $download_name);
header("Content-Transfer-Encoding: binary");
readfile($filename);
exit;
}
示例2: beforeSave
/**
* beforeSave callback
*
* @param array $options
* @return boolean true on success
*/
public function beforeSave($options = array())
{
if (!empty($this->data[$this->alias]['file']['tmp_name'])) {
$File = new File($this->data[$this->alias]['file']['tmp_name']);
$this->data[$this->alias]['filesize'] = $File->size();
$this->data[$this->alias]['mime_type'] = $File->mime();
}
if (!empty($this->data[$this->alias]['file']['name'])) {
$this->data[$this->alias]['extension'] = $this->fileExtension($this->data[$this->alias]['file']['name']);
$this->data[$this->alias]['filename'] = $this->data[$this->alias]['file']['name'];
}
if (empty($this->data[$this->alias]['adapter'])) {
$this->data[$this->alias]['adapter'] = 'S3Storage';
}
// Start Auto Creator & Modifier Id Saving
$exists = $this->exists();
$user = class_exists('CakeSession') ? CakeSession::read('Auth.User') : null;
if (!$exists && $this->hasField('creator_id') && empty($this->data[$this->alias]['creator_id'])) {
$this->data[$this->alias]['creator_id'] = $user['id'];
}
if ($this->hasField('modifier_id') && empty($this->data[$this->alias]['modifier_id'])) {
$this->data[$this->alias]['modifier_id'] = $user['id'];
}
// End Auto Creator & Modifier Id Saving
$Event = new CakeEvent('FileStorage.beforeSave', $this, array('record' => $this->data, 'storage' => $this->getStorageAdapter($this->data[$this->alias]['adapter'])));
$this->getEventManager()->dispatch($Event);
if ($Event->isStopped()) {
return false;
}
return true;
}
示例3: replace
function replace($path)
{
$F = new File($path);
$md5 = $F->md5();
$this->path = appPATH . 'qg/file/' . $md5;
$F->copy($this->path);
$this->setVs(array('name' => $F->basename(), 'mime' => $F->mime(), 'text' => $F->getText(), 'md5' => $F->md5(), 'size' => $F->size()));
}
示例4: action_index
/**
* Output the captcha challenge
*
* @param string $group Config group name
*/
public function action_index($group = 'default')
{
// Output the Captcha challenge resource (no html)
// Pull the config group name from the URL
$captcha = Captcha::instance($group)->render(FALSE);
$this->request->headers['Content-Type'] = File::mime($captcha);
$this->request->headers['Content-length'] = filesize($captcha);
$this->request->response = $captcha;
}
示例5: action_default
/**
* Output the captcha challenge
*
* @param string $group Config group name
*/
public function action_default($group = 'default')
{
// Output the Captcha challenge resource (no html)
// Pull the config group name from the URL
$captcha = Captcha::instance($group)->render(FALSE);
$this->request->headers['Content-Type'] = File::mime($captcha);
// The necessity of this header is questionable and causes problems in Safari and other WebKit browsers.
// Uncomment at your own peril, scheduled for removal unless a case can be made to keep it.
//$this->request->headers['Content-Length'] = filesize($captcha);
$this->request->headers['Connection'] = 'close';
$this->request->response = $captcha;
}
示例6: action_asset
public function action_asset()
{
$asset = Request::instance()->param('filename');
$file = MODPATH . 'amfphp/assets/' . $asset;
if (!is_file($file)) {
throw new Kohana_Exception('Asset does not exist');
}
$this->request->headers['Content-Type'] = File::mime($file);
$this->request->headers['Content-Length'] = filesize($file);
$this->request->send_headers();
$content = @fopen($file, 'rb');
if ($content) {
fpassthru($content);
exit;
}
}
示例7: download
public static function download($path, $name = null, $headers = array())
{
if (!file_exists($path)) {
return Response::code(404);
}
if (is_null($name)) {
$name = basename($path);
}
$ext = File::extension($name);
if ($ext == "") {
$ext = File::extension($path);
}
$headers = array_merge(array('Content-Description' => 'File Transfer', 'Content-Type' => File::mime(File::extension($path)), 'Content-Transfer-Encoding' => 'binary', 'Expires' => 0, 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Pragma' => 'public', 'Content-Length' => File::size($path), 'Content-Disposition' => 'attachment; filename="' . str_replace('"', '\\"', $name) . '"'), $headers);
foreach ($headers as $k => $v) {
header($k . ": " . $v);
}
readfile($path);
}
示例8: video_tag
public static function video_tag($source, array $attributes = NULL)
{
if (strpos('//', $source) === FALSE && isset($source[0]) && $source[0] !== '/') {
$version = '';
$format = 'mp4';
if (preg_match('#^(?<source>.+)\\.(?<format>\\w+)$#', $source, $matches)) {
$source = $matches['source'];
$format = $matches['format'];
}
if (Kohana::$config->load('assets.versionizable') === TRUE) {
$file_name = Assets::get_file($source, $format);
if ($file_name && is_file($file_name)) {
$version = '-' . hash_hmac_file('md5', $file_name, Kohana::$config->load('assets.versionizable.hmac_password'));
}
}
$source = '/assets/' . $source . $version . '.' . $format;
$mime = File::mime_by_ext($format);
} else {
$mime = File::mime($source);
}
return '<video' . HTML::attributes($attributes) . '><source src="' . $source . '" type="' . $mime . '" /><a href="' . $source . '">' . $source . '</a></video>';
}
示例9: display
/**
* Display a file in the browser.
*
* <code>
* File::display('filename.txt');
* </code>
*
* @param string $file Full path to file
* @param string $content_type Content type of the file
* @param string $filename Filename of the download
*/
public static function display($file, $content_type = null, $filename = null)
{
// Redefine vars
$file = (string) $file;
$content_type = $content_type === null ? null : (string) $content_type;
$filename = $filename === null ? null : (string) $filename;
// Check that the file exists and that its readable
if (file_exists($file) === false || is_readable($file) === false) {
throw new RuntimeException(vsprintf("%s(): Failed to open stream.", array(__METHOD__)));
}
// Empty output buffers
while (ob_get_level() > 0) {
ob_end_clean();
}
// Send headers
if ($content_type === null) {
$content_type = File::mime($file);
}
if ($filename === null) {
$filename = basename($file);
}
header('Content-type: ' . $content_type);
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Length: ' . filesize($file));
// Read file and write to output
readfile($file);
exit;
}
示例10: testMime
/**
* Tests File::mime()
*
* @test
* @dataProvider providerMime
* @param boolean $input Input for File::mime
* @param boolean $expected Output for File::mime
*/
function testMime($input)
{
$this->assertSame(1, preg_match('/^(?:application|audio|image|message|multipart|text|video)\\/[a-z.+0-9-]+$/i', File::mime($input)));
}
示例11: testMime
/**
* Test mime()
*
* @return void
*/
public function testMime()
{
$path = CAKE . 'Test' . DS . 'test_app' . DS . 'webroot' . DS . 'img' . DS . 'cake.power.gif';
$file = new File($path);
$this->assertEquals('image/gif', $file->mime());
}
示例12: test_mime
/**
* Tests File::mime()
*
* @test
* @dataProvider provider_mime
* @param boolean $input Input for File::mime
* @param boolean $expected Output for File::mime
*/
public function test_mime($input)
{
$this->markTestSkipped('This test doesn\'t do anything useful!');
$this->assertSame(1, preg_match('/^(?:application|audio|image|message|multipart|text|video)\\/[a-z.+0-9-]+$/i', File::mime($input)));
}
示例13: send_file
/**
* Send file download as the response. All execution will be halted when
* this method is called! Use TRUE for the filename to send the current
* response as the file content. The third parameter allows the following
* options to be set:
*
* Type | Option | Description | Default Value
* ----------|-----------|------------------------------------|--------------
* `boolean` | inline | Display inline instead of download | `FALSE`
* `string` | mime_type | Manual mime type | Automatic
* `boolean` | delete | Delete the file after sending | `FALSE`
*
* Download a file that already exists:
*
* $request->send_file('media/packages/kohana.zip');
*
* Download generated content as a file:
*
* $request->response($content);
* $request->send_file(TRUE, $filename);
*
* [!!] No further processing can be done after this method is called!
*
* @param string filename with path, or TRUE for the current response
* @param string downloaded file name
* @param array additional options
* @return void
* @throws Kohana_Exception
* @uses File::mime_by_ext
* @uses File::mime
* @uses Request::send_headers
*/
public function send_file($filename, $download = NULL, array $options = NULL)
{
if (!empty($options['mime_type'])) {
// The mime-type has been manually set
$mime = $options['mime_type'];
}
if ($filename === TRUE) {
if (empty($download)) {
throw new Kohana_Exception('Download name must be provided for streaming files');
}
// Temporary files will automatically be deleted
$options['delete'] = FALSE;
if (!isset($mime)) {
// Guess the mime using the file extension
$mime = File::mime_by_ext(strtolower(pathinfo($download, PATHINFO_EXTENSION)));
}
// Force the data to be rendered if
$file_data = (string) $this->_body;
// Get the content size
$size = strlen($file_data);
// Create a temporary file to hold the current response
$file = tmpfile();
// Write the current response into the file
fwrite($file, $file_data);
// File data is no longer needed
unset($file_data);
} else {
// Get the complete file path
$filename = realpath($filename);
if (empty($download)) {
// Use the file name as the download file name
$download = pathinfo($filename, PATHINFO_BASENAME);
}
// Get the file size
$size = filesize($filename);
if (!isset($mime)) {
// Get the mime type
$mime = File::mime($filename);
}
// Open the file for reading
$file = fopen($filename, 'rb');
}
if (!is_resource($file)) {
throw new Kohana_Exception('Could not read file to send: :file', array(':file' => $download));
}
// Inline or download?
$disposition = empty($options['inline']) ? 'attachment' : 'inline';
// Calculate byte range to download.
list($start, $end) = $this->_calculate_byte_range($size);
if (!empty($options['resumable'])) {
if ($start > 0 or $end < $size - 1) {
// Partial Content
$this->_status = 206;
}
// Range of bytes being sent
$this->_header['content-range'] = 'bytes ' . $start . '-' . $end . '/' . $size;
$this->_header['accept-ranges'] = 'bytes';
}
// Set the headers for a download
$this->_header['content-disposition'] = $disposition . '; filename="' . $download . '"';
$this->_header['content-type'] = $mime;
$this->_header['content-length'] = (string) ($end - $start + 1);
if (Request::user_agent('browser') === 'Internet Explorer') {
// Naturally, IE does not act like a real browser...
if (Request::$initial->secure()) {
// http://support.microsoft.com/kb/316431
$this->_header['pragma'] = $this->_header['cache-control'] = 'public';
}
//.........这里部分代码省略.........
示例14: check_real_mime
/**
* 设置真实的文件类型
*
* @return boolean|Core_Upload
*/
protected function check_real_mime()
{
// 真实类型检测
if ($this->config['mimes_check']) {
$type = File::mime($this->file['tmp_name']);
if (false === $type) {
throw new Exception('Upload error type', Upload::ERR_EXTENSION);
} else {
$this->file['type'] = $type;
}
}
return $this;
}
示例15: _create_headers
/**
* Create the image HTTP headers
*
* @param string path to the file to server (either default or cached version)
*/
private function _create_headers($file_data)
{
// Create the required header vars
$last_modified = gmdate('D, d M Y H:i:s', filemtime($file_data)) . ' GMT';
$content_type = File::mime($file_data);
$content_length = filesize($file_data);
$expires = gmdate('D, d M Y H:i:s', time() + $this->config['cache_expire']) . ' GMT';
$max_age = 'max-age=' . $this->config['cache_expire'] . ', public';
// Some required headers
header("Last-Modified: {$last_modified}");
header("Content-Type: {$content_type}");
header("Content-Length: {$content_length}");
// How long to hold in the browser cache
header("Expires: {$expires}");
/**
* Public in the Cache-Control lets proxies know that it is okay to
* cache this content. If this is being served over HTTPS, there may be
* sensitive content and therefore should probably not be cached by
* proxy servers.
*/
header("Cache-Control: {$max_age}");
// Set the 304 Not Modified if required
$this->_modified_headers($last_modified);
/**
* The "Connection: close" header allows us to serve the file and let
* the browser finish processing the script so we can do extra work
* without making the user wait. This header must come last or the file
* size will not properly work for images in the browser's cache
*/
header("Connection: close");
}