2011-03-23 51 views
0

我修改了一個我在這裏找到的腳本來處理一次上傳多張圖片。但是,當我嘗試運行該腳本時會引發錯誤。我使用該腳本只允許一張圖片在時間上傳,並且沒有任何問題。上傳多張圖片導致500錯誤

這是我的代碼。

Function uploadMultiple(){ 
    $config = array(
     'allowed_types' => 'jpg|png|jpeg|gif', 
     'upload_path' => $this->board_path, 
     'overwrite' => false, 
     //'file_name' => $fileName 

    ); 
    //print_r($config); 

    $this->load->library('upload'); 
    $errorCount = 0; 
    $results = array(
     'errorsPresent' => false, 
    ); 
    $successCount = 0; 

    //for each image...try to upload. if it fails, add it to the error list. 
    //keep a list of successful uploads. 
    print_r($_FILES); 
    for ($i = 0; $i<count($_FILES); $i++){ 
     echo 'here'; 
     $_FILES['userfile']['name'] = $_FILES['userfile' . $i]['name']; 
     $_FILES['userfile']['type'] = $_FILES['userfile' . $i]['type']; 
     $_FILES['userfile']['tmp_name'] = $_FILES['userfile' . $i]['tmp_name']; 
     $_FILES['userfile']['error']  = $_FILES['userfile' . $i]['error']; 
     $_FILES['userfile']['size'] = $_FILES['userfile' . $i]['size']; 

     $config['file_name']  = 'img_' . time() . '.png'; //inserts the unix time into the file name. 
     $config['upload_path'] = $this->board_path; 
     $config['allowed_types'] = 'jpg|jpeg|gif|png'; 
     $config['max_size']  = '0'; 
     $config['overwrite']  = FALSE; 
     $this->upload->initialize($config); 

     if (! $this->upload->do_upload()){ 
      $results['errorsPresent'] = true; 
      $results['error'][$errorCount] = $this->upload->display_errors(); 
      $errorCount ++; 

     } else { 
      $data = array('upload_data' => $this->upload->data());    
      $pictureData = $this->upload->data(); 
      $file_location = $pictureData['full_path']; 
      $file_location = substr($file_location, 18);//this should probably be dynamic... 
      $file_location = $this->db->escape($file_location); 
      $results['success'][$successCount] = $file_location; 

      chmod($pictureData['full_path'], 777); //don't need to give it execute permissions but oh well. 
      $successCount ++;  
     } 

    } 

    return $results; 
} 

這是500錯誤。

內部服務器錯誤

服務器遇到一個內部錯誤 或配置錯誤, 無法完成您的請求。

請與服務器管理員 ,站長@本地和 通知他們的錯誤 發生的時間,以及任何你可能有 做到這一點可能造成的錯誤。

關於此錯誤的更多信息可能在服務器錯誤日誌中可用 。

此外,500內部服務器 錯誤錯誤遇到,而 試圖使用ErrorDocument到 處理請求。

這是Apache日誌文件中這樣說:

[週三3月23日2時29分41秒2011] [錯誤] [客戶端129.21.129.32] ModSecurity的:拒絕訪問代碼爲500(相位4)。模式匹配「(?:\ b(?:(?:s(?:選舉列表,因爲它不包含在(?:一個集合函數中,並且不存在|一個集合函數或))GROUP BY子句|提供的參數在RESPONSE_BODY中不是有效的(?:(?:M(?:S | y)| Postgre)SQL | O(?:racle | DBC)))| S(?:yntax error converti ...) 「/etc/apache2/conf.d/modsecurity/modsecurity_crs_50_outbound.conf」] [line「23」] [id「970003」] [msg「SQL Information Leakage」] [severity「WARNING」] [tag「LEAKAGE/ERRORS」 ] [主機名 「hostname.com」] [URI 「/longboard/index.php/board/add」] [UNIQUE_ID 「TYmTVYEVgWYAAASKoIcAAAAJ」]

基於該錯誤消息,我認爲ModSecurity的阻擋了腳本一些原因,但我不知道爲什麼。任何見解將不勝感激。

感謝

+0

請問您可以在這裏發佈'$ results'變量嗎? – BigFatBaby 2011-03-23 09:54:40

+0

帶有500錯誤的頁面錯誤,因此我的echo或print_r語句不打印。 – henex 2011-03-25 02:11:36

回答

0

它結束了一個數據庫錯誤。 Mod_security阻止了錯誤消息。我進入了mod_security日誌文件,發現哪個規則導致它拋出500錯誤。然後我用這個規則進入文件並評論它。我重新啓動apache並重新測試,然後顯示數據庫錯誤。由於這是一個開發服務器,我正在考慮將這條規則留下評論。 (它確實向全世界廣播,也是我安裝了Mod_security的原因。)

0

嘗試禁用mod_security後, 在.htaccess中添加此

SecFilterEngine Off 
+0

我試過了,不幸的是沒有效果。 – henex 2011-03-25 02:12:04