Uploads - Same file name

Last post 04-07-2012, 6:45 AM by anthemia. 3 replies.
Sort Posts: Previous Next
  •  04-06-2012, 8:02 AM 73646

    Uploads - Same file name

    Hi,
    I have set the uploader up and is working fine for multiple uploads, but wanted to test what happens if on a future upload someone uploads a different file with the same name as a previous file.
     
    It seems like it just ignores the new file but gives no error message.  Is this the case, and how can I fix it?

    Thanks 
  •  04-06-2012, 8:04 AM 73647 in reply to 73646

    Re: Uploads - Same file name

    Actually it overwrites the previous file, but again, with no alert or fix
  •  04-06-2012, 8:29 AM 73651 in reply to 73647

    Re: Uploads - Same file name

    Hi anthemia,
     
    I suggest you use method "CopyTo" to save the upload files. It allow you handle the upload file store location and the new file name. Then you can check if the file exist or not. If exist, fire your own logic to handle it by the CopyTo method.
     
    The example below shows you how to use the CopyTo method to save 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.         Form - Start uploading manually  
    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. {  
    31. $guidlist=split("/",$fileguidlist);       
    32.     foreach($guidlist as $fileguid)      
    33.     {      
    34.           
    35.         //get the uploaded file based on GUID         
    36.         $mvcfile=$uploader->GetUploadedFile($fileguid);         
    37.         if($mvcfile)         
    38.         {         
    39.     <!-- check the file here, exist or not, then use the CopyTo to handle the new file name.$mvcfile->FileName  is the original file name-->  
    40.         $mvcfile->Copyto("D:/phpuploader/photos/".$mvcfile->FileName);   
    41.         }      
    42.     }      
    43.   
    44. }  
    45. ?>  
    46.                   
    47.     </div>  
    48. </body>  
    49. </html>  
    Regards,
     
    Ken 
  •  04-07-2012, 6:45 AM 73656 in reply to 73651

    Re: Uploads - Same file name

    Thanks for your help Ken, for each upload now have mkdir a new directory, then used rename to move the files 
View as RSS news feed in XML