Imao sam sličan problem pre nekih 6 meseci. Sad sam već zaboravio u čemu je tačno kvaka, ali evo nađoh funkciju koju sam tada napisao:
PHP kôd:
/**
* Force download of specific file
*
* @access public
* @param string $path File path
* @param string $type Serve file as this type
* @return void
*/
function download_file($path, $type = 'application/octet-stream', $name = '', $force_download = false) {
// Check file...
if (!is_file($path) || connection_status()!=0) return false;
// headers...
if($force_download) {
header("Cache-Control: public");
//session_cache_limiter("must-revalidate");
} else {
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
} // if
header("Expires: ".gmdate("D, d M Y H:i:s", mktime(date("H")+2, date("i"), date("s"), date("m"), date("d"), date("Y")))." GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Content-Type: $type");
header("Content-Length: ".(string)(filesize($path)));
// Prepare disposition
$disposition = $force_download ? 'attachment' : 'inline';
// Name...
if(trim($name) == '') {
header("Content-Disposition: $disposition; filename=\"" . basename($path)) . "\"";
} else {
header("Content-Disposition: $disposition; filename=\"" . trim($name)) . "\"";
} // if
header("Content-Transfer-Encoding: binary\n");
if ($file = fopen($path, 'rb')) {
while(!feof($file) and (connection_status()==0)) {
print(fread($file, 1024*8));
flush();
} // while
fclose($file);
} // if
// Done...
return((connection_status() == 0) && !connection_aborted());
} // end func download_file
Probaj sa ovim pa mi javi kako se snalazi. Tada sam baš ludeo zbog problema i probao razne varijacije tako da je moguće da ova funkcija ima i elemenata viška. U suštini, može da prosledi fajl ili da forsira download...
PS: $force_download bi trebalo da bude TRUE kako bi se fajl prosledio kao attachment ne inline (tj. kako bi pokrenuo download).