Force File Download

This is where you share YOUR scripts with others

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Sun Dec 16, 2012 5:25 pm

Force File Download

Postby BenRocket » Sun Dec 16, 2012 5:36 pm

I'm practicing with PHP and trying to download a file using PHP. However, the file contents just outputted to the screen. There is the code:

Code: Select all

   $download_path = $_SERVER['DOCUMENT_ROOT'] . "/my_cms/root/scripts/logging_in/uploaded_files";
   $filename = $_GET['filename'];
   $file = "$download_path/$file";
   if(!file_exists($file)) die("I'm sorry, the file doesn't seem to exist.");
   $type = filetype($file);
   $today = date("F j, Y, g:i a");
   $time = time();

    header('Content-Description: File Transfer');
   header("Content-type: $type");
   header("Content-Disposition: attachment;filename=$filename");
   header("Content-Transfer-Encoding: binary");
   header('Expires: 0');

What is the problem with it?
Thank you.

Return to “Your Scripts”

Who is online

Users browsing this forum: No registered users and 4 guests