我上传图片没有问题,但当我尝试上传pdf,doc或xls等文档时,出现以下错误
无法上传" Document.pdf"。不允许使用文件类型
我的配置文件
ivory_ck_editor:
default_config: default
configs:
default:
toolbar: standard
filebrowserBrowseRoute: elfinder
filebrowserBrowseRouteParameters: []
fm_elfinder:
#assets_path: / # default is /assets, this is where css/js elfinder files are
instances:
default:
locale: %locale% # defaults to current request locale
editor: ckeditor # other options are tinymce, tinymce4, fm_tinymce, form, simple, custom
#editor_template: custom template for your editor # default null
#path_prefix: / # for setting custom assets path prefix, useful for non vhost configurations, i.e. http://127.0.0.1/mysite/
#fullscreen: true|false # default is true, applies to simple and ckeditor editors
#theme: smoothness # jquery theme, default is 'smoothness'
include_assets: true # disable if you want to manage loading of javascript and css assets manually
#visible_mime_types: ['image/png', 'image/jpg', 'image/jpeg'] # only show these mime types, defaults to show all
connector:
#debug: true|false # defaults to false
roots: # at least one root must be defined, defines root filemanager directories
uploads:
#show_hidden: true|false # defaults to false, hides dotfiles
driver: LocalFileSystem
path: uploads
upload_allow: ['image/png', 'image/jpg', 'image/jpeg','text/txt', 'document/pdf', 'document/docx', 'document/xlsx']
upload_deny: ['all']
upload_max_size: 10M # also file upload sizes restricted in php.ini
我更改了upload_allow设置。
如何上传pdf,doc或xls文件?
答案 0 :(得分:1)
如果找到此网站http://mime.ritey.com/,它可以帮助我找出文件的mime类型。如果编辑器是ckeditor,则无需更改upload_allow,因为它将任何文件作为图像插入。
我们必须使用editor:form
将表单实例添加到fm_elfinderfm_elfinder:
instances:
default:
locale: %locale%
editor: ckeditor
include_assets: true
connector:
roots:
uploads:
driver: LocalFileSystem
path: uploads
upload_allow: ['image/png', 'image/jpg', 'image/jpeg']
upload_deny: ['all']
upload_max_size: 10M
form:
locale: %locale%
editor: form
fullscreen: true
include_assets: true
connector:
debug: false
roots:
uploads:
driver: LocalFileSystem
path: uploads
upload_allow: ['image/png', 'image/jpg', 'image/jpeg', 'application/pdf', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']
upload_deny: ['all']
upload_max_size: 10M
我添加了mime类型的PDF,Word,Excel和Powerpoint文件。
,表格是
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Ivory\CKEditorBundle\Form\Type\CKEditorType;
use FM\ElfinderBundle\Form\Type\ElFinderType;
class PublicationType extends AbstractType
{ public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title', TextType::class)
->add('document', ElFinderType::class, array('instance'=>'form', 'enable'=>true))
->add('description', CKEditorType::class, array(
'required' => false, 'empty_data' => null))
->add('content', FileType::class)
->add('publicationDate', DateType::class, array(
'years' => range(date('Y')-15, date('Y'))
))
;
}
使用ElFinderType,我可以上传任何类型的文件