/ Published in: PHP
Force download function that worked well, Thanks.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function force_download($filename = '', $data = false, $enable_partial = true, $speedlimit = 0) { if ($filename == '') { return FALSE; } return FALSE; // Try to determine if the filename includes a file extension. // We need it in order to set the MIME type { return FALSE; } // Grab the file extension // Load the mime types @include(APPPATH.'config/mimes'.EXT); // Set a default mime if we can't find it { $UserBrowser = "Opera"; $UserBrowser = "IE"; else $UserBrowser = ''; $mime = ($UserBrowser == 'IE' || $UserBrowser == 'Opera') ? 'application/octetstream' : 'application/octet-stream'; } else { } if($data === false) { $name = $info['basename']; } else { $name = $filename; } // Clean data in cache if exists // Check for partial download { if(!$lbyte) $lbyte = $size - 1; $new_length = $lbyte - $fbyte; } else { } // Common headers // Open file if($data === false) { if(!$file) return FALSE; } // Cut data for partial download if($data === false) else // Disable script time limit // Check for speed limit or file optimize if($speedlimit > 0 || $data === false) { if($data === false) { $chunksize = $speedlimit > 0 ? $speedlimit * 1024 : 512 * 1024; { echo $buffer; if($speedlimit > 0) } } else { $index = 0; $speedlimit *= 1024; //convert to kb { $left = $size - $index; $index += $buffersize; echo $buffer; } } } else { echo $data; } }
URL: http://codeigniter.com/forums/viewthread/71192/#351584