automatic file-rename trigger on upload

Last post 05-30-2011, 2:54 PM by Cassiopeia. 2 replies.
Sort Posts: Previous Next
  •  05-30-2011, 1:07 PM 67731

    automatic file-rename trigger on upload

    Could you point me to the line of code to trigger an automatic rename if a file already exists upon upload?
     
    Currently:
    fileA.xxx exists on server, new upload of fileA.xxx overwrites original fileA.xxx
     
    What I'd like to see:
    fileA.xxx exists on server, new upload of fileA.xxx. User gets notified of duplicate filename and is requested to either OVERWRITE the original, RENAME the uploaded file to fileA-1.xxx or CANCEL the upload.
     
    or at the very least: 
    fileA.xxx exists on server, new upload of fileA.xxx gets renamed to fileA-1.xxx. User get's notified of the rename
    Filed under: ,
  •  05-30-2011, 2:49 PM 67733 in reply to 67731

    Re: automatic file-rename trigger on upload

    Dear Cassiopeia,
     
    Please open "\cuteeditor_files\Dialogs\upload_handler.php", you can find the following code in this file:
     
    foreach($guidlist as $fileguid)
     {
      
      //$contentType=$_FILES["file"]["type"];
      $mvcfile=$uploader->GetUploadedFile($fileguid);
      if(!$mvcfile)continue;
      
      $f_basename = $mvcfile->FileName;       
      $f_basename = preg_replace("/[^a-zA-Z0-9s.]/", "_", $f_basename);
      $savepath=$C_AbsolutePath . '' . $f_basename; 
      
      
      if(is_file($savepath))
      {
       unlink($savepath);
      }  
      $mvcfile->MoveTo($savepath);   
      chmod($savepath, 0644);  
      echo "The file ". $f_basename . " has been uploaded successfully! <br>";
      echo "File size: ". FormatSize( $filesize) .".";
      echo "<script language=javascript>parent.UploadSaved('" . $filepath . $f_basename . "','". $filepath ."');</script>"; 
     }
     
    You can update this code  and implement your requirement.
     
    Thanks for asking
  •  05-30-2011, 2:54 PM 67735 in reply to 67733

    Re: automatic file-rename trigger on upload

    thank you!
View as RSS news feed in XML