Link to home
Start Free TrialLog in
Avatar of fox_statton
fox_statton

asked on

Why is this not working?

Ive got this simple code:

$id="info.gif";
$file = '/home/server/files/76/'.$id;

header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header('Content-Length: ' . filesize($filename));
header('Content-Disposition: attachment; filename=' . basename($file));
readfile($file);


It seems to find the file fine, but it prints out the entire contents.

If I put

$file = '/home/server/files/76/info.gif";

it works fine.

Anyone?
Avatar of Batalf
Batalf
Flag of United States of America image

Both of them should have worked, since it's actually the exact same thing.

This is the code I have used for this:
   
$id="info.gif";
$file = "/home/server/files/76/".$id;

$mimetype = "image/gif"; // You should have a switch() block which sets the mimetype for different extensions.
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");    
header("Content-Type: ".$mimetype);
header("Content-Length: ".filesize($filename));
header("Content-Disposition: attachment; filename=\"$id\"");

Batalf
Avatar of prsupriya
prsupriya

try this....

$id="info.gif";
$file = '/home/server/files/76/'.$id;

header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Description: File Transfer');
header('Content-Type: image/gif');
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename="'. basename($file)."\"");
readfile($file);
exit();
ASKER CERTIFIED SOLUTION
Avatar of designbai
designbai

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial