File rename

Last post 07-12-2010, 12:12 PM by Eric. 1 replies.
Sort Posts: Previous Next
  •  07-12-2010, 4:35 AM 62420

    File rename

    Hi,
     
    I would like to add a code to the name of the uploaded file.
    Ho can i do this ? 
     
    Peter  
    Filed under:
  •  07-12-2010, 12:12 PM 62434 in reply to 62420

    Re: File rename

    Please try the following code:
     
    demo2.php:
    <?php require_once "phpuploader/include_phpuploader.php" ?>
    <?php session_start(); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
     <title>Demo 2 - use UploadUrl property</title>
    </head>
    <body>
     <?php
      $uploader=new PhpUploader();
      $uploader->MultipleFilesUpload=true;
      $uploader->InsertText="Select multiple files (Max 10M)";  
      $uploader->MaxSizeKB=10240;
      $uploader->AllowedFileExtensions="*.jpg,*.png,*.gif,*.bmp";  
      $uploader->UploadUrl="demo2_upload.php";  
      $uploader->Render();
     ?> 
     <script type='text/javascript'>
     function CuteWebUI_AjaxUploader_OnTaskComplete(task)
     {
      var div=document.createElement("DIV");
      var link=document.createElement("A");
      link.setAttribute("href","savefiles/myprefix_"+task.FileName);
      link.innerHTML="You have uploaded file : savefiles/myprefix_"+task.FileName;
      link.target="_blank";
      div.appendChild(link);
      document.body.appendChild(div);
     }
     </script> 
    </body> 
    </html>
    demo2_upload.php:
    <?php require_once "phpuploader/include_phpuploader.php" ?>
    <?php
    $uploader=new PhpUploader();

    $mvcfile=$uploader->GetValidatingFile();

    if($mvcfile->FileName=="1a1.gif")
    {
     $uploader->WriteValidationError("My custom error : Invalid file name. ");
     exit(200);
    }//USER CODE:
    $targetfilepath= "savefiles/newfilenameprefix" . $mvcfile->FileName;
    if( is_file ($targetfilepath) )
     unlink($targetfilepath);
    $mvcfile->MoveTo( $targetfilepath );
    $uploader->WriteValidationOK();
    ?>
    Regards,
    Eric
View as RSS news feed in XML