Php 如何在kohana中使用blueimp jquery文件上载?
我想在kohana框架中使用blueimp jquery文件上传,但无法正确实现它。我有一个带有索引操作的控制器,其上载处理程序初始化如下:Php 如何在kohana中使用blueimp jquery文件上载?,php,kohana,jquery-file-upload,Php,Kohana,Jquery File Upload,我想在kohana框架中使用blueimp jquery文件上传,但无法正确实现它。我有一个带有索引操作的控制器,其上载处理程序初始化如下: class Controller_Ajax_Jfupload extends Controller_Ajax { public function action_index() { $upload_handler = new UploadHandler(); } } UploadHan
class Controller_Ajax_Jfupload extends Controller_Ajax {
public function action_index() {
$upload_handler = new UploadHandler();
}
}
UploadHandler.php被复制到/Controller文件夹。我用示例文件中给出的html创建了视图。但这根本不起作用。我不知道在我的上传控制器上把url指向哪里。有很多方法:这是我的方法
public function action_index() {
//no render the body of page : error json
$this->auto_render=false;
error_reporting(E_ALL | E_STRICT);
require('UploadHandler.php');
$upload_handler = new UploadHandler();
}
不要忘记页面中的以下脚本:
<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-upload fade">
<td>
<span class="preview"></span>
</td>
<td>
<p class="name">{%=file.name%}</p>
<strong class="error text-danger"></strong>
</td>
<td>
<p class="size">Processing...</p>
<div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="progress-bar progress-bar-success" style="width:0%;"></div></div>
</td>
<td>
{% if (!i && !o.options.autoUpload) { %}
<button class="btn btn-primary start" disabled>
<i class="glyphicon glyphicon-upload"></i>
<span>Start</span>
</button>
{% } %}
{% if (!i) { %}
<button class="btn btn-warning cancel">
<i class="glyphicon glyphicon-ban-circle"></i>
<span>Cancel</span>
</button>
{% } %}
</td>
</tr>
{% } %}
</script>
<script id="template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-download fade">
<td>
<span class="preview">
{% if (file.thumbnailUrl) { %}
<a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" data-gallery><img src="{%=file.thumbnailUrl%}"></a>
{% } %}
</span>
</td>
<td>
<p class="name">
{% if (file.url) { %}
<a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a>
{% } else { %}
<span>{%=file.name%}</span>
{% } %}
</p>
{% if (file.error) { %}
<div><span class="label label-danger">Error</span> {%=file.error%}</div>
{% } %}
</td>
<td>
<span class="size">{%=o.formatFileSize(file.size)%}</span>
</td>
<td>
{% if (file.deleteUrl) { %}
<button class="btn btn-danger delete" data-type="{%=file.deleteType%}" data-url="{%=file.deleteUrl%}"{% if (file.deleteWithCredentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>
<i class="glyphicon glyphicon-trash"></i>
<span>Delete</span>
</button>
<input type="checkbox" name="delete" value="1" class="toggle">
{% } else { %}
<button class="btn btn-warning cancel">
<i class="glyphicon glyphicon-ban-circle"></i>
<span>Cancel</span>
</button>
{% } %}
</td>
</tr>
{% } %}
</script>
$(function() {
'use strict';
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload({
// Uncomment the following to send cross-domain cookies:
//xhrFields: {withCredentials: true},
url: 'yourUrl' (in this case index)
});
// Enable iframe cross-domain access via redirect option:
if (window.location.hostname === 'blueimp.github.io') {
// Demo settings:
$('#fileupload').fileupload('option', {
url: '//jquery-file-upload.appspot.com/',
// Enable image resizing, except for Android and Opera,
// which actually support image resizing, but fail to
// send Blob objects via XHR requests:
disableImageResize: /Android(?!.*Chrome)|Opera/
.test(window.navigator.userAgent),
maxFileSize: 5000000,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i
});
// Upload server status check for browsers with CORS support:
if ($.support.cors) {
$.ajax({
url: '//jquery-file-upload.appspot.com/',
type: 'HEAD'
}).fail(function() {
$('<div class="alert alert-danger"/>')
.text('Upload server currently unavailable - ' +
new Date())
.appendTo('#fileupload');
});
}
} else {
// Load existing files:
$('#fileupload').addClass('fileupload-processing');
$.ajax({
// Uncomment the following to send cross-domain cookies:
//xhrFields: {withCredentials: true},
url: $('#fileupload').fileupload('option', 'url'),
dataType: 'json',
context: $('#fileupload')[0]
}).always(function() {
$(this).removeClass('fileupload-processing');
}).done(function(result) {
alert('done')
$(this).fileupload('option', 'done')
.call(this, $.Event('done'), {result: result});
});
}
});
</script>
{%for(var i=0,file;file=o.files[i];i++){%}
{%=file.name%}
处理
{%if(!i&&!o.options.autoUpload){%}
开始
{% } %}
{%if(!i){%}
取消
{% } %}
{% } %}
{%for(var i=0,file;file=o.files[i];i++){%}
{%if(file.thumbnailUrl){%}
{% } %}
{%if(file.url){%}
{%}其他{%}
{%=文件名%}
{% } %}
{%if(file.error){%}
错误{%=file.Error%}
{% } %}
{%=o.formatFileSize(file.size)%}
{%if(file.deleteUrl){%}
删除
{%}其他{%}
取消
{% } %}
{% } %}
$(函数(){
"严格使用",;
//初始化jQuery文件上载小部件:
$('#fileupload')。fileupload({
//取消对以下内容的注释以发送跨域cookie:
//xhrFields:{withCredentials:true},
url:'yourUrl'(在本例中为索引)
});
//通过重定向选项启用iframe跨域访问:
if(window.location.hostname=='blueimp.github.io'){
//演示设置:
$('#fileupload')。fileupload('选项'{
url:“//jquery file upload.appspot.com/”,
//启用图像大小调整,Android和Opera除外,
//它实际上支持图像大小调整,但无法
//通过XHR请求发送Blob对象:
disableImageResize:/Android(?。*Chrome)| Opera/
.test(window.navigator.userAgent),
最大文件大小:5000000,
acceptFileTypes:/(\.\/)(gif | jpe?g | png)$/i
});
//支持CORS的浏览器的上载服务器状态检查:
如果($.support.cors){
$.ajax({
url:“//jquery file upload.appspot.com/”,
类型:“头”
}).fail(函数(){
$('')
.text('上载服务器当前不可用-'+
新日期()
.appendTo(“#fileupload”);
});
}
}否则{
//加载现有文件:
$('#fileupload').addClass('fileupload-processing');
$.ajax({
//取消对以下内容的注释以发送跨域cookie:
//xhrFields:{withCredentials:true},
url:$('#fileupload')。fileupload('option','url'),
数据类型:“json”,
上下文:$('#fileupload')[0]
}).always(函数(){
$(this.removeClass('fileupload-processing');
}).完成(功能(结果){
警报(“完成”)
$(此).fileupload('option','done')
.call(this,$.Event('done'),{result:result});
});
}
});