这是我在 codeigniter 代码中使用 ajaxfileupload 和 Jquery 上传图像的代码。但是 codeigniter 代码在日志文件中给出错误。它的上传。但是当我在没有 jquery 和 ajaxfileupload 脚本的情况下测试相同的代码时。
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="//localhost/AjaxFileUploader/ajaxfileupload.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#form").change(function () {
$("#upload").html('<img src="loader.gif"/>');
$.ajaxFileUpload({
url: 'http://localhost/ci/index.php/upload/do_upload',
secureuri: false,
fileElementId: 'userfile',
dataType: 'json',
success: function (data, status) {
if (typeof (data.error) != 'undefined') {
if (data.error != '') {
alert(data.error);
} else {
alert(data.msg);
}
}
},
error: function (data, status, e) {
alert(e);
}
});
});
});
</script></head>
<body>
<form action="http://localhost/ci/index.php/upload/do_upload" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<input type="file" name="userfile" size="20" id="form" />
<br /><br />
<input type="submit" value="upload" id="submit" />
<span id="upload"></span>
</form></body>
</html>
我的codeigniter代码是
function do_upload()
{
$config['upload_path'] = 'c:\upload';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
但是codeigniter没有上传文件。它在日志文件中出现错误,例如“您没有选择要上传的文件”。