Просмотр файла ViPTurbo 3.0/files/preview.php

Размер файла: 2.15Kb
<?
require('../include/path.php');
require($path.'/manage/ctype.php');
require($path.'/files/image_type.php');

if(isset($_GET['name']) && !preg_match('/[^a-z0-9_-]/',$_GET['name']) && isset($_GET['exp']) && array_key_exists($_GET['exp'], $ctype)){

if(preview($_GET['exp'])){

$exp=$_GET['exp'];

if(file_exists($path.'/files/thumbnails/'.$exp.'/'.$_GET['name'].'.'.$exp)){
  
 header('Content-Length: '.filesize($path.'/files/thumbnails/'.$exp.'/'.$_GET['name'].'.'.$exp));
 header('Content-Type: '.$ctype[$exp]);
 header('Content-Disposition: attachment; filename='.$_GET['name'].'.'.$exp);
 readfile($path.'/files/thumbnails/'.$exp.'/'.$_GET['name'].'.'.$exp);

}else{

$f=$path.'/files/'.$exp.'/'.$_GET['name'].'.'.$exp;

switch ($exp){
  case 'jpg':
  $src = imagecreatefromjpeg($f);
  break;
  case 'gif':
  $src = imagecreatefromgif($f);
  break;
  case 'png':
  $src = imagecreatefrompng($f);
  break;
}

$w_src = imagesx($src); 
$h_src = imagesy($src);

$w=64; $h=64; $q=96; // параметры preview картинки

if($w_src>$h_src) {
  $ratio = $w_src/$w; 
}else{
  $ratio = $h_src/$h; 
}

// вычисление пропорций 
 
$w_dest = round($w_src/$ratio); 
$h_dest = round($h_src/$ratio); 

// создаём пустую картинку 
$dest = imagecreatetruecolor($w_dest,$h_dest); 

imagecopyresized($dest, $src, 0, 0, 0, 0, $w_dest, $h_dest, $w_src, $h_src); 
     
switch ($exp){
  case 'jpg':
  imagejpeg($dest,$path.'/files/thumbnails/jpg/'.$_GET['name'].'.jpg',$q);
  break;
  case 'gif':
  imagegif($dest,$path.'/files/thumbnails/gif/'.$_GET['name'].'.gif');
  break;
  case 'png':
  imagepng($dest,$path.'/files/thumbnails/png/'.$_GET['name'].'.png');
  break;
}
     
ob_start();

switch ($exp){
  case 'jpg':
  imagejpeg($dest,"",$q);
  break;
  case 'gif':
  imagegif($dest);
  break;
  case 'png':
  imagepng($dest);
  break;
}

$temp1=ob_get_length();
$temp2=ob_get_contents();
ob_end_clean();

header('Content-Length: '.$temp1);
header('Content-Type: '.$ctype[$exp]);
header('Content-Disposition: attachment; filename='.$_GET['name'].'.'.$exp);

echo $temp2;

imagedestroy($dest); 
imagedestroy($src); 

}

}

}
?>