Upload problems. the upload of small files is normal. Upload files larger than MB. when the progress bar is greater than MB, the progress bar will not go away. where is the code?

Source: Internet
Author: User
The downloading problem is that the downloading of small files is normal. if the downloading of a file larger than MB is beyond MB, the progress bar will not go away. what is wrong with the code? At last, this post was edited by bxline from 2012-12-1706: 31: 43. I used the following code. I tried it twice and downloaded it to MB, one download to 129 download problem, small files can be downloaded normally, download files larger than MB, when the progress bar is outside MB, the progress bar will not go, where the code is wrong?
At the end of this post, I edited the following code by bxline at 06:31:43 on. I tried to download the code to 145M 5 m twice. once downloaded to 129M, I did not leave.
What's going on? The downloading of small files is normal, that is, files larger than MB are abnormal.
Below is the code: I am 03 + FASTCGI, not apache, so some lines in the code are commented out.

If (file_exists ($ filename )){
$ Mtime = ($ mtime = filemtime ($ filename ))? $ Mtime: gmtime ();
$ Size = intval (sprintf ("% u", filesize ($ filename )));
# If (intval ($ size + 1)> return_bytes (ini_get ('memory _ limit ') & intval ($ size * 1.5) <= 1073741824 ){
# Ini_set ('memory _ limit ', intval ($ size * 1.5 ));
#}
// @ Apache_setenv ('no-gzip ', 1 );
// @ Ini_set ('zlib. output_compression ', 0 );
Header ('content-Description: File Transfer ');
Header ('content-Type: application/force-download ');
Header ('content-Type: application/octet-stream ');
Header ('content-Disposition: attachment; filename = '. basename ($ filename ));
Header ('content-Transfer-Encoding: binary ');
Header ('expires: 0 ');
Header ('cache-Control: must-revalidate, post-check = 0, pre-check = 0 ');
Header ('pragma: public ');
Header ("Content-Length:". $ size );
Set_time_limit (300 );
$ Chunksize = 1*(1024*1024 );
// Ob_clean ();
// Flush ();
If ($ size> $ chunksize ){
$ Handle = fopen ($ filename, 'RB ');
$ Buffer = '';
While (! Feof ($ handle )){
$ Buffer = fread ($ handle, $ chunksize );
Echo $ buffer;
Ob_flush ();
Flush ();
}
Fclose ($ handle );
} Else {
Ob_flush ();
Flush ();
Readfile ($ filename );
}
Exit;
}
------ Solution --------------------
Echo 100*1024/300;
341 K/s
That is, the average bandwidth is more than 3 MB.

Your download code does not have the resumable Upload capability. Once a transmission error occurs, it can be terminated.
------ Solution --------------------
I should have written it.

Function down($file){
    IF(!$file Or !File_Exists($file) Or !Is_Readable($file)) {Return False;}

    IF($f = atr($file)) {
        Header("Content-Length:{$f['size']}");
        Header('Content-Description:File Transfer');
        Header('Content-Transfer-Encoding:binary');
        Header('Expires:0');
        Header('Cache-Control:must-revalidate');
        Header('Pragma:public');
 
        IF(Function_exists("mime_content_type")) {
            Header("Content-Type: ".mime_content_type($f['name']));
        }Else{
            Header("Content-Type: application/octet-stream");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.