我正在尝试上传多张图片。
我的表格是:
<form>
<input type="file" name="images[]">
<input type="file" name="images[]">
<input type="file" name="images[]">
</form>
我知道这种形式是正确的。 Codeigniter尝试上传文件时收到错误。
function do_upload_images() {
$files = $_FILES;
$cpt = count ( $_FILES ['images'] ['name'] );
for($i = 0; $i < $cpt; $i ++) {
$_FILES ['images'] ['name'] = $files ['images'] ['name'] [$i];
$_FILES ['images'] ['type'] = $files ['images'] ['type'] [$i];
$_FILES ['images'] ['tmp_name'] = $files ['images'] ['tmp_name'] [$i];
$_FILES ['images'] ['error'] = $files ['images'] ['error'] [$i];
$_FILES ['images'] ['size'] = $files ['images'] ['size'] [$i];
$this->upload->initialize ( $this->set_upload_options () );
$this->upload->do_upload ($_FILES['images']);
}
}
private function set_upload_options() {
// upload an image options
$config = array ();
$config ['upload_path'] = './uploads/estate_images';
$config ['allowed_types'] = 'gif|jpg|png';
$config ['encrypt_name'] = TRUE;
return $config;
}
这是我得到的错误:
消息:isset或空文件名中的非法偏移类型: libraries / Upload.php行号:377
答案 0 :(得分:4)
我自己得到解决方案。只需要更改以下行:
$this->upload->do_upload ($_FILES['images']);
到
$this->upload->do_upload ('images');