我有一個php文件上傳多個文件,我想爲每個上傳的文件創建插入mysql行。例如,如果上傳3個文件:a.txt,b.txt和c.txt,它將創建3個插入查詢,其中$ filename是a.txt,第二個b.txt和第三個3.txt。這可能嗎?多個mysql查詢的多個文件上傳
$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')");
是的,這是可能的。但請注意,'mysql'擴展名已被棄用,並最終被刪除。改爲使用'mysqli'或'PDO'。 –