如何解决多个上传的标题未保存到数据库
| 抱歉,这些解决方案无法解决我的目的。因此,我提供了我的代码的更多细节,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;
}
在这里,我使用了递增标题。
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
}
这就是我所做的。请帮助我获取每个上传文件的标题。因为我能够在数据库中保存不同的图像,但是标题对于数据库中的所有人似乎都是相同的。
解决方法
尝试这个:
$text=$_POST[\'text\'][$j];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。