Re: File name append when already present

  •  11-19-2012, 6:03 AM

    Re: File name append when already present

    Hi mtimmons,

     

    I suggest you use method "CopyTo" to handle the upload file store location and the file name, then before you save the upload file, you can check the file name first and save it as a new name if exists.

     

    Below is the example which shows you how to use method "CopyTo" to handle the upload file.

     

    1. <?php require_once "phpuploader/include_phpuploader.php" ?> 
    2. <?php session_start(); ?> 
    3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
    4. <html xmlns="http://www.w3.org/1999/xhtml"
    5.     <head> 
    6.         <title> 
    7.             example 
    8.         </title> 
    9.     </head> 
    10.     <body> 
    11.  
    12.         <form id="form1" method="POST"
    13.             <?php                 
    14.                     $uploader=new PhpUploader(); 
    15.                     $uploader->MaxSizeKB=10240; 
    16.                     $uploader->Name="myuploader"
    17.                     $uploader->InsertText="Select multiple files (Max 10M)"
    18.                     $uploader->AllowedFileExtensions="*.jpg,*.png,*.gif,*.txt,*.zip,*.rar";   
    19.                     $uploader->MultipleFilesUpload=true; 
    20.                     $uploader->Render(); 
    21.  
    22.             ?> 
    23.  
    24.         </form> 
    25.  
    26.  
    27.         <?php 
    28. $fileguidlist=@$_POST["myuploader"]; 
    29. if($fileguidlist
    30. $guidlist=explode("/",$fileguidlist);    
    31.     foreach($guidlist as $fileguid)     
    32.     {     
    33.          
    34.         //get the uploaded file based on GUID        
    35.         $mvcfile=$uploader->GetUploadedFile($fileguid);        
    36.         if($mvcfile)        
    37.         {        
    38.         $mvcfile->CopyTo("D:/sites/phpuploader/test/".$mvcfile->FileName);  
    39.         }     
    40.     }     
    41.  
    42. ?> 
    43.  
    44.         </div> 
    45.     </body> 
    46. </html> 
     

    Regards,

     

    Ken

View Complete Thread