mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
parent
28140f923b
commit
f959fcefc4
2 changed files with 41 additions and 2 deletions
|
@ -463,6 +463,17 @@ class FileTest extends CakeTestCase {
|
|||
$TmpFile->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
|
||||
/**
|
||||
* getTmpFile method
|
||||
*
|
||||
|
|
|
@ -291,9 +291,16 @@ class File {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the File info.
|
||||
* Returns the File info as an array with the following keys:
|
||||
*
|
||||
* @return string The File extension
|
||||
* - dirname
|
||||
* - basename
|
||||
* - extension
|
||||
* - filename
|
||||
* - filesize
|
||||
* - mime
|
||||
*
|
||||
* @return array File information.
|
||||
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::info
|
||||
*/
|
||||
public function info() {
|
||||
|
@ -306,6 +313,9 @@ class File {
|
|||
if (!isset($this->info['filesize'])) {
|
||||
$this->info['filesize'] = $this->size();
|
||||
}
|
||||
if (!isset($this->info['mime'])) {
|
||||
$this->info['mime'] = $this->mime();
|
||||
}
|
||||
return $this->info;
|
||||
}
|
||||
|
||||
|
@ -536,4 +546,22 @@ class File {
|
|||
}
|
||||
return copy($this->path, $dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mime type of the file. Uses the finfo extension if
|
||||
* its available, otherwise falls back to mime_content_type
|
||||
*
|
||||
* @return false|string The mimetype of the file, or false if reading fails.
|
||||
*/
|
||||
public function mime() {
|
||||
if (function_exists('finfo_open')) {
|
||||
$finfo = finfo_open(FILEINFO_MIME);
|
||||
list($type, $charset) = explode(';', finfo_file($finfo, $this->pwd()));
|
||||
return $type;
|
||||
} else if (function_exists('mime_content_type')) {
|
||||
return mime_content_type($this->pwd());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue