laravel - 如何在 laravel 中使用播种机保存特定文件 .docx
问题描述
我想用播种机将文件.docx保存在laravel的mysql数据库中,,
这是我在 DocumentTableSeeder 中的代码
public function run()
{
DB::table('document')->insert([
'filename' => file_get_contents(database_path() . '/seeds/SOW.docx'),
]);
DB::table('document')->insert([
'filename' => file_get_contents(database_path() . '/seeds/RFQ.docx'),
]);
DB::table('document')->insert([
'filename' => file_get_contents(database_path() . '/seeds/TKDN.docx'),
]);
}
如何使用播种机 laravel 将 .docx 文件保存在 mysql 数据库中?请帮助谢谢
解决方案
您可以将列类型更改为longText
,可能文件的内容被截断。
并使用htmlenties
函数将文件内容转换为安全内容。
public function run()
{
DB::table('document')->insert([
'filename' => htmlentities(file_get_contents(database_path() . '/seeds/SOW.docx')),
]);
DB::table('document')->insert([
'filename' => htmlentities(file_get_contents(database_path() . '/seeds/RFQ.docx')),
]);
DB::table('document')->insert([
'filename' => htmlentities(file_get_contents(database_path() . '/seeds/TKDN.docx')),
]);
}
我不知道你的逻辑,但你不应该将文件内容保存到数据库中,你应该保存文件路径而不是文件内容。
推荐阅读
- spring - Spring JMS & Solace - 每个事务会话接收多条消息
- c# - 编写 Roslyn 分析器时如何获取给定变量名称的当前值?
- html - 什么是 tppabs 属性?
- php - CentOS + Apache:您无权访问此服务器上的 /info.php
- android - 软输入在文本选择上通过自定义键盘打开——如何防止
- c# - 由非托管 (C++) COM 服务器实例化的托管 (C#) 控件在 Windows 更新后中断
- azure - Azure 中的 Applicatoin_Start、Init 和水平缩放
- database - Postgresql - “,”或附近的语法错误
- typescript - TypeScript:获取对象本身内部的对象键的类型
- c++ - ifstream - 监控文件更新