本书未发布

字段:文件上传 File

未匹配的标注

文档尚未来得及翻译,欢迎以改进的方式提交译文。

Field Type - File

Usage

field-type-file.png

The file field type should be a text-like type in your database. The file's name is stored in this field, while the original will be saved in the location you specify, and any resized copies will be stored where you define in the sizes option.

'media_document' => array(
    'title' => 'File',
    'type' => 'file',
    'location' => storage_path() . '/media_documents/',
    'naming' => 'random',
    'length' => 20,
    'size_limit' => 2,
    'display_raw_value' => false,
    'mimes' => 'pdf,psd,doc',
)

In the edit form, an admin user will be presented with a file uploader.

The required location option lets you define where the file should be stored.

The optional naming option lets you define whether to keep the file's name or to make the file name random. By default this is set to random in order to avoid naming collisions, but setting this to keep lets you keep your file's names.

The optional length option lets you define size of file name in case random is supplied in the naming option.

The optional size_limit option lets you set an integer size limit counted in megabytes. This only affects the JavaScript file uploading dialog, it doesn't limit your PHP upload sizes (which you can do in your php.ini).

The optional display_raw_value option lets you put the raw value of the saved file source string into the displayed file link. This is useful if you're using accessors, mutators, and setter fields to skip storing the file on your local server and instead upload it to a remote public file server.

The optional mimes option by default allows all file types. This uses Laravel's mimes validation, which in turn uses the PHP Fileinfo extension to read the contents of the file and determine the actual MIME type.

本文章首发在 LearnKu.com 网站上。

上一篇 下一篇
Summer
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 0
发起讨论 查看所有版本


暂无话题~