View Single Post
  #3 (permalink)  
Old 05-02-2008, 10:34 AM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Age: 26
Posts: 5,846
Last Blog:
Performance or Maintai...
Rep Power: 20
Jordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud of
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default Re: File download is corrupted

How large is the corrupted file compared to the others? Are you actually sending the correct size? What do you headers look like on the download script? They should look similar to this:

PHP Code:
          header("Pragma:  no-cache");
          
header("Expires: 0");
          
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
          
header("Cache-Control: public");
          
header("Content-Description: File Transfer");
          
header("Content-type: $mtype");
          
header("Content-Transfer-Encoding: binary"); 
          
header("Content-Disposition: attachment; filename=\"".basename($file)."\"");
            
            
          if (
ini_get('allow_url_fopen')) {
        if (
extension_loaded('curl')) {
                
header("Content-Length: " remotefsize($file));  
        }
     }
      
            
header("Accept-Ranges: bytes"); 
Next, why did you write your own function to "chunk" the data? You can use something as simple as:

PHP Code:
@readfile("$filename"); 
If all you ever intend on sending the user is zip/compressed files you can simply forward their browser to the file URL. IE:

PHP Code:
header("Location: " .$file); 
There is no reason to force a download for these type of files as the browser will do that anyway.

Here is some things you can do:
1) Download the file. Once complete open it with a text-editor and see if any text data is getting added to the beginning or ending of the file that shouldn't be there.

2) Does the file download when you link directly? If not, then it isn't your PHP script. You've corrupted the file somehow.

3) Try to use the php readfile function above and see if it is just your chunk function.

4) Make sure your headers are correct.

I hope this helps. You can download the community project "ionFiles" here on CodeCall. If you look at the download.php file you can see how our PHP file download script works.
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
Don't hesitate to ask any questions that you have! Check out our ASCII Calculator!
Reply With Quote