我很抱歉,但这些解决方案并没有解决我的目的。所以我提供了更详细的代码,
var a=0;
function _add_more() {
var txt = "<br><input type=\"file\" name=\"item_file[]\"><br><input type=\"text\" name=\"text[]\">";
document.getElementById("dvFile").innerHTML += txt;
alert(a);
a=a+1;
}
在这里,我使用了一个to increement title。
function upload(){
if(count($_FILES["item_file"]['name'])>0) { //check if any file uploaded
$GLOBALS['msg'] = ""; //initiate the global message
for($j=0; $j < count($_FILES["item_file"]['name']); $j++) { //loop the uploaded file array
$filen = $_FILES["item_file"]['name']["$j"]; //file name
$path = 'uploads/'.$filen; //generate the destination path
$text=$_POST['text']['name']["$j"] + "<br>";
if(move_uploaded_file($_FILES["item_file"]['tmp_name']["$j"],$path)) {
$insert=mysql_query("insert into image_upload set title='".$text."', image='".$filen."'") or die(mysql_error());
//upload the file
$GLOBALS['msg'] .= "File# ".($j+1)." ($filen) uploaded successfully<br>"; //Success message
}
}
}
else {
$GLOBALS['msg'] = "No files found to upload"; //Failed message
}
uploadForm(); //display the main form
}
这就是我所做的。请帮我获取每个上传文件的标题。因为我能够在数据库中保存不同的图像,但标题对于数据库中的所有人来说都是相同的。
答案 0 :(得分:2)
试试这个:
$text=$_POST['text'][$j];