Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/223577-content-deposition-not-working/
Share on other sites

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>

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.