Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Clearly, if your script is used to send your file as email attachment, it is true that your file should be under 10Mo because lots of mail servers will reject bigger emails.</p> <p>For security reasons, you cannot access informations about a file from the browser. But as soon as the file is selected in a file field of a form, you can use HTML5 file API. <a href="http://www.html5rocks.com/en/tutorials/file/dndfiles/" rel="nofollow">See this page for a complete presentation</a>.</p> <p>Here is the portion of code you would need to handle file size before submission :</p> <pre><code>&lt;input type="file" id="a_file" name="a_file" /&gt; &lt;script&gt; function fileSelect(evt) { var file = evt.target.files[0]; var size_mo = (file.size / (1024 * 1024)).toFixed(3); if (size_mo &gt;= 10) { alert('Your file is too big ('+size_mo+'Mo).'); // eventually reset the form with window.your_form.reset() to avoid submit } else { alert('Your file is ready for upload ('+size_mo+'Mo)'); } } document.getElementById('a_file').addEventListener('change', fileSelect, false); &lt;/script&gt; </code></pre> <p>However this solution will only support up-to-date browsers and is not compatible with versions of Internet Explorer lower than 10.</p> <p>There is no other solution using HTML or JS. If you want full support you will need Flash or Java (keep in mind that there are also computers with these technologies not installed). So the best you can do is use the HTML5 code with browser detection and do not alarm the user if you can't read the file size and have the good behavior if HTML5 is supported.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload