ACC SHELL

Path : /srv/www/vhosts/unitedsolution/admin/gallery/
File Upload :
Current File : /srv/www/vhosts/unitedsolution/admin/gallery/uploadfiles.php

<?php

/*
    Fce pro resize obrázků
  */
  function resizePhoto($vstup, $vystup, $width, $height, $aspectratio = '1', $quality = '75') {

   	$vstup_wd = imagesx($vstup);
		$vstup_ht = imagesy($vstup);

		if($vstup_wd <= $width && $vstup_ht <= $height) {
			$width = $vstup_wd;
			$height = $vstup_ht;
		}else{

			if($aspectratio) {
				$w = round($vstup_wd * $height / $vstup_ht);
				$h = round($vstup_ht * $width / $vstup_wd);

				if(($height-$h)<($width-$w)){
					$width =& $w;
				} else {
					$height =& $h;
				}
			}
		}

		$temp = imageCreateTrueColor($width,$height);
		imageCopyResampled($temp, $vstup, 0, 0, 0, 0, $width, $height, $vstup_wd, $vstup_ht);
		@Touch($vystup); //kvuli novemu PHP - nelze odkazovat ve funkci ImageJPEG na neexistujici soubor, funkce Touch ho vytvori

    //ulozime obrazek do souboru
    if(ImageJPEG($temp, $vystup, $quality)) {
		  imagedestroy($temp); //uvolnime pamet
		  return true;
    }
		else
		{
      return false; 
		}
	}

echo $dir = substr(dirname($_SERVER['SCRIPT_FILENAME']),0,-14);

$inc_dir = $dir.'/admin/connect.php';

include($inc_dir);
include($dir.'/admin/class/gallery.php');

connect();

$gallery = new gallery;

$gallery->select_settint();

echo 'Upload result:<br>'; // At least one symbol should be sent to response!!!

$uploaddir_1 = $dir.'/g_small/';
$uploaddir_2 = $dir.'/g_foto/';
$uploaddir_3 = $dir.'/g_tiny/';

$target_encoding = "ISO-8859-2";

echo '<pre>';

if(count($_FILES) > 0){

	$arrfile = pos($_FILES);
	
	$filename = time().rand(0,10000);
	
	$filename = $_GET['parent'].'_'.$filename.'.jpg';
	
	move_uploaded_file  ($arrfile['tmp_name'], $dir.'/tmp/'.$filename);
	$arrfile['tmp_name']=$dir.'/tmp/'.$filename;
	chmod ($arrfile['tmp_name'], 777);

	$uploadfile = $uploaddir_1.$filename;
	$uploadfile2 = $uploaddir_2.$filename;
	$uploadfile3 = $uploaddir_3.$filename;
	$name = $filename;
	
	if(file_exists($arrfile['tmp_name'])) {
	
  	$obrazok = imagecreatefromjpeg($arrfile['tmp_name']);

  	resizePhoto($obrazok, $uploadfile3, 40, 40); //tiny img
  	resizePhoto($obrazok, $uploadfile, $gallery->setting['s_width'], $gallery->setting['s_height']); //small img
  	resizePhoto($obrazok, $uploadfile2, 800, 600); //normal img
	
	}
	
	if(file_exists($uploadfile2)){
	
		// end foto
		
		$query = "SELECT MAX(ord) AS max_ord FROM ".DBPREFIX."gallery WHERE parent = '$_GET[parent]'";
		
		$sent = mysql_query($query);
		
		$data = mysql_fetch_object($sent);
		
		$ord = $data->max_ord;
		
		$ord++;
	
		$query = "INSERT INTO ".DBPREFIX."gallery (path,parent,typ,ord) VALUES('$name','$_GET[parent]','2','$ord')";
			
		mysql_query($query);
		
		echo "File is valid, and was successfully uploaded.\n";
	
	}

	// begin image destroy
	
	imagedestroy($obrazok);
	imagedestroy($img);
	imagedestroy($v_img);
	
	// end image destroy
	
}
else{

	echo 'No files sent. Script is OK!'; //Say to Flash that script exists and can receive files

}

echo 'Here is some more debugging info:';

print_r($_FILES);

echo "</pre>";

?>

ACC SHELL 2018