我有一个添加行函数来添加多个输入字段行,以便在表单中上传多个文件。这里我尝试在添加除输入字段的默认第一行之外的行时更改输入名称。但它也在改变第一行的名称。怎么解决?谢谢你的帮助 !! (我使用PHP Codeigniter和Mysql)。
//我的添加行功能
function addRow(tableID) {
/* here i used the Datatable in a form and i get the count of existing rows */
var table = document.getElementById(tableID);
var rowCount = table.rows.length; //this to get the count of row
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
/* Here I change the input names using id */
$("#uploadBtn").attr('name',"image"+rowCount+"[]");
for(var i=0; i<colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[0].cells[i].innerHTML;
switch(newcell.childNodes[0].type) {
case "text":
newcell.childNodes[0].value = "";
break;
case "checkbox":
newcell.childNodes[0].checked = false;
break;
case "select-one":
newcell.childNodes[0].selectedIndex = 0;
break;
}
}
}
//我的模型函数上传文件
function file_upload() {
foreach($val as $row) { //Here i getting different names of input fields in $row
if(!empty($_FILES[$row])){
log_message('debug',$row);
$valid_formats = array("jpg","jpeg", "png", "gif","bmp");
$max_file_size = 1024*1024*1024*1024; //500 kb
$path = "uploads/image/"; // Upload directory
$count = 0;
// Loop $_FILES to execute all files
foreach ($_FILES[$row]['name'] as $f => $name) {
if ($_FILES[$row]['error'][$f] == 4) {
continue; // Skip file if any error found
}
if ($_FILES[$row]['error'][$f] == 0) {
if ($_FILES[$row]['size'][$f] > $max_file_size) {
$message[] = "$name is too large!.";
continue; // Skip large files
}
elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
$message[] = "$name is not a valid format";
continue; // Skip invalid file formats
}
else{ // No error found! Move uploaded files
if(move_uploaded_file($_FILES[$row]["tmp_name"][$f], $path.$_FILES['name'])) {
$image_names[] ="prop".$prop_count."_".$prop_id."_img".$count;
}
$count++; // Number of successfully uploaded file
}
}
}
}
else{
$img="";
}
$img = implode(',',$image_names);
}
}
答案 0 :(得分:0)
尝试阅读本网站: http://www.ahowto.net/php/easily-integrateload-phpexcel-into-codeigniter-framework
它说,你可以为每次卖出设定价值。