尝试在十月CMS下创建一个组件,它应该允许前端多个文件上传。我尝试在已经存在的形式中集成Blueimp jQuery-File-Upload插件,因为10月份的CMS使用了一个集成的ajax框架,它允许将数据提交给组件方法,所以我会使用这个ajax方法,而不是Blueimp默认的方法
所以一个正常的文件上传看起来像这样
$('#gallery').fileupload({
// Uncomment the following to send cross-domain cookies:
//xhrFields: {withCredentials: true},
url: 'path/to/controller'
});但是我想用一些像这样的东西
$('#gallery').fileupload({
// Uncomment the following to send cross-domain cookies:
//xhrFields: {withCredentials: true},
add: function (e, data) {
data.submit();
$.request('onUploads', {
success: function(data){
console.log(data);
}
})
}
});发布于 2015-04-03 04:54:41
您需要使用OctoberCMS所在的Request class from Laravel。基本上,您可以转到布局文件的代码部分并添加
function onUploads()
{
// Get the file
$file = Request::file('somefile');
// Code to do something with it
// enter code here
}根据您试图实现的目标,您可以编写适当的代码来上传它。例如,在my Social Login plugin中,我使用this class的方法从选定的社交网络获取照片,并在插件的社交模型和上传的文件之间创建关系,以便前端用户可以在其web应用程序中将照片输出为显示照片。
另一个很好的方法是直接上传到主题目录中,比如Request::file('somefile')->move(app_path() . '/themes/yourtheme/assets/uploads/');,但是你需要添加代码来限制上传的大小,并修改文件名。如果你在实现某件事上需要帮助,请随时发表评论。gl hf
https://stackoverflow.com/questions/28086615
复制相似问题