Source for file uploadimage.php

Documentation is available at uploadimage.php

  1. <?php
  2. /**
  3. @package Mambo
  4. @author Mambo Foundation Inc see README.php
  5. @copyright Mambo Foundation Inc.
  6. *  See COPYRIGHT.php for copyright notices and details.
  7. @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see
  8. *  LICENSE.php
  9. *  Mambo is free software; you can redistribute it and/or
  10. *  modify it under the terms of the GNU General Public License
  11. *  as published by the Free Software Foundation; version 2 of the
  12. *  License.
  13. */ 
  14.  
  15. //$adminside = 3;
  16. //require_once('../../index.php');
  17.  
  18. $directory mosGetParam$_REQUEST'directory''');
  19.  
  20. $userfile2=(isset($_FILES['userfile']['tmp_name']$_FILES['userfile']['tmp_name'"");
  21. $userfile_name=(isset($_FILES['userfile']['name']$_FILES['userfile']['name'"");
  22.  
  23. if (isset($_FILES['userfile'])) {
  24.     if ($directory!="banners"{
  25.         $base_Dir "../images/stories/";
  26.     else {
  27.         $base_Dir "../images/banners/";
  28.     }
  29.     if (empty($userfile_name)) {
  30.         echo "<script>alert('".T_('Please select an image to upload'."'); document.location.href='uploadimage.php';</script>";
  31.     }
  32.  
  33.     $filename split("\."$userfile_name);
  34.  
  35.     if (eregi("[^0-9a-zA-Z_]"$filename[0])) {
  36.         echo "<script> alert('".T_('File must only contain alphanumeric characters and no spaces please.'."'); window.history.go(-1);</script>\n";
  37.         exit();
  38.     }
  39.  
  40.     if (file_exists($base_Dir.$userfile_name)) {
  41.         echo "<script> alert('".sprintf(T_('Image %s already exists.'),$userfile_name."'); window.history.go(-1);</script>\n";
  42.         exit();
  43.     }
  44.  
  45.     if ((strcasecmp(substr($userfile_name,-4),".gif")) && (strcasecmp(substr($userfile_name,-4),".jpg")) && (strcasecmp(substr($userfile_name,-4),".png")) && (strcasecmp(substr($userfile_name,-4),".bmp")) &&(strcasecmp(substr($userfile_name,-4),".doc")) && (strcasecmp(substr($userfile_name,-4),".xls")) && (strcasecmp(substr($userfile_name,-4),".ppt")) && (strcasecmp(substr($userfile_name,-4),".swf")) && (strcasecmp(substr($userfile_name,-4),".pdf"))) {
  46.         echo "<script>alert('".T_('The file must be gif, png, jpg, bmp, swf, doc, xls or ppt'."'); window.history.go(-1);</script>\n";
  47.         exit();
  48.     }
  49.  
  50.  
  51.     if (eregi(".pdf"$userfile_name|| eregi(".doc"$userfile_name|| eregi(".xls"$userfile_name|| eregi(".ppt"$userfile_name)) {
  52.         if (!move_uploaded_file ($_FILES['userfile']['tmp_name'],$media_path.$_FILES['userfile']['name']|| !mosChmod($media_path.$_FILES['userfile']['name'])) {
  53.             echo "<script>alert('".sprintf(T_('Upload of %s failed')$userfile_name."'); window.history.go(-1);</script>\n";
  54.             exit();
  55.         }
  56.         else {
  57.             echo "<script>alert('".sprintf(T_('Upload of %s to %s successful')$userfile_name$media_path."'); window.history.go(-1);</script>\n";
  58.             exit();
  59.         }
  60.     elseif (!move_uploaded_file ($_FILES['userfile']['tmp_name'],$base_Dir.$_FILES['userfile']['name']|| !mosChmod($base_Dir.$_FILES['userfile']['name'])) {
  61.         echo "<script>alert('".sprintf(T_('Upload of %s failed')$userfile_name."'); window.history.go(-1);</script>\n";
  62.         exit();
  63.     }
  64.     else {
  65.         echo "<script>alert('".sprintf(T_('Upload of %s to %s successful')$userfile_name$base_Dir."'); window.history.go(-1);</script>\n";
  66.         exit();
  67.     }
  68.  
  69.  
  70. }
  71.  
  72. $iso split'='_ISO );
  73. // xml prolog
  74. echo '<?xml version="1.0" encoding="'$iso[1.'"?' .'>';
  75. ?>
  76. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  77. <html xmlns="http://www.w3.org/1999/xhtml">
  78. <head>
  79. <title>Upload a file</title>
  80. <meta http-equiv="Content-Type" content="text/html; <?php echo _ISO?>" />
  81. <?php
  82. $css mosGetParam($_REQUEST,"t","");
  83. ?>
  84. <link rel="stylesheet" href="../templates/<?php echo $css?>/css/template_css.css" type="text/css" />
  85. </head>
  86. <body>
  87. <table class="adminform">
  88.   <form method="post" action="index3.php?pop=uploadimage.php" enctype="multipart/form-data" name="filename">
  89.     <tr>
  90.       <th class="title"> <?php echo T_('File Upload :'?> <?php echo $directory?></th>
  91.     </tr>
  92.     <tr>
  93.       <td align="center">
  94.         <input class="inputbox" name="userfile" type="file" />
  95.       </td>
  96.     </tr>
  97.     <tr>
  98.       <td>
  99.         <input class="button" type="submit" value="Upload" name="fileupload" />
  100.         <?php echo T_('Max size'?> = <?php echo ini_get'post_max_size' );?>
  101.       </td>
  102.     <tr>
  103.       <td>
  104.         <input type="hidden" name="directory" value="<?php echo $directory;?>" />
  105.       </td>
  106.     </tr>
  107.   </form>
  108. </table>
  109. </body>
  110. </html>

Documentation generated on Mon, 05 May 2008 16:23:55 +0400 by phpDocumentor 1.4.0