Downloading a file via php

Soldato
Joined
4 Jul 2004
Posts
2,647
Location
aberdeen
Hello
I have a file called download.php, and it basically checks if a user is logged in, if they are it uses fopen/fread to open + send a file, but because the file name is .php it saves it as download.php. Is there any way to make it save it as a different name, without using htaccess?

Code:
<? 

include("include/session.php");
// checks if user is logged in
if($session->logged_in){
  //sets the header to appluication/zip cos its a zip file
header('Content-type: application/zip');

$fp = fopen('examplefile.zip', 'rb');
while (!feof($fp))
echo fread($fp, 1024);
fclose($fp);

}
// else if not logged in
else{
//redirect to the main page (yeh i should put a sorry you cant download it yet, but meh
		  header("Location: main.php");
		  
}
?>
 
Back
Top Bottom