我没有得到任何错误,没有,但是图像没有被上传,就像控制器根本没有调用一样,当我添加contruct函数log_message我在日志文件中看不到任何内容,不确定是什么问题。顺便说一下,我正在使用这个库(http://jeromejaglale.com/doc/php/codeigniter_i18n)来管理语言,所以我在url http://getit.mysite/en
这是我的控制器功能
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class FileUpload extends CI_Controller {
public $view_data = array();
private $upload_config;
function __construct() {
parent::__construct();
}
public function do_upload() {
$this->load->library('upload');
$image_upload_folder = base_url() . 'uploads/';
if (!file_exists($image_upload_folder)) {
mkdir($image_upload_folder, DIR_WRITE_MODE, true);
}
$this->upload_config = array(
'upload_path' => $image_upload_folder,
'allowed_types' => 'png|jpg|jpeg|bmp|tiff',
'max_size' => 2048,
'remove_space' => TRUE,
'encrypt_name' => TRUE,
);
$this->upload->initialize($this->upload_config);
if (!$this->upload->do_upload()) {
$upload_error = $this->upload->display_errors();
echo json_encode($upload_error);
} else {
$file_info = $this->upload->data();
echo json_encode($file_info);
}
}
}
?>
和js
jQuery(document).ready(function($) {
var base_url = 'http://getit.mycom/';
$('#upload-file').click(function(e) {
e.preventDefault();
$('#userfile').uploadify('upload', '*');
});
$('#userfile').uploadify({
'auto': false,
'swf': base_url + 'js/uploadify/uploadify.swf',
'cancelImg': base_url + 'js/uploadify/uploadify-cancel.png',
'uploader': base_url + 'fileupload/do_upload',
'fileTypeExts': '*.jpg;*.bmp;*.png;*.tif',
'fileTypeDesc': 'Image Files (.jpg,.bmp,.png,.tif)',
'fileSizeLimit': '8MB',
'fileObjName': 'userfile',
'buttonText': 'Select Photo(s)',
'multi': true,
'removeCompleted': false
});
});
和查看文件(添加用户):
<?php echo form_open_multipart(); ?>
<ul class="unstyled">
<li>
<?php echo form_upload('userfile', '', 'id="userfile"'); ?>
<?php echo (isset($error)) ? $error : ''; ?>
</li>
<li>
<?php echo form_button(array('content' => 'Upload', 'id' => 'upload-file', 'class' => 'btn btn-large btn-primary')); ?>
</li>
</ul>
<?php echo form_close(); ?>
答案 0 :(得分:0)
在控制器代码处,将if (!$this->upload->do_upload())
更改为if (!$this->upload->do_upload('Filedata'))
。试试吧。