[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/public_html/ -> getimage.php (source)

   1  <?php
   2  
   3  /* Reminder: always indent with 4 spaces (no tabs). */
   4  // +---------------------------------------------------------------------------+
   5  // | Geeklog 1.4                                                               |
   6  // +---------------------------------------------------------------------------+
   7  // | getimage.php                                                              |
   8  // |                                                                           |
   9  // | Shows images outside of the webtree                                       |
  10  // +---------------------------------------------------------------------------+
  11  // | Copyright (C) 2004-2006 by the following authors:                         |
  12  // |                                                                           |
  13  // | Authors: Tony Bibbs        - tony AT tonybibbs DOT com                    |
  14  // +---------------------------------------------------------------------------+
  15  // |                                                                           |
  16  // | This program is free software; you can redistribute it and/or             |
  17  // | modify it under the terms of the GNU General Public License               |
  18  // | as published by the Free Software Foundation; either version 2            |
  19  // | of the License, or (at your option) any later version.                    |
  20  // |                                                                           |
  21  // | This program is distributed in the hope that it will be useful,           |
  22  // | but WITHOUT ANY WARRANTY; without even the implied warranty of            |
  23  // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             |
  24  // | GNU General Public License for more details.                              |
  25  // |                                                                           |
  26  // | You should have received a copy of the GNU General Public License         |
  27  // | along with this program; if not, write to the Free Software Foundation,   |
  28  // | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
  29  // |                                                                           |
  30  // +---------------------------------------------------------------------------+
  31  //
  32  // $Id: getimage.php,v 1.7 2006/05/26 13:35:39 dhaun Exp $
  33  
  34  /**
  35  * For really strict webhosts, this file an be used to show images in pages that
  36  * serve the images from outside of the webtree to a place that the webserver
  37  * user can actually write too
  38  *
  39  * @author   Tony Bibbs <tony@tonybibbs.com>
  40  *
  41  */
  42  
  43  require_once  'lib-common.php';
  44  
  45  require_once $_CONF['path_system'] . 'classes/downloader.class.php';
  46  
  47  $downloader = new downloader();
  48  
  49  $downloader->setLogFile($_CONF['path_log'] . 'error.log');
  50  
  51  $downloader->setLogging(true);
  52  
  53  $downloader->setAllowedExtensions(array('gif' => 'image/gif',
  54                                          'jpg' => 'image/jpeg',
  55                                          'jpeg' => 'image/jpeg',
  56                                          'png' => 'image/x-png',
  57                                         )
  58                                   );
  59                                   
  60  $mode = '';
  61  if (isset($_GET['mode'])) {
  62      $mode = $_GET['mode'];
  63  }
  64  $image = '';
  65  if (isset($_GET['image'])) {
  66      $image = COM_applyFilter ($_GET['image']);
  67  }
  68  if (strstr($image, '..')) {
  69      // Can you believe this, some jackass tried to relative pathing to access
  70      // files they shouldn't have access to?
  71      COM_accessLog('Someone tried to illegally access files using getimage.php');
  72      exit;
  73  }
  74  
  75  // Set the path properly
  76  switch ($mode) {
  77      case 'show':
  78      case 'articles':
  79          $downloader->setPath($_CONF['path_images'] . 'articles/');
  80          break;
  81      case 'topics':
  82          $downloader->setPath($_CONF['path_images'] . 'topics/');
  83          break;
  84      case 'userphotos':
  85          $downloader->setPath($_CONF['path_images'] . 'userphotos/');
  86          break;
  87      default:
  88          // Hrm, got a bad path, just die
  89          exit;
  90  }
  91  
  92  // Let's see if we don't have a legit file.  If not bail
  93  if (is_file($downloader->getPath() . $image)) {
  94      if ($mode == 'show') {
  95          echo '<html><body><img src="' . $_CONF['site_url'] . '/getimage.php?mode=articles&amp;image=' . $image . '" alt=""></body></html>';
  96      } else {
  97          $downloader->downloadFile($image);
  98      }
  99  } else {
 100      $display = COM_errorLog('File, ' . $image . ', was not found in getimage.php');
 101  
 102      if ($mode == 'show') {
 103          echo COM_siteHeader ('menu') . $display . COM_siteFooter ();
 104      } else {
 105          header ('HTTP/1.0 404 Not Found');
 106      }
 107  }
 108  
 109  ?>


Généré le : Wed Nov 21 12:27:40 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics