jaimevalasek / jv-mime-types
通用的 MimeTypes 模块,主要用于 JVUpload 模块。
Requires
- php: >=5.3.3
- zendframework/zendframework: 2.*
This package is not auto-updated.
Last update: 2024-09-24 04:30:22 UTC
README
创建者:Jaime Marcelo Valasek
使用此模块通过 mime-types 或扩展名验证文件上传。
未来视频课程可以在网站或 YouTube 频道 http://www.zf2.com.br/tutoriais - http://www.youtube.com/zf2tutoriais 开发和发布
安装
将此模块下载到您的 vendor 文件夹。
完成以上步骤后,打开文件 config/application.config.php
。并添加名为 JVMimeTypes
的模块。
使用 JVMimeTypes
实例化 JVMimeTypes 类模块
use JVMimeTypes\Service\MimeTypes; $serviceMimeTypes = new MimeTypes($this->getServiceLocator()->get('servicemanager'));
/* * Listing the mime types with extensions as an index - custom in `config/module.config.php` * Passing false as the second parameter returns the numerical indices */ // This code below examples are the profiles that are within the configuration file `config/module.config.php` 'mime_types_custom' => array( 'ext-images-thumb' => array( 'jpg', 'jpeg', 'png', 'gif' ), 'ext-images-min' => array( 'jpg', 'jpeg', 'png', 'gif', 'bmp', 'tif' ), 'ext-audio-min' => array( 'mp3', 'wma' ), 'ext-video-min' => array( 'mp4', 'flv', 'avi', 'wmv' ), 'ext-application-min' => array( 'exe' ), 'ext-ms-oficce' => array( 'xls', 'doc', 'ppt', 'docx', 'xlsx' ), ) // Executing of the method exit(print_r($serviceMimeTypes->getMimeTypeCustom(array('ext-audio-min')))); // Result Array ( [mp3] => video/x-mpeg [wma] => audio/x-ms-wma ) /* * Listing extensions custom audio */ exit(print_r($serviceMimeTypes->getExtCustom(array('ext-audio-min')))); // result Array ( [0] => mp3 [1] => wma )
所有可用方法
-
获取标准文件扩展名的方法
getExtImage();
getExtAudio();
getExtVideo();
getExtApplication();
getExtText();
getExtFiles();
-
获取文件 mime 类型的模式方法
getMimeTypeImage()
getMimeTypeAudio()
getMimeTypeVideo()
getMimeTypeApplication()
getMimeTypeText()
getMimeTypeFiles()
-
自定义方法 - 通过访问
config/module.config.php
文件创建自己的 mime 类型配置,只需遵循示例并调用自定义方法,例如:getExtCustom(array('ext-audio-min'));
getMimeTypeCustom(array('ext-audio-min'));