开发者

Rename file with uploadify

I'm using uploadify with asp and I want to change the file name to the current date+time when the file is complete.

Is there any way to do it?

this is my JS code:

$('#fileUploadJquery').uploadify({
'uploader'      :   'Shared/ClientScripts/Uploadify/uploadify.swf',
'cancelImg'     :   'Shared/ClientScripts/Uploadify/cancel.png',
'rollover'      :   false,
'script'        :   'Shared/ClientScripts/Uploadify/upload.asp',
'folder'        :   'Uploads',
'fileDesc'      :   'Image Files',
'fileExt'       :   '*.jpg;*.gif;*.bmp;*.png',
'auto'          :   true,
'wmode'         :   'transparent',
onComplete    开发者_如何学JAVA  :   function (event, queueID, fileObj, response, data) {
    //$('#fileUpload').val(fileObj.name);
    alert(queueID)
}

Please advice


I'm using uploadify to upload directly from the browser to S3. I'd love to find out there's a way to tell S3 to name the incoming file something other than the name on the user's local computer.


You may want to look into ScriptManager.RegisterClientScriptBlock()

Place it on the codebehind, and calls the function after you rename the file on the server. This call client-side JavaScript (javascriptFunctionName) that will deliver the new filename to Uploadify. Here's some C#:

    public void YourFunction(string fileName)
    {
      ScriptManager.RegisterClientScriptBlock(
        ctrlName,
        ctrlName.GetType(),
        "scriptkey",
        @"javascriptFunctionName('" + fileName + @"');",
        true);
    }    

Hope this helps some. This is used in conjunction with AJAX when you're using ScriptManager, and will notify your Javascript function once the codebehind finishes processing.


You need to do the file manipulation in the server script. Here's an example:

''// I'm using this component, but any component must work
dim theForm
set theForm = Server.CreateObject("ABCUpload4.XForm")

theForm.Overwrite = True
theForm.MaxUploadSize = 1000000


''// FileData is the name Uploadify gives the post value containing the file
dim theField
set theField = theForm("FileData")(1)


If theField.FileExists Then

   ''// Renamed the file adding a "random" string in front of the name
   dim FileName
   FileName =  replace(trim(cdbl(now())), ".", "_") + "_" + theField.FileName

   theForm.AbsolutePath = True
   theField.Save Server.MapPath("../uploadedfiles") & "/" + FileName

   ''// Some browser need this
   Response.write "<html><head><title>File uploaded</title></head><body>File uploaded</body></html>"


End If


I am using uploadify and i've changed my filename like below, check my OnComplete function

'onComplete': function (a, b, c, d, e) {          
            var dt = new Date();                
                var file = c.name.split('.')[0] + "_" + dt.getUTCDate() + dt.getFullYear() + "." + c.name.split('.')[1];

            $("#hdntxtbxFile").val(file);
            UploadSuccess(file, "File"); //function call


            // }
        },

I hope it will help you

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜