php
2010-11-10 42 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

相关问题