0

I am trying to add pdf file size after download link as in here http://jsfiddle.net/bf4ovzg0/

I have gone through few other stackoverflow solutions. HOwever, I have been unable to get this working.

var byteSize  = $("#url")[0].size;
$( "#url" ).after( byteSize);
//alert (byteSize);


<a href="/media/cache/pdf_to_jpg/article-from-the-journal-of-the-american-medical-women-s-association-on-dr-lucy-gullett-38712.pdf" target="_new" id="url">Download the pdf documents </a>

Any idea how to fix this .. if so, can someone help me out at jsFiddle?

I think I can get a PHP backend version working like below

<?php

$head = array_change_key_case(get_headers("http://ec2-54-253-250-162.ap-southeast-2.compute.amazonaws.com/media/cache/pdf_to_jpg/article-from-the-journal-of-the-american-medical-women-s-association-on-dr-lucy-gullett-38712.pdf", TRUE));
$filesize = $head['content-length']/1000000;
echo $filesize;
echo "MB";

?>

However, I am interested in a jQuery front end version if possible?

Hello Universe
  • 3,248
  • 7
  • 50
  • 86

1 Answers1

2

I believe a better solution for this is to get the file size from the server and display it. The only way to do this with jQuery is to perform an ajax query of the file and display it size, but I think it is a bad idea. Please check out this question as well Find size of file behind download link with jQuery

Community
  • 1
  • 1
Timur Osadchiy
  • 5,699
  • 2
  • 26
  • 28