amars Posted January 6, 2011 Share Posted January 6, 2011 here's the code: if (empty($_GET['send_file'])) { header("Refresh: 5; url=$whoami?file=$req_file&send_file=yes"); } else { header("Content-Description: File Transfer"); header("Content-Type: application/force-download"); header("Content-Length: " . filesize("$fileserver_path/$req_file")); header("Content-Disposition: attachment; filename=".$req_file); readfile("$fileserver_path"."/"."$req_file"); exit; } i am using it to hide my download paths. Quote Link to comment https://forums.phpfreaks.com/topic/223577-content-deposition-not-working/ Share on other sites More sharing options...
AbraCadaver Posted January 6, 2011 Share Posted January 6, 2011 I don't see where you define $req_file and you probably want: header('Content-Type: application/octet-stream'); Quote Link to comment https://forums.phpfreaks.com/topic/223577-content-deposition-not-working/#findComment-1155710 Share on other sites More sharing options...
amars Posted January 6, 2011 Author Share Posted January 6, 2011 I already tried octet/stream. Here's the entire script. I got it off hotscripts. The url of the page is: http://www.domain.com/dcheck.php?file=2_fcf.xls <?php session_start();if ($_SESSION['dstatus']=='F') { header("Location: http://www.domain.com/downloadform.php"); exit; } $fileserver_path = dirname(documents); // change this to the directory your files reside $req_file = basename($_GET['file']); $whoami = basename(__FILE__); // you are free to rename this file if (empty($req_file)) { print "Usage: $whoami?file=<file_to_download>"; exit; } /* no web spamming */ if (!preg_match("/^[a-zA-Z0-9._-]+$/", $req_file, $matches)) { print "I can't do that. sorry."; exit; } /* download any file, but not this one */ if ($req_file == $whoami) { print "I can't do that. sorry."; exit; } /* check if file exists */ if (!file_exists("$fileserver_path/$req_file")) { print "File <strong>$req_file</strong> doesn't exist."; exit; } if (empty($_GET['send_file'])) { header("Refresh: 5; url=$whoami?file=$req_file&send_file=yes"); } else { header('Content-Description: File Transfer'); header('Content-Type: application/force-download'); header('Content-Length: ' . filesize("$fileserver_path/$req_file")); header('Content-Disposition: attachment; filename=' . $req_file); readfile("$fileserver_path/$req_file"); exit; } ?> <!-- Change the HTML page below for your convenient --> <html> <head> <title></title> <!-- Maybe Google Analytics here? --> </head> <body> <h2>Downloading <?=$req_file?>...</h2> <p>Your download should begin shortly. If it doesn't start, follow this <a href="<?=$req_file?>">link</a>.</p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/223577-content-deposition-not-working/#findComment-1155713 Share on other sites More sharing options...
PFMaBiSmAd Posted January 6, 2011 Share Posted January 6, 2011 You didn't state what it was doing when it is not working, but you technically need to enclose the filename in double-quotes to get all browsers to recognize the file name, i.e. filename="whatever" Also, any chance your filename contains special characters (even a space) that would require urlencoding the value? Quote Link to comment https://forums.phpfreaks.com/topic/223577-content-deposition-not-working/#findComment-1155721 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.