Files
Testing/mini-upload-form/upload_ctp.php
sean 0e8a8b3028
Some checks are pending
deploy-testing / deploy (push) Waiting to run
Initial testing snapshot
2026-11-17 16:15:01 -05:00

192 lines
6.8 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="";
//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/ctp/".$_SESSION["cp_userid"];
$imgurl="/mini-upload-form/uploads/ctp/".$_SESSION["cp_userid"]."/".$_FILES['upl']['name'];
$ipath="/mini-upload-form/uploads/ctp/".$_SESSION["cp_userid"];
$imgpath=$updir."/".$_FILES['upl']['name'];
$imgname=$_FILES['upl']['name'];
$icount=0;
$sqlnc="SELECT Count(`caption_this_pic`.`hcimagename`) AS `incount` FROM `caption_this_pic` WHERE `caption_this_pic`.`hcimagename` = '".$imgname."'";
$querync=mysql_query($sqlnc) or $em=$em.mysql_error();
$icount = mysql_result($querync,0);
mysql_free_result($querync);
if($icount > 0)
{
@unlink($_FILES['upl']['tmp_name']);
echo '{"status":"Error: Duplicate Image Name","imgurl":"","iwidth":"","iheight":"","thecount":"","badurl":"", "img":"", "extension":"","hcid":""}';
exit();
}
if(!is_dir($updir))
{
if(!mkdir($updir,0777)){echo '{"status":"System Error: Please try again.","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 `caption_this_pic` (`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();
$unixtime=time();
$blogdate=gmdate("F d, Y");
$thetitle="Caption This Pic ".$blogdate;
$thebody='<div style="clear:both;display:block;margin-top:38px"><div><h5 style="position: relative;text-align: center;top: -38px;letter-spacing: 0.4em;text-transform: none;font-variant: small-caps;font-weight: bold;font-size: 1em;border-bottom: 1px solid #BBB9B9;margin-bottom: -20px"><span style="color: #FDF8F8;text-decoration: none;font-style: normal;font-size: 0.8em">'.$blogdate.'</span></h5></div><div style="margin-bottom:20px"><img src="'.$imgurl.'" alt="Caption This Pic" style="height: auto;width:100%;max-width:100% !important;border:none" border="0" /></div></div>';
$thebody=htmlspecialchars($thebody, ENT_QUOTES, 'UTF-8');
$sqlins="INSERT INTO `se_blogentries` (
`se_blogentries`.`blogentry_user_id`,
`se_blogentries`.`blogentry_blogentrycat_id`,
`se_blogentries`.`blogentry_date`,
`se_blogentries`.`blogentry_views`,
`se_blogentries`.`blogentry_title`,
`se_blogentries`.`blogentry_body`,
`se_blogentries`.`blogentry_search`,
`se_blogentries`.`blogentry_privacy`,
`se_blogentries`.`blogentry_comments`,
`se_blogentries`.`blogentry_trackbacks`,
`se_blogentries`.`blogentry_totalcomments`,
`se_blogentries`.`blogentry_totaltrackbacks`
)
VALUES
(
70695,
3,
$unixtime,
0,
'".$thetitle."',
'".$thebody."',
0,
31,
31,
'',
0,
0
)";
$queryins=mysql_query($sqlins) or $em=$em.mysql_error();
$blogid= mysql_insert_id();
$sqlbid="UPDATE `caption_this_pic` SET `caption_this_pic`.`blogid` = ".$blogid." WHERE `caption_this_pic`.`hcidu` = ".$hcid;
$querybid=mysql_query($sqlbid) or $em=$em.mysql_error();
$status="Not Active";
$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.'", "icount":"'.$icount.'"}';
mail("phil@b8world.com", "Caption This Pic", "New CTP Created");
exit();
}
}
echo '{"status":"error general","imgurl":"","iwidth":"","iheight":"","thecount":"","badurl":"", "img":"", "extension":"","hcid":""}';
exit();