php
2010-11-10 41 views 0 likes 
0
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在單次循環運作良好, 我怎麼插入多個文件中的文件夾來存儲(文件夾名稱:附件)For循環中不工作move_uploaded_file

回答

4

move_uploaded_file刪除原始文件,因此它不會在第二次迭代存在,則使用第一次迭代後複製將工作。

$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; 
     } 
    } 
    } 
+0

上午拉傑什感謝宥答覆,在你的代碼中添加多個文件工作以及 – Rajesh 2010-11-11 04:45:18

+0

我的頁面創建一個文件夾來保存在其中可以刪除上傳的文件。 但是,一旦上傳的文件被傳輸到這個文件夾,即使他們在我的電腦上,我也不能刪除上傳文件或文件夾。 – Rajesh 2010-11-11 05:23:00

+0

嗨,我的頁面創建一個文件夾來保存可以刪除的上傳文件。 但是,一旦上傳的文件被轉移到這個文件夾,我無法刪除上傳文件。 PLZ回覆我的任何PHP代碼。 – Rajesh 2010-11-11 05:25:32

相關問題