Support forums
in

how to deal with duplicate file name

Last post 05-30-2011, 9:03 PM by Kenneth. 4 replies.
Sort Posts: Previous Next
  •  05-28-2011, 3:52 PM 67708

    how to deal with duplicate file name

    Dear sir
     
    I have a question
     
    I just found that image upload to the server with their original name .
     
    what if there are two people upload the image with the same file name ,but in the difference time ?
     
    for example
     
    Jason just upload the image named " iphone.jpg"
     
    few days later , Kevin wants to upload the image also named "iphone.jpg"
     
    can we let all upload file with the unique file name ? 
  •  05-29-2011, 9:17 PM 67715 in reply to 67708

    Re: how to deal with duplicate file name

    Hi acyk,
     
    You can custom the file name by method MoveTo, like below.
     
    In this example, I add the time belore the file name.
     
    <?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>
        example
        </title>
    </head>
    <body>
     
                <form id="form1" method="POST">
                    <?php                
                        $uploader=new PhpUploader();
                        $uploader->MaxSizeKB=10240;
                        $uploader->Name="myuploader";
                        $uploader->InsertText="Select multiple files (Max 10M)";
                        $uploader->AllowedFileExtensions="*.jpg,*.png,*.gif,*.txt,*.zip,*.rar";    
                        $uploader->MultipleFilesUpload=true;
                        $uploader->Render();
                ?>
                </form>
    <?php
    $fileguidlist=@$_POST["myuploader"];
    if($fileguidlist)
    {
    $guidlist=split("/",$fileguidlist);     
        foreach($guidlist as $fileguid)    
        {    
            
            //get the uploaded file based on GUID       
            $mvcfile=$uploader->GetUploadedFile($fileguid);       
            if($mvcfile)       
            {       
            $mvcfile->MoveTo("D:/2005/phpuploader/test/".date("H.i.s").$mvcfile->FileName);
            }    
        }    

    }
    ?>
        </div>
    </body>
    </html>
     
    Regards,
     
    ken
     
  •  05-29-2011, 11:11 PM 67719 in reply to 67715

    Re: how to deal with duplicate file name

    great idea !
     
    thanks for your help 
     
    let me try  
  •  05-30-2011, 11:38 AM 67728 in reply to 67715

    Re: how to deal with duplicate file name

    1.  <form id="form1" method="POST">  
    2.                 MaxSizeKB=10240;  
    3.                     $uploader->Name="myuploader";  
    4.                     $uploader->InsertText="Select multiple files (Max 10M)";  
    5.                     $uploader->AllowedFileExtensions="*.jpg,*.png,*.gif,*.txt,*.zip,*.rar";      
    6.                     $uploader->MultipleFilesUpload=true;  
    7.                     $uploader->Render();  
    8.                 ?>  
    9.               
    10.             </form>  
    11.   
    12.   
    13.   
    14.   
    15. GetUploadedFile($fileguid);         
    16.         if($mvcfile)         
    17.         {         
    18.         $mvcfile->MoveTo("/home/ftp/iphone4tw/attach/test/uploads/iPhone4TW-".date("H-i-s")."_".$mvcfile->FileName);   
    19.         }      
    20.     }      
    21.   
    22. }  
    23. ?>  
    24.   
    25. <script type="text/javascript">  
    26.     function CuteWebUI_AjaxUploader_OnTaskComplete(task)  
    27.     {  
    28.         var div=document.createElement("DIV");  
    29.         div.innerHTML=" [ img]http://attach.iphone4.tw/test/uploads/" + task.FileName + "[/img]<br>";  
    30.         document.body.appendChild(div);  
    31.     }  
    32.     </script>    
    I have problem to show the final file name here , and file lsit suddenly gone  forever
     
    here is my test page , pls advise , thanks
     
     
     
     
  •  05-30-2011, 9:03 PM 67739 in reply to 67728

    Re: how to deal with duplicate file name

    Hi acyk,
     
    Two ways.
     
    1. Remove the <form> tag.
     
    2. Use the example below
     
    <?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>
            Ajax - Multiple files upload
        </title>
        <script type="text/javascript">
            var handlerurl='ajax-multiplefiles-handler.php'
        </script>
        <script type="text/javascript">
        function CuteWebUI_AjaxUploader_OnPostback()
        {
            var uploader = document.getElementById("myuploader");
            var guidlist = uploader.value;

            //Send Request
            var xh;
            if (window.XMLHttpRequest)
                xh = new window.XMLHttpRequest();
            else
                xh = new ActiveXObject("Microsoft.XMLHTTP");
            
            xh.open("POST", handlerurl, false, null, null);
            xh.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
            xh.send("guidlist=" + guidlist);

            //call uploader to clear the client state
            uploader.reset();

            if (xh.status != 200)
            {
                alert("http error " + xh.status);
                setTimeout(function() { document.write(xh.responseText); }, 10);
                return;
            }

            var filelist = document.getElementById("filelist");
            filelist.style.listStyleType="none";
            var list = eval(xh.responseText); //get JSON objects
            //Process Result:
            for (var i = 0; i < list.length; i++)
            {
                var item = list[i];
                
                var msg = "";
                var li = document.createElement("li");
                li.innerHTML = msg;
                filelist.appendChild(li);
            }
        }
        </script>

    </head>
    <body>
    <form id="form1" >  
        <div class="demo">                        
                        <?php
                    $uploader=new PhpUploader();
                    $uploader->MaxSizeKB=10240;
                    $uploader->Name="myuploader";
                    $uploader->MultipleFilesUpload=true;
                    $uploader->InsertText="Select multiple files (Max 10M)";
                    $uploader->AllowedFileExtensions="*.jpg,*.png,*.gif,*.bmp,*.txt,*.zip,*.rar";    
                    $uploader->Render();
                ?>
                        
                <ol id="filelist">
                </ol>        
        </div>
        </form>
    </body>
    </html>
     
     
    Regards,
     
    Ken
View as RSS news feed in XML
Powered by Community Server (Commercial Edition), by Telligent Systems