本书未发布

字段:文件上传 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
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
讨论数量: 0
发起讨论 只看当前版本


暂无话题~