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 である認証ライブラリ内にあることに気付きました。CI_Controller の代わりにアプリケーションを拡張するコントローラーが必要です。それを削除してコントローラーを CI_Controller に戻すと、IE で動作します。しかし、これは実際には安全ではありません。問題は、extend Aplication を使用すると IE で動作しないのに、chrome と firefox で動作するのはなぜですか?

4

1 に答える 1

0

ユーザー エージェント con config.php を比較したり、Cookie 名にアンダースコアを使用したりしないでください。

于 2012-10-29T17:40:39.317 に答える