header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename="". $file ."";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($file));
file_get_contents($file);
readfile($file);
exit();
Any idea what I'm doing wrong? Shouldn't this download any file from my server to the harddrive of the user? Somehow every file is damaged! Moreover I wonder how I can change the filename of the downloaded file?
$file
always contains the full path to my file.
if I try header('Location:' . $file );
the browser successfully opens my file. however if the file is a .jpg the browser doesn't prompt the download window. instead it just opens the file in the browserwindow. I want every file to be downloaded to the hd.
Please help me guys. I'm after this for over a week now and I can't find a solution?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…