gpt4 book ai didi

php - 动态执行多个 $_FILES 时更改第一个输入字段名称

转载 作者:行者123 更新时间:2023-11-29 23:56:51 25 4
gpt4 key购买 nike

我有一个添加行函数来添加多个输入字段行,以便在表单中上传多个文件。在这里,我尝试更改输入名称,同时添加一行(输入字段的默认第一行除外)。但它也改变了第一行名称。怎么解决呢?感谢您的帮助 !! (我使用 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);
}
}

最佳答案

尝试阅读此网站: http://www.ahowto.net/php/easily-integrateload-phpexcel-into-codeigniter-framework

它说,您可以为每次销售设置值(value)。

关于php - 动态执行多个 $_FILES 时更改第一个输入字段名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25286113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com