upload.php

Go to the documentation of this file.
00001 <?php
00002   /*
00003    This file is part of DocBookWiki.  DocBookWiki is a web application
00004    that displays and edits DocBook documents.
00005 
00006    Copyright (C) 2004, 2005, 2006, 2007
00007    Dashamir Hoxha, dashohoxha@users.sourceforge.net
00008 
00009    DocBookWiki is free software; you can redistribute it and/or modify
00010    it under the  terms of the GNU General  Public License as published
00011    by the Free  Software Foundation; either version 2  of the License,
00012    or (at your option) any later version.
00013 
00014    DocBookWiki is distributed in the  hope that it will be useful, but
00015    WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
00016    MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
00017    General Public License for more details.
00018 
00019    You should have  received a copy of the  GNU General Public License
00020    along  with  DocBookWiki;  if  not,  write  to  the  Free  Software
00021    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00022    USA
00023   */
00024 
00025 include_once 'config/const.Paths.php';
00026 include_once 'config/const.Options.php';
00027 include_once 'global.php';
00028 
00029 //load the translations of the messages
00030 set_locale();
00031 
00032 //get the variable upload_source and load the corresponding module
00033 //which contains the function upload_files(); this function should be
00034 //specific for each upload source
00035 $upload_source = $_POST['upload_source'];
00036 include_once "upload/$upload_source.php";
00037 
00038 //call the function upload_files()
00039 upload_files();
00040 
00041 //display a message about the upload
00042 include_once 'upload/upload_message.html';
00043 
00044 exit;
00045 
00046 //--------------- functions ---------------------
00047 
00049 function set_locale()
00050 {
00051   $app_name = basename(dirname(dirname(__FILE__)));
00052   $domain = $app_name;
00053   if (LNG != UNDEFINED)  setlocale(LC_MESSAGES, LNG);
00054   if (CODESET != UNDEFINED)  bind_textdomain_codeset($domain, CODESET);
00055   bindtextdomain($domain, 'l10n/');
00056   textdomain($domain);
00057 }
00058 
00060 function T_($msgid)
00061 {
00062   return gettext($msgid);
00063 }
00070 function check_upload_status($file)
00071 {
00072   $error = $_FILES[$file]['error'];
00073   switch ($error)
00074     {
00075     case UPLOAD_ERR_INI_SIZE:
00076       $msg = T_("File 'v_fname' exceeds the upload_max_filesize directive in php.ini.");
00077       break;
00078 
00079     case UPLOAD_ERR_FORM_SIZE:
00080       $msg = T_("File 'v_fname' exceeds the MAX_FILE_SIZE directive that was specified in the html form.");
00081       break;
00082 
00083     case UPLOAD_ERR_PARTIAL:
00084       $msg = T_("File 'v_fname' was only partially uploaded. Please try again.");
00085       break;
00086 
00087     case UPLOAD_ERR_NO_FILE:
00088       $msg = T_("No file was uploaded. Please try again.");
00089       break;
00090 
00091     default:
00092     case UPLOAD_ERR_OK:
00093       $msg = '';
00094       break;
00095     }
00096 
00097   $fname = $_FILES[$file]['name'];
00098   $fname = basename($fname);
00099   $msg = str_replace('v_fname', $fname, $msg);
00100 
00101   return $msg;
00102 }
00103 
00109 function move_file($tmp_file, $dest_file)
00110 {
00111   //check that the file is uploaded
00112   if (!is_uploaded_file($tmp_file))
00113     $msg = T_("File 'v_fname' not uploaded, there is some error.");
00114 
00115   //move the uploaded file to the destination
00116   chmod($tmp_file, 0644);
00117   $dest_dir = dirname($dest_file);
00118   shell("mkdir -p $dest_dir");
00119   shell("cp $tmp_file $dest_file");
00120   unlink($tmp_file);
00121 
00122   //check that the file was moved successfully
00123   if (file_exists($dest_file))
00124     $msg = T_("File 'v_fname' uploaded successfully.");
00125   else 
00126     $msg = T_("File 'v_fname' is not uploaded for some reasons.");
00127 
00128   $msg = str_replace('v_fname', basename($dest_file), $msg);
00129   return $msg;
00130 }
00131 ?>

Generated on Wed Jan 9 08:27:32 2008 for DokBookWiki by  doxygen 1.5.2