-1
如何通過HTML5(JavaScript的)和PHP(笨)上傳mysql數據庫中的多個圖像。在mysql數據庫中上傳多張圖片由PHP
我做了什麼,PHP(笨)? (我不能改變的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
}
}
也許你應該嘗試使用'$ _FILES ['upimg']' – Musa
@ Musa - 這是我的錯誤。 –