不适用于 For 循环的 move_uploaded_file

Raj*_*esh 0 php

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);
  } 
Run Code Online (Sandbox Code Playgroud)

请帮我。在上面的程序中,move_uploaded_file 在单次迭代中运行良好,我如何插入多个文件以存储在文件夹中(文件夹名称:附件)

Gaz*_*ler 5

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;
         }
     }
  } 
Run Code Online (Sandbox Code Playgroud)