00001 <?php
00002 # This file is part of the Savane project
00003 # <http://gna.org/projects/savane/>
00004 #
00005 # $Id: download.php 5326 2006-02-05 21:18:20Z yeupou $
00006 #
00007 # Copyright 2001-2002 (c) Laurent Julliard, CodeX Team, Xerox
00008 #
00009 # Copyright 2002-2005 (c) Mathieu Roy <yeupou--gnu.org>
00010 #
00011 #
00012 # The Savane project is free software; you can redistribute it and/or
00013 # modify it under the terms of the GNU General Public License
00014 # as published by the Free Software Foundation; either version 2
00015 # of the License, or (at your option) any later version.
00016 #
00017 # The Savane project is distributed in the hope that it will be useful,
00018 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00020 # GNU General Public License for more details.
00021 #
00022 # You should have received a copy of the GNU General Public License
00023 # along with the Savane project; if not, write to the Free Software
00024 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00025
00026
00027 if (isset($item_file_id))
00028 {
00029 $file_id = $item_file_id;
00030 }
00031
00032 # check if the provided file_id is a valid numerical id
00033 if (!$file_id || !ctype_digit($file_id))
00034 {
00035 exit_missing_param();
00036 }
00037
00038 $sql="SELECT filename,filesize FROM trackers_file WHERE file_id='$file_id' LIMIT 1";
00039 $result=db_query($sql);
00040
00041 if ($result && db_numrows($result) > 0)
00042 {
00043
00044 if (db_result($result,0,'filesize') == 0)
00045 {
00046
00047 exit_error(_('Nothing in here - File has a null size'));
00048
00049 }
00050 else
00051 {
00052 # Redirect to an url that will pretend the file really exists with
00053 # this name, so all browsers will propose its name as filename when
00054 # saving it.
00055 session_redirect($GLOBALS['sys_home'].'file/'.db_result($result,0,'filename').'?file_id='.$file_id);
00056
00057 }
00058
00059 }
00060 else
00061 {
00062 exit_error(_("Couldn't find attached file")." (file #$file_id)");
00063 }
00064
00065 ?>