plugins/gallery/fetcher.php
changeset 9 ebd7003e73c6
parent 0 7caf561c50ee
child 25 d9f37d2ea2cf
equal deleted inserted replaced
8:8490ce0cdd8c 9:ebd7003e73c6
    48   if ( !$perms->get_permissions('gal_full_res') && $type == 'full' )
    48   if ( !$perms->get_permissions('gal_full_res') && $type == 'full' )
    49   {
    49   {
    50     $type = 'preview';
    50     $type = 'preview';
    51   }
    51   }
    52   
    52   
    53   $q = $db->sql_query('SELECT img_filename, img_time_mod, is_folder FROM '.table_prefix.'gallery WHERE img_id=' . $id . ';');
    53   $q = $db->sql_query('SELECT img_title, img_filename, img_time_mod, is_folder FROM '.table_prefix.'gallery WHERE img_id=' . $id . ';');
    54   if ( !$q )
    54   if ( !$q )
    55     $db->_die();
    55     $db->_die();
    56   
    56   
    57   if ( $db->numrows() < 1 )
    57   if ( $db->numrows() < 1 )
    58     die('Image not found');
    58     die('Image not found');
    62   switch ( $type )
    62   switch ( $type )
    63   {
    63   {
    64     case 'thumb':
    64     case 'thumb':
    65       $filename = ENANO_ROOT . '/cache/' . $row['img_filename'] . '-thumb.jpg';
    65       $filename = ENANO_ROOT . '/cache/' . $row['img_filename'] . '-thumb.jpg';
    66       $mimetype = 'image/jpeg';
    66       $mimetype = 'image/jpeg';
       
    67       $ext = "jpg";
    67       break;
    68       break;
    68     case 'preview':
    69     case 'preview':
    69       $filename = ENANO_ROOT . '/cache/' . $row['img_filename'] . '-preview.jpg';
    70       $filename = ENANO_ROOT . '/cache/' . $row['img_filename'] . '-preview.jpg';
    70       $mimetype = 'image/jpeg';
    71       $mimetype = 'image/jpeg';
       
    72       $ext = "jpg";
    71       break;
    73       break;
    72     case 'full':
    74     case 'full':
    73       $filename = ENANO_ROOT . '/files/' . $row['img_filename'];
    75       $filename = ENANO_ROOT . '/files/' . $row['img_filename'];
    74       $ext = get_file_extension($filename);
    76       $ext = get_file_extension($filename);
    75       switch($ext)
    77       switch($ext)
   107   
   109   
   108   header('Content-type: '   . $mimetype);
   110   header('Content-type: '   . $mimetype);
   109   header('Content-length: ' . strlen($contents));
   111   header('Content-length: ' . strlen($contents));
   110   header('Last-Modified: '  . date('r', $row['img_time_mod']));
   112   header('Last-Modified: '  . date('r', $row['img_time_mod']));
   111   
   113   
       
   114   if ( isset($_GET['download']) )
       
   115   {
       
   116     // determine an appropriate non-revealing filename
       
   117     $filename = str_replace(' ', '_', $row['img_title']);
       
   118     $filename = preg_replace('/([^\w\._-]+)/', '-', $filename);
       
   119     $filename = trim($filename, '-');
       
   120     $filename .= ".$ext";
       
   121     header('Content-disposition: attachment; filename=' . $filename);
       
   122   }
       
   123   
   112   echo $contents;
   124   echo $contents;
       
   125   
       
   126   gzip_output();
       
   127   
       
   128   $db->close();
       
   129   exit;
   113   
   130   
   114 }
   131 }
   115 
   132 
   116 ?>
   133 ?>