ACC SHELL

Path : /srv/www/vhosts/vaszahradnik/old/php/
File Upload :
Current File : /srv/www/vhosts/vaszahradnik/old/php/img.php

<?php
if (!$fil) $fil = $_GET['filename'];
 $realwidth = $_GET['width'];

 $quality = $_GET['quality'];
$httppath = $_SERVER['HTTP_HOST']; #для очистки абсолютного пути в ИЕ
$scriptname=$_SERVER['SCRIPT_NAME'];
$scriptname=str_ireplace('engine/resizeimg.php','',$scriptname);

$fil=str_ireplace($httppath,'',$fil);      #сделать путь - достройку глобальной переменной..
# $fil=str_ireplace($scriptname,'',$fil); #local = off!!!!

$fil=str_ireplace('http://','',$fil);


$fil=str_replace('www.','',$fil);
$fil=str_replace('lores','hires',$fil);
$crc=md5($fil.$realwidth.$quality);




$header='';
$n_add=0;




$filbuf=$fil;

if (strstr($fil,'[-'))
{
$filbuf=substr($fil,0, strpos($fil,'[-')).substr($fil,strpos($fil,'-]')+2);
}



if (strstr($fil,'.jpg'))
 {
$imgtype="jpeg";
 }
 elseif (strstr($fil,'.gif'))
 {
$imgtype="gif";
 }
 elseif (strstr($fil,'.png'))
 {
$imgtype="png";
 }
  elseif (strstr($fil,'.wbm'))
 {
$imgtype="WBMP";
 }
 else
 {
  exit;#error
 }

#+++++++++++++++++++CACHE+++++++++++++++++++

if (file_exists("cache/$crc")&&(filemtime('cache/'.$crc)>filemtime($filbuf))) # Если файл есть и сохранен позже оригинала
{
if ($imgtype=="jpeg")
{   header("Content-type: image/jpeg");
} else if ($imgtype=="WBMP")
{   header("Content-type: image/vnd.wap.wbmp");
} else
{
     header("Content-type: image/png");
}
$fl=Fopen("cache/$crc",'r');
$str=Fread($fl,@filesize("cache/$crc"));
echo $str;
exit();
}

#+++++++++++++++++++END OF CACHE+++++++++++++++++++

if (strstr($fil,'[-'))
{
$header=substr($fil, strpos($fil,'[-')+2,strpos($fil,'-]')-strpos($fil,'[-')-2);
$header=str_replace("*","\\",$header);
$header=strtoupper($header);

$fil=$filbuf;
}


$loadfunction="imagecreatefrom". $imgtype;

$im=$loadfunction($fil);

$width = imagesx($im);
$height = imagesy($im);

$k=$realwidth/$width;

$n_width = max ($realwidth, 1);
$n_height =max ($height*$k, 1);

if ($header){ $n_add=$n_width+20*$k+50*$k*strlen($header);}

$im_p = imagecreatetruecolor($n_width+$n_add, $n_height);

$ct = imagecolortransparent($im);
if ($ct>=0){$ct = imagecolorsforindex($im,$ct);
$ct2 = imagecolorexact($im_p, $ct['red'], $ct['green'], $ct['blue']);
imagecolortransparent($im_p, $ct2);
imagefill($im_p,0,0,$ct2);}

imagecopyresampled($im_p, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height);
if ($header){
imagecopyresampled($im_p, $im,  $n_width, 0,  $width-1, 0, $n_add+100 , $n_height, 1, $height);
imagestring($im_p, 6*$k, $n_width+10*$k,32*$k,$header,1);
}



ob_start ();

if ($imgtype=="jpeg")
{   header("Content-type: image/jpeg");
	imagejpeg($im_p, null, $quality);
} else if ($imgtype=="WBMP")
{   header("Content-type: image/vnd.wap.wbmp");
	imageWBMP($im_p, null, $quality);
} else
{
     header("Content-type: image/png");
     imagepng($im_p);
}
#++++++++++++++++++++++++++++++++++++++

$cache = ob_get_contents();
ob_end_clean ();
echo $cache;

$fp = @fopen ("cache/$crc", "w");
@fwrite ($fp, $cache);
@fclose ($fp);


?>

ACC SHELL 2018