<?php
// Copyright 2001-2004 Interakt Online. All rights reserved.
session_start();
include("../functions.inc.php");
//language resources
include_once("../languages/".((isset($_SESSION['KTML2security'][$_GET['counter']]['language']))? $_SESSION['KTML2security'][$_GET['counter']]['language']:"english").".inc.php");
$ALT_PATH = "../";
require_once("../security.php");
?>
<html>
<head>
<title><?php echo (isset($KT_Messages["Upload Image"])) ? $KT_Messages["Upload Image"] : "Upload Image"; ?></title>
<link href="../styles/main.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?php
if ($secTest && $sessionTest) {
if ($_GET['currentPath'] != "") {
$the_path = __realpath($KT_PATH_VAR."/".urldecode($_GET['currentPath']), 1);
} else {
$the_path = __realpath($KT_PATH_VAR, 1);
}
// array containing permitted mime types
$allowed_types = array(
"image/bmp",
"image/gif",
"image/pjpeg",
"image/jpeg",
"image/png",
"image/x-png",
"audio/x-pn-realaudio",
"audio/mpeg",
"audio/mp3",
"audio/x-wav",
"video/mpeg",
"video/quicktime",
"video/x-msvideo",
"video/x-ms-wmv",
"video/avi",
"application/x-shockwave-flash"
);
$allowed_ext = array("bmp", "gif", "jpeg", "jpg", "jpe", "png", "swf");
// The Laplacian operator radius for image sharpening.
$NWS_Sharpen_radius = 1;
// The standard deviation for image sharpening.
$NWS_Sharpen_sigma = 1;
function validate_upload($the_file, $allowed_types, $allowed_ext) {
$the_file_ext = explode(".", $the_file['name']);
$the_file_ext = $the_file_ext[count($the_file_ext)-1];
$iserror = "";
if (isset($the_file['error'])) {
if ($the_file['error'] == 0) {
if (!in_array($the_file['type'], $allowed_types) || !in_array(strtolower($the_file_ext), $allowed_ext)) {
$iserror = "You cannot upload this file type!!!<br><a href=\"newupload.php?currentPath=".urlencode($_GET['currentPath'])."&counter=" . $_GET['counter'] . "&submode=" . $_GET['submode'] . "\">Press here</a> to go back";
}
} else {
switch ($the_file['error']) {
case 1:
$iserror = "File exceeds global maximum file size !!!<br><a href=\"newupload.php?currentPath=".urlencode($_GET['currentPath'])."&counter=" . $_GET['counter']."&submode=" . $_GET['submode'] ."\">Press here</a> to go back";
break;
case 2:
$iserror = "File exceeds local maximum file size !!!<br><a href=\"newupload.php?currentPath=".urlencode($_GET['currentPath'])."&counter=" . $_GET['counter']."&submode=" . $_GET['submode'] ."\">Press here</a> to go back";
break;
case 3:
$iserror = "File only partial uploaded !!!<br><a href=\"newupload.php?currentPath=".urlencode($_GET['currentPath'])."&counter=" . $_GET['counter']."&submode=" . $_GET['submode'] ."\">Press here</a> to go back";
break;
case 4:
$iserror = "No file !!!<br><a href=\"newupload.php?currentPath=".urlencode($_GET['currentPath'])."&counter=" . $_GET['counter']."&submode=" . $_GET['submode'] ."\">Press here</a> to go back";
break;
}
}
} else {
if ($the_file == "none") {
$iserror = "No file !!!<br><a href=\"newupload.php?currentPath=".urlencode($_GET['currentPath'])."&counter=" . $_GET['counter']."&submode=" . $_GET['submode'] ."\">Press here</a> to go back";
} else {
if (!in_array($the_file['type'], $allowed_types) || !in_array(strtolower($the_file_ext), $allowed_ext)) {
$iserror = "You cannot upload this file type!!!<br><a href=\"newupload.php?currentPath=".urlencode($_GET['currentPath'])."&counter=" . $_GET['counter']."&submode=" . $_GET['submode'] ."\">Press here</a> to go back";
}
}
}
return $iserror;
}
function validate_gd() {
$strret = "";
if (function_exists('ImageTypes')) {
if (@ImageTypes() & IMG_GIF) {
$strret .= " *.gif";
}
if (@ImageTypes() & IMG_PNG) {
$strret .= " *.png";
}
if (@ImageTypes() & IMG_JPG) {
$strret .= " *.jpg";
}
}
}
function my_exec($command) {
$retArray = Array();
exec($command,$retArray);
return implode('',$retArray);
}
function validate_imagick () {
$pos = strpos(my_exec('convert'), 'ImageMagick');
if ($pos === false) {
return 0;
} else {
return 1;
}
}
function ResizeImage ($image, $pathToSave, $newWidth, $newHeight, $imagetype, $sharpen, $keep) {
if (file_exists($pathToSave)) {
$a=unlink($pathToSave);
}
if (!preg_match("#^image/#", $imagetype)) {
return "<br>Image type not recognized : " . $imagetype;
}
$resize = ($newWidth != '' || $newHeight != '');
if($sharpen == '' && !$resize){
if (!move_uploaded_file($image, $pathToSave)) {
return "Could not copy file. Check the path to and the permissions for the upload directory.<br><a href=\"newupload.php?currentPath=".urlencode($_GET['currentPath'])."&counter=" . $_GET['counter']."\">Press here</a> to go back";
}
return "";
}
$gd = false;
if (function_exists("ImageTypes")) {
if ($imagetype == 'image/gif' && @ImageTypes() & IMG_GIF) {
$gd = true;
} elseif (($imagetype == 'image/x-png' || $imagetype == 'image/png') && @ImageTypes() & IMG_PNG) {
$gd = true;
} elseif (($imagetype == 'image/pjpeg' || $imagetype == 'image/jpeg' || $imagetype == 'image/jpg') && @ImageTypes() & IMG_JPG) {
$gd = true;
}
}
if ($sharpen == 0 && $gd) {
switch($imagetype) {
case "image/gif":
$srcImage=@imagecreatefromgif($image['tmp_name']);
break;
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
$srcImage=@imagecreatefromjpeg($image['tmp_name']);
break;
case "image/x-png":
case "image/png":
$srcImage=@imagecreatefrompng($image['tmp_name']);
break;
default:
$srcImage=@imagecreatefromjpeg($image['tmp_name']);
break;
}
if ($srcImage) {
$srcWidth = ImageSX( $srcImage );
$srcHeight = ImageSY( $srcImage );
if ($keep == '1') {
if ($newWidth != '' && $newHeight != '') {
$ratioWidth = $srcWidth/$newWidth;
$ratioHeight = $srcHeight/$newHeight;
if( $ratioWidth < $ratioHeight ){
$destWidth = $newWidth * $srcWidth/$srcHeight;
$destHeight = $newHeight;
} else {
$destWidth = $newWidth;
$destHeight = $srcHeight/$ratioWidth;
}
} else {
if ($newWidth != '') {
$ratioWidth = $srcWidth/$newWidth;
$destWidth = $newWidth;
$destHeight = $srcHeight/$ratioWidth;
} else {
$ratioHeight = $srcHeight/$newHeight;
$destHeight = $newHeight;
$destWidth = $srcWidth/$ratioHeight;
}
}
} else {
$destWidth = $newWidth;
$destHeight = $newHeight;
}
ob_start();
phpinfo(8);
$phpinfo=ob_get_contents();
ob_end_clean();
$phpinfo=strip_tags($phpinfo);
$phpinfo=stristr($phpinfo,"gd version");
$phpinfo=stristr($phpinfo,"version");
$end=strpos($phpinfo,".");
$phpinfo=substr($phpinfo,0,$end);
$length = strlen($phpinfo)-1;
$phpinfo=substr($phpinfo,$length);
if (function_exists('imagecreatetruecolor') && $phpinfo>=2) {
$destImage = @imagecreatetruecolor ($destWidth, $destHeight);
} else {
$destImage = @imagecreate($destWidth, $destHeight);
}
@ImageCopyResized ($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
@ImageJPEG ($destImage, $pathToSave, 90);
@ImageDestroy ($srcImage);
@ImageDestroy ($destImage);
if (file_exists ($pathToSave)) {
return "";
} else {
return "<br>Error writing file to " . $pathToSave . ".<br>Please check folder permissions.<br/><a href=\"newupload.php?currentPath=".urlencode($_GET['currentPath'])."&counter=" . $_GET['counter']."\">Press here</a> to go back";
}
} else {
return "<br>Unidentified GD Error