我一直在使用Codeigniter和Uploadify创建一个照片库,它在chrome和firefox上运行良好。但是在IE上,当我上传图像时,文件会在创建缩略图的服务器上传,但没有数据记录到数据库中。在IE上传完成后,当我重新加载页面时,我总是自动退出并且必须再次登录。我正在使用ag_auth库。
控制器中的上传方法:
public function do_upload() {
$this->load->library('upload');
$gallery_title = $this->input->post('galleryTitle');
$gallery_id = $this->input->post('galleryID');
$folder_title = str_replace(' ', '_', $gallery_title);
$image_upload_folder = FCPATH . '/uploads/image-gallery/' . $folder_title;
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' => FALSE,);
$this->upload->initialize($this->upload_config);
if (!$this->upload->do_upload()) {
$upload_error = $this->upload->display_errors();
echo json_encode($upload_error);
} else {
$thumb_upload_folder = $image_upload_folder . '/thumb';
if (!file_exists($thumb_upload_folder)) {
mkdir($thumb_upload_folder, DIR_WRITE_MODE, true);
}
$img = $this->upload->data();
// create thumbnail
$new_image = $thumb_upload_folder . '/thumb_' . $img['file_name'];
$c_img_lib = array('image_library' => 'gd2', 'source_image' => $img['full_path'], 'maintain_ratio' => TRUE, 'width' => 120, 'height' => 120, 'new_image' => $new_image);
$this->load->library('image_lib', $c_img_lib);
$this->image_lib->resize();
$file_info = $this->upload->data();
echo json_encode($file_info);
$root_path = str_replace("\\", "/", FCPATH);
$path = str_replace($root_path, "", $file_info['file_path']);
$url = $path . $file_info['file_name'];
$thumb_url = $path . 'thumb/thumb_' . $file_info['file_name'];
$this->load->database();
$query = array('url' => $url, 'thumb_url' => $thumb_url, 'gallery_id' => $gallery_id);
$this->db->insert('images', $query);
$inserted_id = $this->db->insert_id();
$query2 = array('order' => $inserted_id);
$this->db->where('id', $inserted_id);
$this->db->update('images', $query2);
}
}
javascript在视图文件中:
<script type="text/javascript">
$(document).ready(function () {
var base_url = '<?php echo base_url(); ?>';
$('#upload-file').click(function (e) {
e.preventDefault();
$('#userfile').uploadify('upload', '*');
});
$('#userfile').uploadify({
'debug':true,
'auto':true,
'swf': base_url + 'assets/js/jquery/uploadify_31/uploadify.swf',
'uploader': base_url + 'glenn-admin/image_gallery/do_upload',
'cancelImg': base_url + 'assets/javascript/jquery/uploadify_31/uploadify-cancel.png',
'fileTypeExts':'*.jpg;*.bmp;*.png;*.tif',
'fileTypeDesc':'Image Files (.jpg,.bmp,.png,.tif)',
'fileSizeLimit':'2MB',
'fileObjName':'userfile',
'buttonText':'Upload Photos',
'multi':true,
'removeCompleted':true,
'method': 'post',
'formData': {'galleryTitle': '<?php echo $gallery_title ?>', 'galleryID': '<?php echo $gallery_id ?>'},
'onUploadError' : function(file, errorCode, errorMsg, errorString) {
alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
},
'queueID' : 'image-queue',
'onUploadProgress' : function(file, bytesUploaded, bytesTotal, totalBytesUploaded, totalBytesTotal) {
$('#progressbar').progressbar({
value: (totalBytesUploaded/totalBytesTotal)*100
});},
});
</script>
这真的让我很难过。真的很感激,如果有人有这方面的解决方案。 PS:
哦,我刚刚意识到问题出在我正在使用的身份验证库中,这就是AG_auth。它需要控制器扩展Application而不是CI_Controller,当我删除它并将控制器扩展回CI_Controller时,它适用于IE。但这真的不安全。所以问题是当我使用扩展应用程序但是在chrome和firefox上工作时,为什么它不适用于IE?
答案 0 :(得分:0)
尝试不比较用户代理con config.php而不在cookie名称上使用下划线。