Jump to content

[SOLVED] Download file using form button


AshmanSNET

Recommended Posts

G'day,

I'm having a bit of difficulty with my download page. I'm trying to get a file to download from a path I set when the button is pressed, however the header() doesn't seem to like me entering the path to the file.

 

How would I go about achieving this? I've looked for information on the net but can't seem to find anything helpful.

 

Thanks

 

Ashman

www.settlers.net

Link to comment
https://forums.phpfreaks.com/topic/72178-solved-download-file-using-form-button/
Share on other sites

This downloads the file specified in $file (with full path):

 

$file = "path/file.whatever"
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Content-Transfer-Encoding: binary');
readfile($file);
exit;

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.