Simply downloading a file from a webpage

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dilbert137
Forum Commoner
Posts: 57
Joined: Sat Jun 02, 2007 5:02 am
Location: Mauritius

Simply downloading a file from a webpage

Post by Dilbert137 »

Dear All,

Does anyone knows how to download a csv file from a webpage directory as a save as like when we want to download a file from a http server or ftp server? I got a sample coding but i don't think it's the solution as i displays only the data and does not download the file as a save as menu.

if (isset($_REQUEST["file"])) {
$file=$dir.$_REQUEST["file"];
header("Content-type: application/force-download");
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($file));
header("Content-disposition: attachment; filename=".basename($file)."");
readfile("$file");
} else {
echo "No file selected";

Regards
Stéphane
Post Reply