我尝试了许多多文件上传器,可以与codeigniter集成,如
- 浆负载
- jquery文件上传
虽然它们在纯php环境下工作得很好,但我不能让它们在codeigniter框架下工作。我试了两天。试了很多github和博客上的文章。但我不能在codeigniter框架下工作。如果有人能一步一步地告诉我,或者如果有教程的话,请帮助我。我是一个codeigniter新手。
新:我下载了blueimp Jquery-File-Upload插件,并按照这个链接,因为它是.. https://github.com/blueimp/jQuery-File-Upload/wiki/Latest-jQuery-File-Upload-easy-integration-with-codeigniter
当我选择一个文件,并点击chrome上传它说:
Error SyntaxError: Unexpected token <
火狐在上面说:
Error SyntaxError: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
我研究了在我的服务器和演示服务器上使用它的区别,在我的服务器上,在firebug中POST返回的是整个index.html...但在演示服务器上,它返回JSON数据。
下面是js/main.js中我修改过的部分:
$(function () {
'use strict';
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload({
// Uncomment the following to send cross-domain cookies:
//xhrFields: {withCredentials: true},
url: 'upload/do_upload'
});
// Enable iframe cross-domain access via redirect option:
$('#fileupload').fileupload(
'option',
'redirect',
window.location.href.replace(
/\/[^\/]*$/,
'/cors/result.html?%s'
)
);
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) {
$(this).fileupload('option', 'done')
.call(this, $.Event('done'), {result: result});
});
}
});
我所做的唯一更改是使index.html的表单操作指向我的脚本(upload/do_upload)
1条答案
按热度按时间thigvfpy1#
控制器