douningle7944 2011-06-15 17:46
浏览 44
已采纳

多个上传的标题未保存到数据库

I am sorry but these solutions din't solved my purpose. So m giving more detail of my code,

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;

    }

here i have used a 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
}

this is what i have done. Please help me to get title for each uploaded file. as i am able to save different images in database but title appears to be same for all in database.

  • 写回答

1条回答 默认 最新

  • dongmen1860 2011-06-15 17:55
    关注

    Try this:

    $text=$_POST['text'][$j];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)