archive files are corrubted if i download it with header()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
trazan
Forum Newbie
Posts: 15
Joined: Fri Nov 13, 2009 8:41 pm

archive files are corrubted if i download it with header()

Post by trazan »

i use this code to download files but i found the archive files corrubted
i download it directly and it was good and this in the localhost and in my Site do you know how can i solve it

Code: Select all

 
        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Cache-control: public");
        header("Content-Description: File Transfer");
                header('HTTP/1.1 206 Partial Content');
        header('Accept-Ranges: bytes');
        header("Content-Transfer-Encoding: binary");
                header("Content-length: ".filesize($filename));
        header('Content-type: application/zip'); 
        header("Content-Disposition: attachment; filename=\"" . basename($filename) . "\"");
trazan
Forum Newbie
Posts: 15
Joined: Fri Nov 13, 2009 8:41 pm

Re: archive files are corrubted if i download it with header()

Post by trazan »

any help!!!!!!!!!
trazan
Forum Newbie
Posts: 15
Joined: Fri Nov 13, 2009 8:41 pm

Re: archive files are corrubted if i download it with header()

Post by trazan »

:offtopic: :offtopic: :offtopic:
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: archive files are corrubted if i download it with header()

Post by requinix »

Where's the code that outputs the file?
trazan
Forum Newbie
Posts: 15
Joined: Fri Nov 13, 2009 8:41 pm

Re: archive files are corrubted if i download it with header()

Post by trazan »

that is the code as u see i use this code to limtied the speed of download and i put it after the header function

Code: Select all

$file = fopen($filename, "r");    
    while(!feof($file)) {
 
        // send the current file part to the browser
        print fread($file, round($download_rate * 1024));    
 
        // flush the content to the browser
        flush();
 
        // sleep one second
        sleep(1);    
    }    
 
    // close file stream
    fclose($file);
}
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: archive files are corrubted if i download it with header()

Post by requinix »

For compatibility with Windows use

Code: Select all

$file = fopen($filename, "rb");
How does the size of the downloaded file compare with the original file?
trazan
Forum Newbie
Posts: 15
Joined: Fri Nov 13, 2009 8:41 pm

Re: archive files are corrubted if i download it with header()

Post by trazan »

For compatibility with Windows use
I Am Linux User
____
How does the size of the downloaded file compare with the original file?

ohh i just notic that when i puse the download and resume it again the download wil start the download for the file from the begining but he will write on the same file on the pc
exapmle : if i download file.zip ( 10 M.B ) and pused the download in 50% and resumed it again i will found the final file size 15 M.B
now you have the code , does any one knoe what i can do for that
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: archive files are corrubted if i download it with header()

Post by requinix »

trazan wrote:I Am Linux User
That's nice, but make the change anyways. It's called "planning ahead".


You've only gone halfway between a regular download script and one that lets you pause and resume. Halfway means you get some of one and some of the other - and that means you don't have a fully functional script.

For a regular download comment out the HTTP/1.1 206 and the Accept-Ranges headers.
For a resumeable download you'll need more work. Work that's outside the scope of this thread right now.
trazan wrote:ohh i just notic that when i puse the download and resume it again the download wil start the download for the file from the begining but he will write on the same file on the pc
exapmle : if i download file.zip ( 10 M.B ) and pused the download in 50% and resumed it again i will found the final file size 15 M.B
Given the code you have, that's absolutely correct behavior.

Without pausing the download, what is the size of the file you get and what is the size of the original file? Are they the same or are they different?
trazan
Forum Newbie
Posts: 15
Joined: Fri Nov 13, 2009 8:41 pm

Re: archive files are corrubted if i download it with header()

Post by trazan »

Given the code you have, that's absolutely correct behavior.

Without pausing the download, what is the size of the file you get and what is the size of the original file? Are they the same or are they different?
Without pausing the download the file size is correct and it is not corrubted
:banghead: :banghead:
Post Reply