开发者

multiple upload's title not saved to database

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.


Try this:

$text=$_POST['text'][$j];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜