如何通过 html5(javascript) 和 php(codeigniter) 在 mysql 数据库中上传多个图像。
我该怎么办,php(codeigniter)?(我不能改变javascript代码,请给我例子)
html:
<form action="#" method="post" enctype="multipart/form-data">
<input name="name[]" type="file" id="fileElem" multiple accept="image/*" style="display:none" onchange="handleFiles(this.files)">
</form>
javascript如下:
function doClick() {
var el = document.getElementById("fileElem");
if (el) {
el.click();
}
}
function handleFiles(files) {
var d = document.getElementById("fileList");
if (!files.length) {
d.innerHTML = "<p>No files selected!</p>";
} else {
var list = document.createElement("ul");
d.appendChild(list);
for (var i=0; i < files.length; i++) {
var li = document.createElement("li");
list.appendChild(li);
var img = document.createElement("img");
img.src = window.URL.createObjectURL(files[i]);;
img.height = 60;
img.onload = function() {
window.URL.revokeObjectURL(this.src);
}
li.appendChild(img);
var info = document.createElement("span");
info.innerHTML = files[i].name + ": " + files[i].size + " bytes";
li.appendChild(info);
}
}
}
我试过:
//$config['upload_path'] = './uploads/';
//$config['allowed_types'] = 'gif|jpg|png';
//$this->upload->initialize($config);
//$this->load->library('upload');
for($i=0; $i<count($_FILES['name']); $i++){
if ($_FILES['error'][$i] == 0) {
$this->db->insert('table', $_FILES['name'][$i]); // this don't work
}
}