我修改了我在这里找到的一个脚本来处理一次上传的多张图片。但是,当我尝试运行脚本时,它会引发错误。我曾经让脚本一次只允许上传一张图片,而且效果很好,没有任何问题。
这是我的代码。
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错误。
内部服务器错误
服务器遇到内部错误或配置错误,无法完成您的请求。
请联系服务器管理员 webmaster@localhost 并告知他们错误发生的时间,以及您所做的任何可能导致错误的事情。
服务器错误日志中可能提供有关此错误的更多信息。
此外,在尝试使用 ErrorDocument 处理请求时遇到 500 Internal Server Error 错误。
这是apache日志文件所说的:
[2011 年 3 月 23 日星期三 02:29:41] [错误] [客户端 129.21.129.32] ModSecurity:使用代码 500(第 4 阶段)拒绝访问。模式匹配 "(?:\b(?:(?:s(?:elect 列表,因为它不包含在 (?:an 聚合函数并且没有|聚合函数或) 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 出于某种原因阻止了脚本,但我不确定为什么。任何见解将不胜感激。
谢谢