2

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      :   function (event, queueID, fileObj, response, data) {
    //$('#fileUpload').val(fileObj.name);
    alert(queueID)
}

Please advice

Eduardo Molteni
  • 38,786
  • 23
  • 141
  • 206
Chaofix
  • 61
  • 1
  • 2
  • 7
  • I think you can just do it server side, after the file has been uploaded. What language do you use for the server? – futureelite7 Nov 06 '09 at 06:41
  • I'm using ASP and at the server I know how to change the name. now the question is, how I send the new name to the Uploadify script – Chaofix Nov 06 '09 at 06:45

4 Answers4

0

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

Syed Salman Raza Zaidi
  • 2,172
  • 9
  • 42
  • 87
0

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.

0

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.

Dan
  • 1,729
  • 1
  • 18
  • 25
0

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
Eduardo Molteni
  • 38,786
  • 23
  • 141
  • 206