Board index   FAQ   Search  
Register  Login
Board index PHP Your Scripts

Force File Download

This is where you share YOUR scripts with others

Moderators: macek, egami, gesf

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
<?PHP
   $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');
   readfile($file);
?>


What is the problem with it?
Thank you.
BenRocket
New php-forum User
New php-forum User
 
Posts: 1
Joined: Sun Dec 16, 2012 5:25 pm

Return to Your Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron