Location: PHPKode > projects > OpenBizMap > obm2007.1/mydata/script/sys_download.txt
<?php
/*
OpenDataBag - Data Web Interface
Copyright (C) 2004 Nawara

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

$content_type_array=array();
$content_type_array['.gif']['type']='image/gif';
$content_type_array['.gif']['disp']='inline';
$content_type_array['.png']['type']='image/x-png';
$content_type_array['.png']['disp']='attachment';
$content_type_array['jpeg']['type']='image/jpeg';
$content_type_array['jpeg']['disp']='inline';
$content_type_array['.jpg']['type']='image/jpeg';
$content_type_array['.jpg']['disp']='inline';
$content_type_array['.jpe']['type']='image/jpeg';
$content_type_array['.jpe']['disp']='inline';
$content_type_array['tiff']['type']='image/tiff';
$content_type_array['tiff']['disp']='inline';
$content_type_array['.tif']['type']='image/tiff';
$content_type_array['.tif']['disp']='attachment';
$content_type_array['.rgb']['type']='image/rgb';
$content_type_array['.rgb']['disp']='inline';
$content_type_array['.pdf']['type']='application/pdf';
$content_type_array['.pdf']['disp']='attachment';
$content_type_array['.rtf']['type']='application/rtf';
$content_type_array['.rtf']['disp']='inline';
$content_type_array['.odt']['type']='application/vnd.oasis.opendocument.text';
$content_type_array['.odt']['disp']='attachment';



$preview=0+get('preview');
$mark=0+get('mark');
$log=get('log');

if($log)
{
  $content=file_get_contents(cfg_data_path.'/temp/errors/'.$log.'.log');

  header('Content-Type: text');
  header('Content-Disposition: inline; filename="'.$log.'.log"');
  header('Content-Length: '.strlen($content));

  echo $content;
}
else
{
  $field=get('field');
  $variable_name=substr(str_replace('_',' ',substr($field,0,strrpos($field,'_'))),4);
  $sysId=substr($field,strrpos($field,'_')+1);
  


  $line_array=search('sysId='.$sysId.'');

  $variable_array=line2array($line_array[0]);

  reset($variable_array);
  foreach($variable_array as $tmp_variable_name => $tmp)
  {
    if(purename($tmp_variable_name)==$variable_name)
    {
      $variable_name=$tmp_variable_name;
      break;
    }
  }

  $filename=read($line_array[0],$variable_name);
  if(substr($filename,-5)=='.file')
    $filename=substr($filename,0,-5);
  $preamble=substr(purename($filename),0,1).'/'.substr(purename($filename),0,2);
  
  
  //USEREXIT OnDownload
  $userexit='ondownload';
  if(file_exists(cfg_data_path.'/config/userexit/exit_'.$userexit.'.txt'))
  {
    include(cfg_data_path.'/config/userexit/exit_'.$userexit.'.txt');
  }
  else
  {
    include(cfg_data_path.'/script/userexit/exit_'.$userexit.'.txt');
  }
  
  if($preview>0)
  {
    //RESIZE
    $filename1 = cfg_data_path.'/data/files/'.$preamble.'/'.$filename.'.file';
    if(!file_exists($filename1.'.thumb'.$preview))
    {
      list($width, $height) = getimagesize($filename1);

      $new_width=$width;
      $new_height=$height;
      while($new_width>$preview or $new_height>$preview)
      {
        $new_width=$new_width/2;
        $new_height=$new_height/2;
      }

      $thumb = imagecreatetruecolor($new_width, $new_height);
      $source = imagecreatefromjpeg($filename1);
  
      imagecopyresampled($thumb, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
      imagejpeg($thumb,$filename1.'.thumb'.$preview);
    }
  
    $content=file_get_contents($filename1.'.thumb'.$preview);
  
    header('Content-type: image/jpeg');
  
    echo $content;
  
  }
  elseif($mark>0)
  {
    //RESIZE
    $filename1 = cfg_data_path.'/data/files/'.$preamble.'/'.$filename.'.file';
    if(!file_exists($filename1.'.rgb'))
    {
      $source = imagecreatefromjpeg($filename1);
      imagejpeg($source,$filename1.'.rgb');
    }
  
    $content=file_get_contents($filename1.'.rgb');
  
    if(isset($content_type_array[substr($filename,-4)]))
    {
      header('Content-Type: '.$content_type_array[substr($filename,-4)]['type']);
      header('Content-Disposition: '.$content_type_array[substr($filename,-4)]['disp'].'; filename="'.basename($filename).'"');
    }
    else
    {
      header('Content-Type: text/html');
      header('Content-Disposition: attachment; filename="'.basename($filename).'"'); //attachement couses too much dialog boxes /inline
    }
    header('Content-Length: '.strlen($content));
    echo $content;
  }
  else
  {
    addpath(cfg_data_path.'/data/files');
    $content=file_get_contents(cfg_data_path.'/data/files/'.$preamble.'/'.$filename.'.file');
  
  
    if(isset($content_type_array[substr($filename,-4)]))
    {
      header('Content-Type: '.$content_type_array[substr($filename,-4)]['type']);
      header('Content-Disposition: '.$content_type_array[substr($filename,-4)]['disp'].'; filename="'.basename($filename).'"');
    }
    else
    {
      header('Content-Type: '.$content_type_array[substr($filename,-3)]);
      header('Content-Disposition: attachment; filename="'.basename($filename).'"'); //attachement couses too much dialog boxes /inline
    }
    header('Content-Length: '.strlen($content));
  
    echo $content;
  }
}
exit;
?>
Return current item: OpenBizMap