• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Showing file size

New Here ,
Apr 18, 2006 Apr 18, 2006

Copy link to clipboard

Copied

Hi, I have a large number of pdfs on the server. Pages with links to these pdfs are created dynamically according to different criteria (as you would expect). The list of pdfs are stored in a database.

I was hoping there was someway to retrieve the file sizes of these pdfs using coldfusion. The files are all stored on the same server as the website. I want to display the sizes next to the links.

Couldn't find a coldfusion function that returns this sort of information, any ideas?

thanks, John

Views

734

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 18, 2006 Apr 18, 2006

Copy link to clipboard

Copied

<cffile action="ReadBinary" file="C:\CFusionMX7\wwwroot\pdfDir\myPDF.pdf" variable="fileVar">
File size: <cfoutput>#DecimalFormat(Len(fileVar)/1024)#</cfoutput> KB <br>
File size: <cfoutput>#DecimalFormat(Len(fileVar)/(1024*1024))#</cfoutput> MB


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 18, 2006 Apr 18, 2006

Copy link to clipboard

Copied

Exactly what I wanted, thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 20, 2006 Apr 20, 2006

Copy link to clipboard

Copied

I got this working. Does anybody have any idea how much impact this has on the server?? All the literature I found says that it read the file - implying that it reads in the entire file. This would be a big impact on our server.

thanks again,

cakesy

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 20, 2006 Apr 20, 2006

Copy link to clipboard

Copied

Even it obviously works, the impact will be absolutely horrible. Your server will just read files. Nothing else. Why not use CFDIRECTORY that returns sizes? There are also third-party tags that return file size without reading the file. Or you could use Java, if you want.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 20, 2006 Apr 20, 2006

Copy link to clipboard

Copied

I got this working. Does anybody have any idea how much impact this has on the server?? All the literature I found says that it read the file - implying that it reads in the entire file. This would be a big impact on our server.
The suggesttion was just an instinctive reaction to your question, "Couldn't find a coldfusion function that returns this sort of information, any ideas?".

Oh, and, yes, cffile's read or readbinary will read the file, and it is, of course, less efficient than cfdirectory if you only want to get file size. However, the impact of cffile on the server is not as dramatically different from that of cfdirectory or Java as has been said here. It should be realized that, in some cases, it is the creation of objects that usually consumes the most resources, even if those objects do not read files. Don't take my word for it. Measure the execution times yourself.

In any case, you should not go empty-handed. As Mr Black has suggested, one could also do it with cfdirectory. I've done so below.



Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 20, 2006 Apr 20, 2006

Copy link to clipboard

Copied

Looks MUCH better to me. You even can use "*.pdf" filter to speed-up the process....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 20, 2006 Apr 20, 2006

Copy link to clipboard

Copied

LATEST
Looks MUCH better to me.
Looks can be deceiving. Apply the "*.pdf" filter, and any other speeders-up you can think of. Run the code, measuring the execution time. Do same with the cffile-readbinary above. Compare the times.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation