b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (0.9.x) [ class tree: admin ] [ index: admin ] [ all elements ]

Source for file b2upload.php

Documentation is available at b2upload.php

  1. <?php
  2. /**
  3.  * b2 File Upload
  4.  *
  5.  * b2evolution - {@link http://b2evolution.net/}
  6.  * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  7.  * @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
  8.  *
  9.  * @package admin
  10.  * @author original hack by shockingbird.com
  11.  */
  12.  
  13. /**
  14.  * Includes:
  15.  */
  16. require_once (dirname(__FILE__).'/_header.php');
  17.  
  18. // Check permissions:
  19. $current_User->check_perm'upload''any'true );
  20.  
  21. ?><html xml:lang="<?php locale_lang(?>" lang="<?php locale_lang(?>">
  22. <head>
  23.     <meta http-equiv="Content-Type" content="text/html; charset=<?php locale_charset(?>" />
  24.     <title><?php echo T_('b2evo'?> &gt; <?php echo T_('upload images/files'?></title>
  25.     <link href="variation.css" rel="stylesheet" type="text/css" title="Variation" />
  26.     <link href="desert.css" rel="alternate stylesheet" type="text/css" title="Desert" />
  27.     <link href="legacy.css" rel="alternate stylesheet" type="text/css" title="Legacy" />
  28.     <?php ifis_filedirname(__FILE__).'/custom.css' ) ) ?>
  29.     <link href="custom.css" rel="alternate stylesheet" type="text/css" title="Custom" />
  30.     <?php ?>
  31.     <script type="text/javascript" src="styleswitcher.js"></script>
  32.     <script type="text/javascript">
  33.     <!-- // idocs.com's popup tutorial rules !
  34.     function targetopener(blah, closeme, closeonly) {
  35.         if (! (window.focus && window.opener))return true;
  36.         window.opener.focus();
  37.         if (! closeonly)window.opener.document.post.content.value += blah;
  38.         if (closeme)window.close();
  39.         return false;
  40.     }
  41.     //-->
  42.     </script>
  43. </head>
  44. <body>
  45. <div class="panelblock">
  46. <?php
  47.  
  48. if (!isset($_POST['submit']))
  49. {
  50.     $i explode(" ",$fileupload_allowedtypes);
  51.     $i implode(", ",array_slice($i1count($i)-2));
  52.     ?>
  53.     <p><strong><?php echo T_('File upload'?></strong></p>
  54.     <p><?php echo T_('Allowed file types:')$i ?></p>
  55.     <p><?php printfT_('Maximum allowed file size: %d KB')$fileupload_maxk )?></p>
  56.     <form action="b2upload.php" method="post" enctype="multipart/form-data">
  57.     <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $fileupload_maxk*1024 ?>" />
  58.     <input type="file" name="img1" size="30" class="uploadform" />
  59.  
  60.     <p><?php echo T_('Description'?>:<br />
  61.     <input type="text" name="imgdesc" size="30" class="uploadform" /></p>
  62.  
  63.     <input type="submit" name="submit" value="<?php echo T_('Upload !'?>" class="search" />
  64.     </form>
  65. </div>
  66. </body>
  67. </html>
  68. <?php exit();
  69. }
  70.  
  71.  //Makes sure they choose a file
  72.  
  73. //print_r($_FILES);
  74. //die();
  75.  
  76. if (!empty($_POST)) //$img1_name != "") {
  77.     $imgalt (isset($_POST['imgalt'])) $_POST['imgalt''';
  78.  
  79.     $img1_name (strlen($imgalt)) $_POST['imgalt'$_FILES['img1']['name'];
  80.     $img1_type (strlen($imgalt)) $_POST['img1_type'$_FILES['img1']['type'];
  81.     $img1_size (strlen($imgalt)) $_POST['img1_size'$_FILES['img1']['size'];
  82.     $imgdesc str_replace('"''&amp;quot;'$_POST['imgdesc']);
  83.  
  84.     $imgtype explode(".",$img1_name);
  85.     $imgtype " ".$imgtype[count($imgtype)-1]." ";
  86.  
  87.     if (!ereg(strtolower($imgtype)strtolower($fileupload_allowedtypes))) {
  88.         die(sprintfT_('File %s: type %s is not allowed.')$img1_name$imgtype ));
  89.     }
  90.  
  91.     if (strlen($imgalt)) {
  92.         $pathtofile $fileupload_realpath."/".$imgalt;
  93.         $img1 $_POST['img1'];
  94.     else {
  95.         $pathtofile $fileupload_realpath."/".$img1_name;
  96.         $img1 $_FILES['img1']['tmp_name'];
  97.     }
  98.  
  99.     // makes sure not to upload duplicates, rename duplicates
  100.     $i 1;
  101.     $pathtofile2 $pathtofile;
  102.     $tmppathtofile $pathtofile2;
  103.     $img2_name $img1_name;
  104.  
  105.     while (file_exists($pathtofile2)) {
  106.         $pos strpos($tmppathtofile'.'.trim($imgtype));
  107.         $pathtofile_start substr($tmppathtofile0$pos);
  108.         $pathtofile2 $pathtofile_start.'_'.zeroise($i++2).'.'.trim($imgtype);
  109.         $img2_name explode('/'$pathtofile2);
  110.         $img2_name $img2_name[count($img2_name)-1];
  111.     }
  112.  
  113.     if (file_exists($pathtofile&& !strlen($imgalt)) {
  114.         $i explode(" ",$fileupload_allowedtypes);
  115.         $i implode(", ",array_slice($i1count($i)-2));
  116.         move_uploaded_file($img1$pathtofile2)
  117.          or dieT_('Couldn\'t upload your file to:').' '.$pathtofile2);
  118.  
  119.     if!chmod($pathtofile20644) )
  120.     {
  121.         echo '<p class="error">Unable to change file permissions..</p>';
  122.     }
  123.     // duplicate-renaming function contributed by Gary Lawrence Murphy
  124.     ?>
  125.     <p><strong><?php echo T_('Duplicate File?'?></strong></p>
  126.     <p><strong><em><?php printfT_('The filename "%s" already exists!')$img1_name )?></em></strong></p>
  127.     <p><?php printfT_('Filename "%s" moved to "%s"')$img1$pathtofile2.'/'.$img2_name )?></p>
  128.     <p><?php echo T_('Confirm or rename:'?></p>
  129.     <form action="b2upload.php" method="post" enctype="multipart/form-data">
  130.     <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $fileupload_maxk*1024 ?>" />
  131.     <input type="hidden" name="img1_type" value="<?php echo $img1_type;?>" />
  132.     <input type="hidden" name="img1_size" value="<?php echo $img1_size;?>" />
  133.     <input type="hidden" name="img1_name" value="<?php echo $img2_name;?>" />
  134.     <input type="hidden" name="img1" value="<?php echo $pathtofile2;?>" />
  135.     <?php echo T_('Alternate name'?>:<br /><input type="text" name="imgalt" size="30" class="uploadform" value="<?php echo $img2_name;?>" /><br />
  136.     <br />
  137.     <?php echo T_('Description'?>:<br /><input type="text" name="imgdesc" size="30" class="uploadform" value="<?php echo $imgdesc;?>" />
  138.     <br />
  139.     <p><input type="submit" name="submit" value="<?php echo T_('Confirm !'?>" class="search" /></p>
  140.     </form>
  141. </div>
  142. </body>
  143. </html><?php die();
  144.  
  145.     }
  146.  
  147.     if (!strlen($imgalt)) {
  148.         move_uploaded_file($img1$pathtofile//Path to your images directory, chmod the dir to 777
  149.          or dieT_('Couldn\'t upload your file to:').' '.$pathtofile);
  150.     else {
  151.         rename($img1$pathtofile)
  152.         or dieT_('Couldn\'t upload your file to:').' '.$pathtofile);
  153.     }
  154.     if!chmod($pathtofile0644) )
  155.     {
  156.         echo '<p class="error">Unable to change file permissions..</p>';
  157.     }
  158. }
  159.  
  160.  
  161. ifereg('image/'$img1_type) )
  162. // uploaded file is an image
  163.     $piece_of_code '&lt;img src=&quot;'.$fileupload_url.'/'.$img1_name.'&quot;';
  164.     if$img_dimensions getimagesize$pathtofile ) )
  165.     // add 'width="xx" height="xx"
  166.         $piece_of_code .= ' width=&quot;'.$img_dimensions[0].'&quot; height=&quot;'.$img_dimensions[1].'&quot;';
  167.     }
  168.     $piece_of_code .= ' alt=&quot;'.$imgdesc.'&quot; /&gt;';
  169. }
  170. else
  171. {
  172.     $piece_of_code '&lt;a href=&quot;'.$fileupload_url.'/'.$img1_name.'&quot; title=&quot;'.$imgdesc.'&quot;&gt;'.$imgdesc.'&lt;/a&gt;';
  173. }
  174.  
  175. ?>
  176.  
  177. <p><strong><?php echo T_('File uploaded !'?></strong></p>
  178. <p><?php printfT_('Your file <strong>"%s"</strong> was uploaded successfully !')$img1_name )?></p>
  179. <p><?php echo T_('Here\'s the code to display it:'?></p>
  180. <p><form action="b2upload.php">
  181. <!--<textarea cols="25" rows="3" wrap="virtual"><?php echo "&lt;img src=&quot;$fileupload_url/$img1_name&quot; border=&quot;0&quot; alt=&quot;&quot; /&gt;"?></textarea>-->
  182. <input type="text" name="imgpath" value="<?php echo $piece_of_code?>" size="40" class="large" /><br />
  183. <input type="button" name="close" value="<?php echo T_('Add the code to your post !'?>" class="search" onclick="targetopener('<?php echo $piece_of_code?>')" />
  184. </form>
  185. </p>
  186. <p><strong><?php echo T_('Image Details'?></strong>: <br />
  187. <?php echo T_('Name'?>:
  188. <?php echo "$img1_name"?>
  189. <br />
  190. <?php echo T_('Size'?>:
  191. <?php echo round($img1_size/1024,2)?> KB
  192. <br />
  193. <?php echo T_('Type'?>:
  194. <?php echo "$img1_type"?>
  195. </p>
  196. <p align="right">
  197. <form action="b2upload.php">
  198. <input type="button" name="close" value="<?php echo T_('Close this window'?>" class="search" onclick="window.close()" />
  199. </form>
  200. </p>
  201. </div>
  202. </body>
  203. </html>

Documentation generated on Tue, 20 May 2008 01:51:28 +0200 by phpDocumentor 1.4.2