【问题标题】:Rename file with uploadify使用 uploadify 重命名文件
【发布时间】:2010-12-13 17:39:43
【问题描述】:

我正在使用asp的uploadify,我想在文件完成时将文件名更改为当前日期+时间。

有什么办法吗?

这是我的 JS 代码:

$('#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)
}

请指教

【问题讨论】:

  • 我认为您可以在文件上传后在服务器端进行。服务器使用什么语言?
  • 我正在使用 ASP 并且在服务器上我知道如何更改名称。现在的问题是,我如何将新名称发送到 Uploadify 脚本

标签: asp-classic uploadify http-upload


【解决方案1】:

我正在使用uploadify 直接从浏览器上传到S3。我很想知道有一种方法可以告诉 S3 将传入文件命名为不同于用户本地计算机上的名称。

【讨论】:

    【解决方案2】:

    您可能需要查看 ScriptManager.RegisterClientScriptBlock()

    将它放在代码隐藏中,并在您重命名服务器上的文件后调用该函数。这将调用客户端 JavaScript (javascriptFunctionName) 将新文件名传递给 Uploadify。这是一些 C#:

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

    希望这会有所帮助。这在您使用 ScriptManager 时与 AJAX 结合使用,并且会在代码隐藏完成处理后通知您的 Javascript 函数。

    【讨论】:

      【解决方案3】:

      您需要在服务器脚本中进行文件操作。这是一个例子:

      ''// 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
      

      【讨论】:

        【解决方案4】:

        我正在使用uploadify,我已经改变了我的文件名,如下所示,检查我的OnComplete函数

        '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
        
        
                    // }
                },
        

        希望对你有帮助

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-07-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-05-29
          • 1970-01-01
          • 1970-01-01
          • 2012-06-20
          相关资源
          最近更新 更多