简体   繁体   English

在coldfusion中,如何找到链接文件的文件大小并将其用作alt属性

[英]In coldfusion how can I find the filesize of a linked file and use that as an alt attribute

I have a large list with icons linking to pdf and msword files. 我有一个大型列表,其中包含链接到pdf和msword文件的图标。 I'd like to get the filesize in kb of the linked file then use that as the alt attribute on the image. 我想在链接文件的kb中获取文件大小,然后将其用作图像上的alt属性。 The generated code would look something like this. 生成的代码看起来像这样。

Description of file <a href="file1.pdf"><img src="pdficon.gif" alt="27.6 kb" /></a> 
<a href="file1.doc"><img src="wordicon.gif" alt="33.2 kb" /></a>

All the links to the files are static href's as not all the files in the directory are used in this list. 文件的所有链接都是静态href,因为目录中的所有文件都不在此列表中使用。 How would I go about doing in coldfusion? 我怎么去做冷敷? Would I have to get all the files using cfdirectory and then match them up with the href's? 我是否必须使用cfdirectory获取所有文件,然后将它们与href匹配? Or is there a way to just parse the parent href and grab the filesize? 或者有没有办法解析父href并获取文件大小?

Thanks! 谢谢!

Time to use Java 是时候使用Java了

<cfset file = createObject("java","java.io.File").init("/directoy/filename")>
<cfset fileSizeInKB = file.length() / 1024>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM