0

试图让 Uploadify 与 Codeigniter 一起工作时,我有点头疼。基本上我要做的是上传多个文件,然后运行数据库查询以将其详细信息添加到我的数据库中。稍后我将添加更复杂的代码(例如获取 EXIF/IPTC 数据),但现在我只需要它获取文件名并在上传后为每张照片插入数据库。

问题是我收到了 HTTP 302 错误。我设置了这个:

$config['sess_match_useragent'] = FALSE;

我还将以下内容放入我的 .htaccess 文件中:

SecFilterEngine Off
SecFilterScanPOST Off

但它导致整个站点停止工作,引发“内部服务器错误”。

我真的很想让 uploadify 工作,这很棒,只是 Codeigniter 的噩梦!

我的代码如下:

在我看来输入:

<input id="fileInput" name="fileInput" type="file" />
     <script type="text/javascript">
        $(document).ready(function() {
        $("#fileInput").uploadify({
            'uploader'       : '<?php echo base_url()?>assets/uploadify/uploadify.swf',
            'script'         : '<?php echo site_url()?>/upload/do_upload/',
            'cancelImg'      : '<?php echo base_url()?>assets/uploadify/cancel.png',
            'fileExt'        : '*.jpg;*.jpeg',
            'folder'         : 'assets/photos/highres',
            'auto'           : true,
            'multi'          : true,
            'onError'        : function (event,ID,fileObj,errorObj) {
                          alert(errorObj.type + ' Error: ' + errorObj.info);
                        }
        });    });

    </script>

我的控制器:

public function do_upload()
        {
            // check for login, if logged in
            if($this->session->userdata('logged_in') == "1")
            {
                $config['upload_path'] = 'assets/photos/highres/';
                $config['allowed_types'] = 'jpg';
                $config['max_size'] = '1000000';
                $config['overwrite'] = FALSE;
                $config['remove_spaces'] = TRUE;
                $config['encrypt_name'] = FALSE;

                $this->load->library('upload', $config);

                if(! $this->upload->do_upload('Filedata'))
                {
                    echo $this->upload->display_errors();
                }
                else
                {
                   $errors = $this->upload->display_errors();

                   $upload_info = $this->upload->data();

                   // Insert file information into database
                   $data = array(
                                    'id' => NULL,
                                    'filename' => $upload_info['file_name']
                                );
                   $this->db->insert('photos', $data);
                  }
            } 
            else
            {
                // redirect to signin page if not logged in
                redirect('signin');
            }
        }

非常感谢任何帮助!

4

1 回答 1

2

更改文件 /application/config/mimes.php 添加

'application/octet-stream'

'jpeg'  =>  array('image/jpeg', 'image/pjpeg'),
'jpg'   =>  array('image/jpeg', 'image/pjpeg'),
'jpe'   =>  array('image/jpeg', 'image/pjpeg'),
'png'   =>  array('image/png',  'image/x-png'),

最后是这样的哑剧

'jpeg'  =>  array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
'jpg'   =>  array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
'jpe'   =>  array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
'png'   =>  array('image/png',  'image/x-png', 'application/octet-stream'),
于 2012-05-31T12:23:41.957 回答