user1559811
user1559811

Reputation: 449

multiple mysql query's for multiple file uploads

I have a multiple file upload with php and I want to create insert a mysql row for each file uploaded. so for example if 3 files were uploaded: a.txt, b.txt and c.txt, it would create 3 insert querys one where $filename was a.txt the second b.txt and the third 3.txt. is this possible?

$target = "test/";

    if($target[strlen($target)-1]!='/')
            $target=$target.'/';
        $count=0;
        foreach ($_FILES['uploaded']['name'] as $filename)
        {
            $temp=$target;
            $tmp=$_FILES['uploaded']['tmp_name'][$count];
            $count=$count + 1;
            $temp=$temp.basename($filename);
            move_uploaded_file($tmp,$temp);
            $temp='';
            $tmp='';
        }

//for each file uploaded    mysql_query("INSERT INTO files VALUES('','$date','$filename')");

Upvotes: 0

Views: 205

Answers (2)

Spin0us
Spin0us

Reputation: 353

For sure it's possible. Just add your mysql_query at the end of your foreach block.

Upvotes: 0

Damien Overeem
Damien Overeem

Reputation: 4529

Yes it is.

And since you are looping the uploaded files already. I would do the sql query in that same loop.

And: POINTS AT THE BIG RED BOX AT http://php.net/manual/en/function.mysql-query.php

Upvotes: 2

Related Questions