php - 如何将文件保存在文件存储中(本地驱动程序) - Laravel
问题描述
我有这个 ajax 可以用 Laravel 插入到 db 中。
$(document).one('click','.insertar', function () {
//var seleccion_etiquetas = $('#seleccion_editar_etiquetas').select2("val");+'&id_etiquetas='+seleccion_etiquetas
var id ="";
var data = $('#datos').serialize();
$.ajax({
type: 'post',
url: "/inserta/"+id,
data: data+'&fotos='+$("#formulario input[name='fotos']").val(),
success: function () {
$('#formulario input[type="text"]').val("");
tablalocales.ajax.reload();
},
complete: function () {
$("#seleccion_editar_etiquetas").val(null).trigger("change");
}
});
});
并返回:
_token: XtpzU3lBFvmTPdRisMqkwxs83dTH1xlLx2OZVQNT
nombre: qwe
direccion: asd
seleccion_editar: 1
id_locales:
id_etiquetas[]: 1
**fotos: C:\fakepath\relaciones.png**
inserta/
我想在控制器中插入:
$local = new Local();
$local->nombre = $pedido->nombre;
$local->direccion = $pedido->direccion;
$local->idfamilias = $pedido->seleccion_editar;
// with this --> $local = $pedido->file('fotos')->store('storage/app/public');
$local->save();
在控制台中,我进行了文件存储php artisan storage:link的第一步, 我只想将文件上传到 Storage/
解决方案
使用此命令,您可以将文件存储在文件系统上。并且如文档中所述 The path to the file will be returned by the store method so you can store the path, including the generated file name, in your database.
在你的情况下应该是这样的:
$path = $pedido->file('fotos')->store('your_dir_name');
$local->file_url = $path;
推荐阅读
- css - Sass @extend 与向组件添加类
- android - 找不到任何与 com.google.firebase:firebase-iid:[16.0.0] 匹配的版本
- javascript - 将数组组转换为对象
- angular - 如何在另一个打开的选项卡中使用组件的更改?
- angular5 - 更改组件数组的值后视图不更新
- sql - SQL ORDER BY,获取列表末尾的负值
- javascript - 函数原型调用另一个函数原型 javascript
- nginx - Plesk - nginx 反向代理 - 忽略子文件夹
- buildroot - 再次运行 make 时,删除覆盖中的文件不会在 rootfs 中删除它们
- javascript - 调用一个函数的返回值给另一个函数