2009-11-06 235 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 


      // } 
     }, 

我希望它會幫助你