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


PHP File::mime方法代码示例

本文整理汇总了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()];
 }
开发者ID:tiagocapelli,项目名称:cakephp-file-storage,代码行数:15,代码来源:StorageUtils.php

示例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']);
 }
开发者ID:malhan23,项目名称:assignment-3,代码行数:13,代码来源:ValidationTest.php

示例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);
 }
开发者ID:edukondaluetg,项目名称:image,代码行数:11,代码来源:ImageBehavior.php

示例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'];
     }
 }
开发者ID:tiagocapelli,项目名称:cakephp-file-storage,代码行数:24,代码来源:FileStorageTable.php

示例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());
 }
开发者ID:Slayug,项目名称:castor,代码行数:16,代码来源:FileTest.php

示例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;
 }
开发者ID:karolak,项目名称:cakephp-image,代码行数:27,代码来源:ImageBehavior.php

示例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';
 }
开发者ID:markstory,项目名称:cakephp-spekkoek,代码行数:14,代码来源:AssetMiddleware.php

示例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;
 }
开发者ID:tiagocapelli,项目名称:cakephp-file-storage,代码行数:20,代码来源:UploadValidator.php


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