Jump to content

Using Headers to send download


bob_the _builder

Recommended Posts

Hi,

 

The following code should get files from url and prompt download.

 

file.php

 

$file = '/home/fusion/public_html/uploads/'.$_GET['files'].'';

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-type: $type");
header("Content-Disposition: attachment;filename=$filename");
header('Pragma: no-cache');
header('Expires: 0');
    
readfile($file);

 

if i send the url as:

 

file.php?1.zip which exists in the uploads folder I get prompted to download file called file.php

 

Any ideas what the issue maybe?

 

 

Cheers

 

 

Link to comment
https://forums.phpfreaks.com/topic/40477-using-headers-to-send-download/
Share on other sites

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.