當使用Coldfusion存儲文件(可以是.txt,.doc,.docx)時,我希望能夠檢索這些文件。我一直在搜索Google,但似乎無法找到答案。Coldfusion下載文件
基本上:我如何檢索一個blob(SQL Server 2008中的varbinary(MAX)),它可以是多種類型的文件擴展名,然後提供下載?
這裏是我的上傳/下載代碼,它的下載已經難倒我:
<!--- <form action="resume.cfm" method="post" enctype="multipart/form-data">
Select File: <input type="file" name="upload" />
<input type="submit" value="Upload File" />
</form>
<cfif structKeyExists(form, "upload")>
<cfquery datasource="#application.dsn.recAppTest#" name="resume">
INSERT INTO resume (resume)
VALUES(
<cfqueryparam cfsqltype="cf_sql_blob" value="#FileReadBinary(FORM.upload)#">
)
</cfquery>
</cfif> --->
<cfoutput>
<cfquery datasource="#application.dsn.recAppTest#" name="resume">
SELECT * FROM resume
</cfquery>
<cfdump var="#resume#" />
</cfoutput>
<cfheader name="Content-Disposition" value="attachment; filename=""> <!--- what goes here if I don't know the incoming extension?? --->
<cfcontent type="text/plain, application/vnd.openxmlformats-officedocument.wordprocessingml.document" />
我甚至不知道這是可能的(我希望是),但如果沒有,一會解決方法是(在上傳時)抓取文件擴展名,然後將其轉換爲數字(varbinary)並將其存儲爲單獨的字段?
你必須存儲文件名稱,擴展名和上傳文件時的類型。你可以使用'CFFILE'來獲取這些信息。否則,你將不得不猜測:http://www.bennadel.com/blog/2490-Detecting-File-Type-Using-Magic-Numbers-In-ColdFusion.htm – imthepitts