1

On the page have a link to the file:

<a href="file.doc">File</a>

Next to the link should automatically show the extension and file size. Example: File (DOC, 15 KB)

How to do it?

I found this documentation:

How to have jQuery restrict file types on upload?

Find size of file behind download link with jQuery

but don't know how to unite them and show

UPD okay, how to know the file extension?

Community
  • 1
  • 1
TriSTaR
  • 405
  • 3
  • 19

2 Answers2

0

If you can determine that information ahead of time, you can use data attributes to tag the link and then display the extra content via CSS :after selector and content: attr(data-size), etc.

If you can't, I think the links would need to be absolute file system links and you could do an Ajax HEAD request on the path to grab the content-length header, do some basic math, and add the relevant information.

probablyup
  • 7,636
  • 1
  • 27
  • 40
0

HTML5 fie api supports to check the file size.

You may use the following code to check the file size as soon you upload the file.

HTML:

<input type="file" id="files" name="files[]" multiple />
<output id="list"></output>

JavaScript:

<script>
  function handleFileSelect(evt) {
    var files = evt.target.files; // FileList object

    // files is a FileList of File objects. List some properties.
    var output = [];
    for (var i = 0, f; f = files[i]; i++) {
      output.push('<li><strong>', escape(f.name), '</strong> (', f.type || 'n/a', ') - ',
                  f.size, ' bytes, last modified: ',
                  f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : 'n/a',
                  '</li>');
    }
    document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>';
  }

  document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>

Fiddle

Read More Here

shishir
  • 851
  • 3
  • 11
  • 27
  • Thanks, but i need this: something like this http://file.doc/ (file size and file extension?) – TriSTaR Sep 22 '16 at 06:05
  • Please look at the fiddle, you may change the display type in the javascript code . Currently it display the information like [tb.jpg (image/jpeg) - 21657 bytes,] – shishir Sep 22 '16 at 06:07
  • and you can show without downloading the file... let's say the link to the doc file, the script recognizes his size and extension – TriSTaR Sep 22 '16 at 06:12