2009-11-06 233 views
2

我正在使用uploadify with 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) 
} 

请指点

+0

我想你可以在文件上传完成后,在服务器端进行操作。你使用什么语言的服务器? – futureelite7 2009-11-06 06:41:37

+0

我正在使用ASP和服务器,我知道如何更改名称。现在的问题是,我如何将新名称发送到Uploadify脚本 – Chaofix 2009-11-06 06:45:12

回答

0

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

0

你可能想看看ScriptManager.RegisterClientScriptBlock()

将其放置在代码隐藏,并要求在重新命名服务器上的文件后的功能。这个调用客户端JavaScript(javascriptFunctionName),它将把新文件名传递给Uploadify。这里有一些C#:

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

希望这有助于一些。当您使用ScriptManager时,这与AJAX结合使用,一旦代码隐藏完成处理,它将通知您的Javascript函数。

0

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

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

我使用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 


      // } 
     }, 

我希望它会帮助你