155 lines
5.5 KiB
PHP
155 lines
5.5 KiB
PHP
<?php if ( !defined('PATHTOINCLUDES') ) define('PATHTOINCLUDES', $_SERVER["DOCUMENT_ROOT"] . '/include/analytics/');
|
|
include(PATHTOINCLUDES."base.php");
|
|
date_default_timezone_set('UTC');
|
|
// A list of permitted file extensions
|
|
$allowed = array('png', 'jpg', 'jpeg', 'gif');
|
|
if(isset($_FILES['upl']) && $_FILES['upl']['error'] == 0){
|
|
$dbcon=dbconnect2();
|
|
//$sql="Delete FROM `community_user_ads`";
|
|
//$query=mysql_query($sql);
|
|
// check number of ads uploaded by customer
|
|
$em="";
|
|
$sql="SELECT count(`hcidu`) FROM `halloween_contest` WHERE `halloween_contest`.`hcapproved` <> 'no' AND `hcuid` = ".$_SESSION["cp_userid"];
|
|
$query=mysql_query($sql) or $em=$em.mysql_error();
|
|
$row=mysql_fetch_row($query);
|
|
$countofads=$row[0];
|
|
if($countofads >= 1)
|
|
{
|
|
$tmpfile=$_FILES['upl']['tmp_name'];
|
|
@unlink($_FILES['upl']['tmp_name']);
|
|
$isgone=file_exists($tmpfile);
|
|
echo '{"status":"Error: You have exceeded the limit of 3 image uploads.","imgurl":"","iwidth":"","iheight":"","badurl":"", "img":"", "extension":"","hcid":""}';
|
|
exit();
|
|
}
|
|
//check image extention
|
|
$extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION);
|
|
if(!in_array(strtolower($extension), $allowed)){
|
|
$tmpfile=$_FILES['upl']['tmp_name'];
|
|
@unlink($_FILES['upl']['tmp_name']);
|
|
$isgone=file_exists($tmpfile);
|
|
echo '{"status":"Error: Please upload a jpg, gif, or png file !","imgurl":"","iwidth":"","iheight":"","thecount":"","badurl":"", "img":"", "extension":"","hcid":""}';
|
|
exit();
|
|
}
|
|
// check size of image
|
|
$thesize=$_FILES['upl']['size'];
|
|
if($thesize > 5000000)
|
|
{
|
|
$tmpfile=$_FILES['upl']['tmp_name'];
|
|
@unlink($_FILES['upl']['tmp_name']);
|
|
$isgone=file_exists($tmpfile);
|
|
echo '{"status":"Error: Image file size exceeds 5MB !","imgurl":"","iwidth":"","iheight":"","thecount":"","badurl":"", "img":"", "extension":"","hcid":""}';
|
|
exit();
|
|
}
|
|
|
|
|
|
|
|
$updir=dirname( __FILE__ );
|
|
$updir=$updir."/uploads/".$_SESSION["cp_userid"];
|
|
$imgurl="/mini-upload-form/uploads/".$_SESSION["cp_userid"]."/".$_FILES['upl']['name'];
|
|
$ipath="/mini-upload-form/uploads/".$_SESSION["cp_userid"];
|
|
$imgpath=$updir."/".$_FILES['upl']['name'];
|
|
$imgname=$_FILES['upl']['name'];
|
|
if(!is_dir($updir))
|
|
{
|
|
if(!mkdir($updir,0777)){echo '{"status":"System Error: Please try again. If error persists, please contact <a href=\"http://bateworld.com/help_contact.php\" target=\"_blank\">bateworld customer satisfaction</a> !","imgurl":"","iwidth":"","iheight":"","thecount":"","badurl":,"hcid":""}';exit();}
|
|
}
|
|
if(move_uploaded_file($_FILES['upl']['tmp_name'], $updir."/".$_FILES['upl']['name'])){
|
|
//strip image of Exif data - which can be corrupt
|
|
|
|
// use copy and then create thumbnail
|
|
$iname = pathinfo($imgpath);
|
|
$iname=$iname['filename'];
|
|
|
|
$full=$updir."/".$iname."_full.".$extension;
|
|
$medium=$updir."/".$iname."_medium.".$extension;
|
|
$thumbnail=$updir."/".$iname."_thumbnail.".$extension;
|
|
$image = new Imagick($imgpath);
|
|
$image->stripImage();
|
|
// Writes resultant image to output directory
|
|
//$image->writeImage($full);
|
|
$image->destroy();
|
|
//resize image
|
|
$size = getimagesize($imgpath);
|
|
$owidth=$size[0];
|
|
$oheight=$size[1];
|
|
include("resize-class.php");
|
|
$width=$owidth;
|
|
$height=$oheight;
|
|
|
|
if($owidth > $oheight)
|
|
{
|
|
if($owidth >= 800)
|
|
{
|
|
$resizeObj = new resize($imgpath);
|
|
$resizeObj -> resizeImage(800,800,'landscape');
|
|
$resizeObj -> saveImage($full, 100);
|
|
}
|
|
else
|
|
{
|
|
copy($imgpath, $full);
|
|
}
|
|
$resizeObj = new resize($imgpath);
|
|
$resizeObj -> resizeImage(210,210,'landscape');
|
|
$resizeObj -> saveImage($medium, 100);
|
|
$resizeObj = new resize($imgpath);
|
|
$resizeObj -> resizeImage(100,100,'landscape'); //crop image to 435px width by 220 height
|
|
$resizeObj -> saveImage($thumbnail, 100);
|
|
}
|
|
if($owidth < $oheight || $owidth == $oheight){
|
|
if($owidth >= 800)
|
|
{
|
|
$resizeObj = new resize($imgpath);
|
|
$resizeObj -> resizeImage(800,800,'portrait');
|
|
$resizeObj -> saveImage($full, 100);
|
|
}
|
|
else
|
|
{
|
|
copy($imgpath, $full);
|
|
}
|
|
$resizeObj = new resize($imgpath);
|
|
$resizeObj -> resizeImage(210,210,'landscape'); //crop image to 435px width by 220 height
|
|
$resizeObj -> saveImage($medium, 100);
|
|
$resizeObj = new resize($imgpath);
|
|
$resizeObj -> resizeImage(100,100,'landscape'); //crop image to 435px width by 220 height
|
|
$resizeObj -> saveImage($thumbnail, 100);
|
|
}
|
|
|
|
|
|
|
|
$urlissue=0;
|
|
|
|
// insert image details into database table
|
|
|
|
|
|
$sqlins="INSERT INTO `halloween_contest` (`hcuid`,`hcuname`,`hcemail`,`hcimgurl`,`hcimgwdth`,`hcimgheight`,`hcimagename`,`badurl`,`hc_path`,`hc_name`,`hc_ext`)
|
|
VALUES (
|
|
".$_SESSION["cp_userid"].",
|
|
'".$_SESSION["nickname"]."',
|
|
'".$_SESSION["cp_useremail"]."',
|
|
'".$imgurl."',
|
|
".$width.",
|
|
".$height.",
|
|
'".$imgname."',
|
|
".$urlissue.",
|
|
'".$ipath."',
|
|
'".$iname."',
|
|
'".$extension."')";
|
|
$qins=mysql_query($sqlins) or $em=$em.mysql_error();
|
|
$hcid= mysql_insert_id();
|
|
|
|
|
|
$status="Approval Pending";
|
|
$colorclass="yellow";
|
|
$userad="";
|
|
|
|
|
|
// do nothing on error ???
|
|
echo '{"status":"success","imgurl":"'.$ipath.'","iname":"'.$iname.'","iwidth":"'.$width.'","iheight":"'.$height.'","badurl":"'.$urlissue.'", "img":"'.$iname.'", "extension":"'.$extension.'","hcid":"'.$hcid.'"}';
|
|
|
|
mail("phil@b8world.com", "Halloween Contest Entry", "Nothingtoadd");
|
|
mail("halloween@b8world.com", "Halloween Contest Entry", "Nothingtoadd");
|
|
exit();
|
|
}
|
|
}
|
|
echo '{"status":"error general","imgurl":"","iwidth":"","iheight":"","thecount":"","badurl":"", "img":"", "extension":"","hcid":""}';
|
|
exit(); |