2012-04-17 131 views
0

我有點頭痛,試圖讓Uploadify與Codeigniter一起工作。基本上我想要做的是上傳多個文件,然後運行數據庫查詢將它的細節添加到我的數據庫。我將在稍後添加更復雜的代碼(如獲取EXIF/IPTC數據),但現在我只需要它來獲取每張照片上傳後的文件名並插入數據庫。Getting Uploadify使用Codeigniter - 302 HTTP錯誤

問題是我得到一個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'); 
      } 
     } 

任何幫助最讚賞!

回答

2

改變文件/application/config/mimes.php 上

'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'), 

添加

'application/octet-stream' 

終於像這樣

'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'), 
的默劇