Location: PHPKode > projects > Aukyla Document Management System > htdocs/download.php
<?php
/*
     download.php, used for downloading files from a URI.
     Copyright (C) 2004 Arend van Beelen, Auton Rijnsburg

     This program is free software; you can redistribute it and/or modify it under the terms of the
     GNU General Public License as published by the Free Software Foundation; either version 2 of
     the License, or (at your option) any later version.

     This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
     without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
     the GNU General Public License for more details.

     You should have received a copy of the GNU General Public License along with this program; if
     not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
     MA 02111-1307 USA

     For any questions, comments or whatever, you may mail me at: hide@address.com
*/

// Uncomment the next line if you can't adjust the include_path setting in your
// php.ini file:
//set_include_path('.:aukyla/base:aukyla/apps:aukyla/plugins');

require_once('Config.php');
require_once('Login.php');
require_once('MIME.php');
require_once('Output.php');
require_once('URI.php');

Output::disableTransformation();

$file = Config::request('file');
$name = Config::request('name');

if($name == '')
{
	$name = basename($file);
}

$mime = MIME::type($name, false);
header("Content-Disposition: attachment; filename=\"$name\"");

if($mime == '')
{
	$mime = MIME::type($file);
}

header("Content-type: $mime");

$contents = URI::fileGetContents($file);
if($contents === false)
{
	errorPage('404', 'Not Found',
	          "The requested URL $file was not found on this server.");
}

echo $contents;
return;

function errorPage($errorcode, $errorstring, $message)
{
	header("HTTP/1.0 $errorcode $errorstring");
	die("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n".
	    "<html><head>\n".
	    "<title>$errorcode $errorstring</title>\n".
	    "</head><body>\n".
	    "<h1>$errorstring</h1>\n".
	    "$message<p>\n".
	    "<hr>\n".
	    "<address>{$_SERVER['SERVER_SIGNATURE']}</address>\n".
	    "</body></html>\n");
}

?>
Return current item: Aukyla Document Management System