plugins/gallery/fetcher.php
author Dan
Wed, 26 Aug 2009 23:37:37 -0400
changeset 38 512951548faa
parent 30 689b095d02cf
child 42 7c6e2e97aa08
permissions -rw-r--r--
More PHP warnings squashed.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
     1
<?php
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
     2
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
     3
/*
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
     4
 * Snapr
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
     5
 * Version 0.1 beta 1
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
     6
 * Copyright (C) 2007 Dan Fuhry
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
     7
 *
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
     8
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
     9
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    10
 *
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    11
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    12
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    13
 */
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    14
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    15
##
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    16
## IMAGE FILE FETCHER
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    17
##
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    18
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    19
$plugins->attachHook('base_classes_initted', '
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    20
  global $paths;
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    21
    $paths->add_page(Array(
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    22
      \'name\'=>\'Image fetcher pagelet\',
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    23
      \'urlname\'=>\'GalleryFetcher\',
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    24
      \'namespace\'=>\'Special\',
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    25
      \'special\'=>0,\'visible\'=>0,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\',
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    26
      ));
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    27
  ');
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    28
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    29
function page_Special_GalleryFetcher()
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    30
{
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    31
  global $db, $session, $paths, $template, $plugins; // Common objects
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    32
  
25
d9f37d2ea2cf Fixed race condition on canvas init (caused boxes to appear off by ~320px); fixed JSON response of null when row[img_tags] is NULL
Dan
parents: 9
diff changeset
    33
  // artificial race condition for debug
d9f37d2ea2cf Fixed race condition on canvas init (caused boxes to appear off by ~320px); fixed JSON response of null when row[img_tags] is NULL
Dan
parents: 9
diff changeset
    34
  // sleep(5);
d9f37d2ea2cf Fixed race condition on canvas init (caused boxes to appear off by ~320px); fixed JSON response of null when row[img_tags] is NULL
Dan
parents: 9
diff changeset
    35
  
0
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    36
  $type = $paths->getParam(0);
26
023a21c8f47c Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents: 25
diff changeset
    37
  if ( !in_array($type, array('thumb', 'preview', 'full', 'embed')) )
0
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    38
  {
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    39
    die('Hack attempt');
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    40
  }
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    41
  
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    42
  $id = intval($paths->getParam(1));
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    43
  if ( !$id )
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    44
  {
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    45
    die('Hack attempt');
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    46
  }
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    47
  
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    48
  // Permissions object
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    49
  $perms = $session->fetch_page_acl($id, 'Gallery');
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    50
  
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    51
  if ( !$perms->get_permissions('gal_full_res') && $type == 'full' )
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    52
  {
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    53
    $type = 'preview';
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    54
  }
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    55
  
9
ebd7003e73c6 Snapr now works with Enano's HTML/gzip optimization switches (1.0 compatibility broken, need 1.0.1 now)
Dan
parents: 0
diff changeset
    56
  $q = $db->sql_query('SELECT img_title, img_filename, img_time_mod, is_folder FROM '.table_prefix.'gallery WHERE img_id=' . $id . ';');
0
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    57
  if ( !$q )
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    58
    $db->_die();
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    59
  
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    60
  if ( $db->numrows() < 1 )
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    61
    die('Image not found');
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    62
  
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    63
  $row = $db->fetchrow();
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    64
  
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    65
  switch ( $type )
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    66
  {
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    67
    case 'thumb':
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    68
      $filename = ENANO_ROOT . '/cache/' . $row['img_filename'] . '-thumb.jpg';
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    69
      $mimetype = 'image/jpeg';
9
ebd7003e73c6 Snapr now works with Enano's HTML/gzip optimization switches (1.0 compatibility broken, need 1.0.1 now)
Dan
parents: 0
diff changeset
    70
      $ext = "jpg";
0
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    71
      break;
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    72
    case 'preview':
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    73
      $filename = ENANO_ROOT . '/cache/' . $row['img_filename'] . '-preview.jpg';
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    74
      $mimetype = 'image/jpeg';
9
ebd7003e73c6 Snapr now works with Enano's HTML/gzip optimization switches (1.0 compatibility broken, need 1.0.1 now)
Dan
parents: 0
diff changeset
    75
      $ext = "jpg";
0
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    76
      break;
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    77
    case 'full':
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    78
      $filename = ENANO_ROOT . '/files/' . $row['img_filename'];
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    79
      $ext = get_file_extension($filename);
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    80
      switch($ext)
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    81
      {
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    82
        case 'png': $mimetype = 'image/png'; break;
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    83
        case 'gif': $mimetype = 'image/gif'; break;
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    84
        case 'bmp': $mimetype = 'image/bmp'; break;
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    85
        case 'jpg': case 'jpeg': $mimetype = 'image/jpeg'; break;
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    86
        case 'tif': case 'tiff': $mimetype = 'image/tiff'; break;
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    87
        default: $mimetype = 'application/octet-stream';
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    88
      }
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    89
      break;
26
023a21c8f47c Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents: 25
diff changeset
    90
    case 'embed':
023a21c8f47c Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents: 25
diff changeset
    91
      if ( !isset($_GET['width']) || !isset($_GET['height']) )
023a21c8f47c Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents: 25
diff changeset
    92
      {
023a21c8f47c Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents: 25
diff changeset
    93
        die('Missing width or height.');
023a21c8f47c Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents: 25
diff changeset
    94
      }
023a21c8f47c Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents: 25
diff changeset
    95
      $width = intval($_GET['width']);
023a21c8f47c Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents: 25
diff changeset
    96
      $height = intval($_GET['height']);
023a21c8f47c Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents: 25
diff changeset
    97
      if ( empty($width) || empty($height) || $width > 2048 || $height > 2048 )
023a21c8f47c Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents: 25
diff changeset
    98
      {
023a21c8f47c Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents: 25
diff changeset
    99
        die('Bad width or height');
023a21c8f47c Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents: 25
diff changeset
   100
      }
023a21c8f47c Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents: 25
diff changeset
   101
      
28
36ea553da7ba Oops - maybe it should also detect the file extension properly
Dan
parents: 27
diff changeset
   102
      $ext = get_file_extension($row['img_filename']);
36ea553da7ba Oops - maybe it should also detect the file extension properly
Dan
parents: 27
diff changeset
   103
      
27
3d8ec1f7d191 Oops - scaled images weren't being cached right.
Dan
parents: 26
diff changeset
   104
      $src_filename  = ENANO_ROOT . '/files/' . $row['img_filename'];
3d8ec1f7d191 Oops - scaled images weren't being cached right.
Dan
parents: 26
diff changeset
   105
      $dest_filename = ENANO_ROOT . '/cache/' . $row['img_filename'] . "-embed-$width-$height.$ext";
3d8ec1f7d191 Oops - scaled images weren't being cached right.
Dan
parents: 26
diff changeset
   106
      $filename =& $dest_filename;
3d8ec1f7d191 Oops - scaled images weren't being cached right.
Dan
parents: 26
diff changeset
   107
      
26
023a21c8f47c Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents: 25
diff changeset
   108
      if ( !file_exists($dest_filename) )
023a21c8f47c Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents: 25
diff changeset
   109
      {
023a21c8f47c Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents: 25
diff changeset
   110
        if ( !scale_image($src_filename, $dest_filename, $width, $height, false) )
023a21c8f47c Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents: 25
diff changeset
   111
        {
023a21c8f47c Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents: 25
diff changeset
   112
          die('Image scaling process failed.');
023a21c8f47c Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents: 25
diff changeset
   113
        }
023a21c8f47c Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents: 25
diff changeset
   114
      }
023a21c8f47c Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents: 25
diff changeset
   115
      
023a21c8f47c Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents: 25
diff changeset
   116
      break;
0
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   117
    default:
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   118
      die('PHP...insane...');
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   119
      break;
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   120
  }
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   121
  
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   122
  // Make sure we have permission to read this image
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   123
  if ( !$perms->get_permissions('read') )
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   124
  {
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   125
    $filename = ENANO_ROOT . '/plugins/gallery/denied.png';
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   126
    $mimetype = 'image/png';
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   127
  }
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   128
  
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   129
  if ( $row['is_folder'] == '1' )
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   130
  {
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   131
    $filename = ENANO_ROOT . '/plugins/gallery/folder.png';
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   132
    $mimetype = 'image/png';
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   133
  }
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   134
  
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   135
  if ( !file_exists($filename) )
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   136
    die('Can\'t retrieve image file ' . $filename);
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   137
  
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   138
  $contents = file_get_contents($filename);
30
689b095d02cf Added Not-Modified support to fetcher; made caching more aggressive
Dan
parents: 28
diff changeset
   139
  // expire images 30 days from now
689b095d02cf Added Not-Modified support to fetcher; made caching more aggressive
Dan
parents: 28
diff changeset
   140
  $expiry = time() + ( 30 * 86400 );
0
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   141
  
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   142
  header('Content-type: '   . $mimetype);
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   143
  header('Content-length: ' . strlen($contents));
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   144
  header('Last-Modified: '  . date('r', $row['img_time_mod']));
30
689b095d02cf Added Not-Modified support to fetcher; made caching more aggressive
Dan
parents: 28
diff changeset
   145
  header('Expires: ' . date('r', $expiry));
689b095d02cf Added Not-Modified support to fetcher; made caching more aggressive
Dan
parents: 28
diff changeset
   146
  
689b095d02cf Added Not-Modified support to fetcher; made caching more aggressive
Dan
parents: 28
diff changeset
   147
  // check for not-modified condition
689b095d02cf Added Not-Modified support to fetcher; made caching more aggressive
Dan
parents: 28
diff changeset
   148
  if ( isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) )
689b095d02cf Added Not-Modified support to fetcher; made caching more aggressive
Dan
parents: 28
diff changeset
   149
  {
689b095d02cf Added Not-Modified support to fetcher; made caching more aggressive
Dan
parents: 28
diff changeset
   150
    $time = @strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
689b095d02cf Added Not-Modified support to fetcher; made caching more aggressive
Dan
parents: 28
diff changeset
   151
    if ( ( !empty($time) && intval($row['img_time_mod']) <= $time ) || date('r', $row['img_time_mod']) === $_SERVER['HTTP_IF_MODIFIED_SINCE'] )
689b095d02cf Added Not-Modified support to fetcher; made caching more aggressive
Dan
parents: 28
diff changeset
   152
    {
689b095d02cf Added Not-Modified support to fetcher; made caching more aggressive
Dan
parents: 28
diff changeset
   153
      header('HTTP/1.1 304 Not Modified');
689b095d02cf Added Not-Modified support to fetcher; made caching more aggressive
Dan
parents: 28
diff changeset
   154
      $db->close();
689b095d02cf Added Not-Modified support to fetcher; made caching more aggressive
Dan
parents: 28
diff changeset
   155
      exit;
689b095d02cf Added Not-Modified support to fetcher; made caching more aggressive
Dan
parents: 28
diff changeset
   156
    }
689b095d02cf Added Not-Modified support to fetcher; made caching more aggressive
Dan
parents: 28
diff changeset
   157
  }
0
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   158
  
9
ebd7003e73c6 Snapr now works with Enano's HTML/gzip optimization switches (1.0 compatibility broken, need 1.0.1 now)
Dan
parents: 0
diff changeset
   159
  if ( isset($_GET['download']) )
ebd7003e73c6 Snapr now works with Enano's HTML/gzip optimization switches (1.0 compatibility broken, need 1.0.1 now)
Dan
parents: 0
diff changeset
   160
  {
ebd7003e73c6 Snapr now works with Enano's HTML/gzip optimization switches (1.0 compatibility broken, need 1.0.1 now)
Dan
parents: 0
diff changeset
   161
    // determine an appropriate non-revealing filename
ebd7003e73c6 Snapr now works with Enano's HTML/gzip optimization switches (1.0 compatibility broken, need 1.0.1 now)
Dan
parents: 0
diff changeset
   162
    $filename = str_replace(' ', '_', $row['img_title']);
ebd7003e73c6 Snapr now works with Enano's HTML/gzip optimization switches (1.0 compatibility broken, need 1.0.1 now)
Dan
parents: 0
diff changeset
   163
    $filename = preg_replace('/([^\w\._-]+)/', '-', $filename);
ebd7003e73c6 Snapr now works with Enano's HTML/gzip optimization switches (1.0 compatibility broken, need 1.0.1 now)
Dan
parents: 0
diff changeset
   164
    $filename = trim($filename, '-');
ebd7003e73c6 Snapr now works with Enano's HTML/gzip optimization switches (1.0 compatibility broken, need 1.0.1 now)
Dan
parents: 0
diff changeset
   165
    $filename .= ".$ext";
ebd7003e73c6 Snapr now works with Enano's HTML/gzip optimization switches (1.0 compatibility broken, need 1.0.1 now)
Dan
parents: 0
diff changeset
   166
    header('Content-disposition: attachment; filename=' . $filename);
ebd7003e73c6 Snapr now works with Enano's HTML/gzip optimization switches (1.0 compatibility broken, need 1.0.1 now)
Dan
parents: 0
diff changeset
   167
  }
ebd7003e73c6 Snapr now works with Enano's HTML/gzip optimization switches (1.0 compatibility broken, need 1.0.1 now)
Dan
parents: 0
diff changeset
   168
  
0
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   169
  echo $contents;
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   170
  
9
ebd7003e73c6 Snapr now works with Enano's HTML/gzip optimization switches (1.0 compatibility broken, need 1.0.1 now)
Dan
parents: 0
diff changeset
   171
  gzip_output();
ebd7003e73c6 Snapr now works with Enano's HTML/gzip optimization switches (1.0 compatibility broken, need 1.0.1 now)
Dan
parents: 0
diff changeset
   172
  
ebd7003e73c6 Snapr now works with Enano's HTML/gzip optimization switches (1.0 compatibility broken, need 1.0.1 now)
Dan
parents: 0
diff changeset
   173
  $db->close();
ebd7003e73c6 Snapr now works with Enano's HTML/gzip optimization switches (1.0 compatibility broken, need 1.0.1 now)
Dan
parents: 0
diff changeset
   174
  exit;
ebd7003e73c6 Snapr now works with Enano's HTML/gzip optimization switches (1.0 compatibility broken, need 1.0.1 now)
Dan
parents: 0
diff changeset
   175
  
0
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   176
}
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   177
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   178
?>