Note that there are some explanatory texts on larger screens.

plurals
  1. POCan a server-side script have the browser assure full download?
    text
    copied!<p>I have a script on my server which generates contents which it sends to the users as files to download. The problem is that sometimes the contents can be a little long, and sometimes communications may die in the middle of the download... In such cases the download simply stops and the contents sent thus far is saved. This would not be so bad if the user could be notified the file has not fully downloaded so that they would try again. But usually nothing seems wrong on the user's side: the browser simply announces "download complete"! And then the user discovers there's been a problem and part of the file is missing only later when they actually try to open the file and work with it (which is much too late).</p> <p>So is there a way for a server-side script sending a file to be downloaded by a browser to have the browser show an error in case the download is not complete?</p> <p>By the way, in order to send the files I use these three HTTP headers:</p> <pre><code>Content-Type: application/octet-stream Content-Disposition: attachment; filename="MyFile.ext" Content-Length: &lt;no. of bytes&gt; </code></pre> <p>I can actually tell the length of the contents in advance, and the browser actually displays this number to the user when it notifies them about the download. But then the browser doesn't say anything when the download finishes before the correct number of bytes has been downloaded, and I cannot expect my users to check the exact size of the file they've downloaded and compare it with what the browser had announced before.</p> <p>Is there perhaps a browser configuration that would make the browser announce an error in such cases? Or is there another HTTP header I can send (perhaps with some checksum or CRC or something) that would have the desired effect?</p> <p>Any help would be much appreciated!</p> <p><strong>Edit:</strong> here is a simple PHP code to test browsers' behaviour on too small downloads:</p> <pre><code>&lt;?php header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="test.txt"'); header('Content-Length: 300'); echo 'Will there be a warning?'; </code></pre> <p>This code sends a file named <code>test.txt</code> and allegedly 300-byte long to the browser for download. In fact the content is much smaller. The browser waits for more content for a bit, then gives up and announces "download complete", without any warning.</p>
 

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