for($i=0;$i<count($sentto1);$i++)
{
$sel="insert into newmessage set sendto='".$sentto1[$i]."',
sendfrom='".$almemailid."',
subject='".$subject."',
message='".$color."',
attac='".$fileatt_name."',
updateddate = now()";
$selqur=mysql_query($sel) or die("Error (" . mysql_errno() .")" . mysql_error());
$lastid_id = mysql_insert_id();
$folderpath = "Attachment/".$lastid_id."".$fileatt_name;
move_uploaded_file($_FILES["attachcopy"]["tmp_name"],$folderpath);
}
请帮帮我。 在上面的程序中,move_uploaded_file在单次迭代中运行良好, 我如何插入多个文件存储在文件夹中(文件夹名称:附件)
答案 0 :(得分:4)
move_uploaded_file删除原始文件,因此它在第二次迭代时不存在,在第一次迭代后使用copy会起作用。
$uploaded = false;
for($i=0;$i<count($sentto1);$i++)
{
$sel="insert into newmessage set sendto='".$sentto1[$i]."',
sendfrom='".$almemailid."',
subject='".$subject."',
message='".$color."',
attac='".$fileatt_name."',
updateddate = now()";
$selqur=mysql_query($sel) or die("Error (" . mysql_errno() .")" . mysql_error());
$lastid_id = mysql_insert_id();
$folderpath = "Attachment/".$lastid_id."".$fileatt_name;
if ($uploaded)
{
copy($uploaded, $folderpath);
}
else
{
if (move_uploaded_file($_FILES["attachcopy"]["tmp_name"],$folderpath))
{
$uploaded = $folderpath;
}
}
}