3

我一直在用 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 一起工作?

4

1 回答 1

0

尝试不比较用户代理 con config.php 并且不在 cookie 名称上使用下划线。

于 2012-10-29T17:40:39.317 回答