本文整理汇总了PHP中Cake\Filesystem\File::mime方法的典型用法代码示例。如果您正苦于以下问题:PHP File::mime方法的具体用法?PHP File::mime怎么用?PHP File::mime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Filesystem\File
的用法示例。
在下文中一共展示了File::mime方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fileToUploadArray
/**
* Returns an array that matches the structure of a regular upload for a local file
*
* @param $file The file you want to get an upload array for.
* @param string Name of the file to use in the upload array.
* @return array Array that matches the structure of a regular upload
*/
public static function fileToUploadArray($file, $filename = null)
{
$File = new File($file);
if (empty($fileName)) {
$filename = basename($file);
}
return ['name' => $filename, 'tmp_name' => $file, 'error' => 0, 'type' => $File->mime(), 'size' => $File->size()];
}
示例2: testMimeTypeFalse
/**
* testMimeTypeFalse method
*
* @expectedException \RuntimeException
* @return void
*/
public function testMimeTypeFalse()
{
$image = CORE_PATH . 'Cake/Test/TestApp/webroot/img/cake.power.gif';
$File = new File($image, false);
$this->skipIf($File->mime(), 'mimeType can be determined, no Exception will be thrown');
Validation::mimeType($image, ['image/gif']);
}
示例3: _isImage
/**
* Check if given path is an image
* @param string $path path of the image
* @return bool true on success
*/
protected function _isImage($path)
{
$file = new File($path);
$mime = $file->mime();
return in_array($mime, $this->_mimeTypes);
}
示例4: getFileInfoFromUpload
/**
* Gets information about the file that is being uploaded.
* - gets the file size
* - gets the mime type
* - gets the extension if present
* - sets the adapter by default to local if not already set
* - sets the model field to the table name if not already set
*
* @param array|\ArrayAccess $upload
* @param string $field
* @return void
*/
public function getFileInfoFromUpload(&$upload, $field = 'file')
{
if (!empty($upload[$field]['tmp_name'])) {
$File = new File($upload[$field]['tmp_name']);
$upload['filesize'] = $File->size();
$upload['mime_type'] = $File->mime();
}
if (!empty($upload[$field]['name'])) {
$upload['extension'] = pathinfo($upload[$field]['name'], PATHINFO_EXTENSION);
$upload['filename'] = $upload[$field]['name'];
}
}
示例5: testMime
/**
* Test mime()
*
* @return void
*/
public function testMime()
{
$this->skipIf(!function_exists('finfo_open') && !function_exists('mime_content_type'), 'Not able to read mime type');
$path = TEST_APP . 'webroot/img/cake.power.gif';
$file = new File($path);
$expected = 'image/gif';
if (function_exists('mime_content_type') && mime_content_type($file->pwd()) === false) {
$expected = false;
}
$this->assertEquals($expected, $file->mime());
}
示例6: _upload
/**
* Upload function.
*
* @param string $fileName Original name of the tmp file.
* @param string $filePath Full path to the tmp file.
* @param bool $copy Whether copy or move the tmp file.
* @return array
*/
protected function _upload($fileName, $filePath, $copy = false)
{
$data = [];
if (!file_exists($filePath)) {
return $data;
}
$fileName = $this->generateUniqueFilename($fileName, $filePath);
$basePath = $this->basePath();
$fullPath = $basePath . DS . $fileName;
$folder = new Folder($basePath, true, 0775);
$transferFn = $copy ? 'copy' : 'move_uploaded_file';
if (file_exists($fullPath) || call_user_func_array($transferFn, [$filePath, $fullPath])) {
$file = new File($fullPath);
if (false !== $file->size()) {
$data = ['filename' => $fileName, 'size' => $file->size(), 'mime' => $file->mime(), 'created' => Time::now()];
}
}
return $data;
}
示例7: getType
/**
* Return the type from a File object
*
* @param File $file The file from which you get the type
* @return string
*/
protected function getType($file)
{
$extension = $file->ext();
if (isset($this->typeMap[$extension])) {
return $this->typeMap[$extension];
}
return $file->mime() ?: 'application/octet-stream';
}
示例8: mimeType
/**
* Validates mime types.
*
* @deprecated Use \Cake\Utility\Validation::mimeType() instead.
* @param array $value.
* @param array $mimeTypes.
* @return boolean
*/
public function mimeType($value, $mimeTypes)
{
if (is_string($mimeTypes)) {
$mimeTypes = [$mimeTypes];
}
$File = new File($value['tmp_name']);
$this->_mimeType = $this->_mimeType = $File->mime();
if (!in_array($this->_mimeType, $mimeTypes)) {
return false;
}
return true;
}