"; if(!empty($exif['Orientation'])) { $ort=$exif['Orientation']; } elseif(!empty($exif['IFD0']['Orientation'])) { $ort=$exif['IFD0']['Orientation']; } else { $ort=1; } $fp = fopen("debug2.txt", "a"); fwrite($fp, "---------------------------------------------- \n \n started \n"); fwrite($fp, "file is $file and ort is $ort \n"); switch($ort) { case 1: $do = 'nothing'; break; case 2: $do = 'horizontal flip'; flipImage($file, MIRROR_HORIZONTAL); $k++; break; case 3: $do = '180 rotate left'; rotateImage($file, 180); $k++; break; case 4: $do = 'vertical flip'; flipImage($file, MIRROR_VERTICAL); $k++; break; case 5: $do = 'vertical flip + 90 rotate right'; flipImage($file, MIRROR_VERTICAL); rotateImage($file, -90); $k++; break; case 6: $do = '90 rotate right'; rotateImage($file, -90); $k++; break; case 7: $do = 'horizontal flip + 90 rotate right'; flipImage($file, MIRROR_HORIZONTAL); rotateImage($file, -90); $k++; break; case 8: $do = '90 rotate left'; rotateImage($file, 90); $k++; break; } }//end of function fix rotation ///END OF IMAGE ROTATION CODE BASED ON EXIF require_once("config.php"); connect(); $ulSubDomain="img1"; $redirectkey=strip_tags($_REQUEST['redirectkey']); $action=strip_tags($_REQUEST['action']); $fp = fopen("debug2.txt", "a"); fwrite($fp, "---------------------------------------------- \n \n started \n"); fwrite($fp, "redirectkey is $redirectkey \n"); $sQuery = "SELECT * FROM ziptemp WHERE redirectkey='$redirectkey'"; $sQueryresult = mysql_query($sQuery); while(($sRow = mysql_fetch_array($sQueryresult))) { $title=addslashes(strip_tags($sRow[title])); $email=addslashes(strip_tags($sRow[email])); $password=addslashes(strip_tags($sRow[password])); $description=addslashes(strip_tags($sRow[description])); $linkback=addslashes(strip_tags($sRow[linkback])); $referredBy=addslashes(strip_tags($sRow[referredby])); $userid=$sRow[userid]; $found=1; } if($found<>1) { die("hack attempt recorded");//if the redirect key is not found in the ziptemp table then an step1.html hasnt been loaded, someone is trying to add images to an existing gallery maliciously } $sQuery = "SELECT * FROM gallery WHERE redirectkey='$redirectkey'";//gallery already created, this is not the first file upload. $sQueryresult = mysql_query($sQuery); while(($sRow = mysql_fetch_array($sQueryresult))) { $title=$sRow[title]; $email=$sRow[email]; $password=$sRow[password]; $description=$sRow[description]; $linkback=$sRow[linkback]; $referredBy=$sRow[referredby]; $rndkey=$sRow[rndkey]; $galleryid=$sRow[id]; $foundG=1; } if($foundG<>1)//gallery not yet in database this must be the first file upload, create the gallery { $theIP = getenv("REMOTE_ADDR"); $theDate=TIME(); $rndkey=rand(999,9999999); $query="INSERT INTO gallery(id, title, description, password, ipaddress, uploaded, linkback, rndkey, email, redirectkey, referredby, userid) values('', '$title', '$description', '$password', '$theIP', '$theDate', '$linkback', '$rndkey', '$email', '$redirectkey', '$referredBy', '$userid')"; if(! mysql_query($query)) { die("error 1"); } //execute the query $galleryid=mysql_insert_id(); } if($action=="upload") { $file=$_FILES['Filedata']['name']; //print "file is $file
"; $fullFilePath=$_FILES['Filedata']['tmp_name'];//$tempDirectory . "/" . $file; $filetype=strtolower(strrchr($file, '.'));//grab the file extension fwrite($fp, "file is $file, filetype is $filetype, fullFilePath is $fullFilePath \n"); if($filetype==".jpg" || $filetype==".jpeg" || $filetype==".png" || $filetype==".png") { srand((double)microtime()*1000000); $temp1 = rand(9,99); $temp2 = date("zHis"); $folder= date("n"); $originalFile="images/main/$folder/$temp2$temp1-orig"; $mainFile="images/main/$folder/$temp2$temp1"; $thumbFile="images/thumb/$folder/$temp2$temp1"; $send=""; $jpg=0; //$fileMime=system('file -ib '. $fullFilePath); $parts = getimagesize($fullFilePath); $fileMime=$parts['mime']; if($fileMime=="image/pjpg" || $fileMime=="image/pjpeg" || $fileMime=="image/jpeg" || $fileMime=="image/jpeg" || $fileMime=="image/jfif" || $fileMime=="image/pjfif") { $jpg=1; $type="jpg"; $allowedFileType=1; $filename="$originalFile.jpg"; copy ($fullFilePath, $filename) or die ("couldnot copy"); //fix_rotation($filename); } if($fileMime=="image/gif") { $allowedFileType=1; $filename="$originalFile.gif"; $type="gif"; copy ($fullFilePath, $filename) or die ("couldnot copy"); } if($fileMime=="image/png" || $fileMime=="image/x-png") { $allowedFileType=1; $filename="$originalFile.png"; $type="png"; copy ($fullFilePath, $filename) or die ("couldnot copy"); } $filenameThumb="$thumbFile.$type"; switch ($type) { case "jpg" : $src_img=imagecreatefromjpeg($filename); break; case "gif" : $src_img=imagecreatefromgif($filename); break; case "png" : $src_img=imagecreatefrompng($filename); break; default : break; } $thumbWidth=160; $thumbHeight=120; $oldWidth=imageSX($src_img); $oldHeight=imageSY($src_img); $factorWidth=$oldWidth/$thumbWidth; $factorHeight=$oldHeight/$thumbHeight; if($factorWidth>$factorHeight) { $smallestFactor=$factorHeight; } else { $smallestFactor=$factorWidth; } $cropWidth=$thumbWidth*$smallestFactor; $cropHeight=$thumbHeight*$smallestFactor; $xStart=($oldWidth-$cropWidth)/2; $yStart=($oldHeight-$cropHeight)/3.5; $dst_img=ImageCreateTrueColor($thumbWidth,$thumbHeight); imagecopyresampled($dst_img,$src_img,0,0,$xStart,$yStart,$thumbWidth,$thumbHeight,$cropWidth,$cropHeight); switch ($type) { case "jpg" : imagejpeg($dst_img,$filenameThumb); break; case "gif" : imagegif($dst_img,$filenameThumb); break; case "png" : imagepng($dst_img,$filenameThumb); break; default : break; } if($oldWidth>861 || $oldHeight>570) { if($oldHeight>$oldWidth) { $factorthumb=$oldHeight/570; } else { $factorthumb=$oldWidth/850; } $new_xthumb=$oldWidth/$factorthumb; $resizedWidth=$new_xthumb; $new_ythumb=$oldHeight/$factorthumb; $resizedHeight=$new_ythumb; $dst_img2=ImageCreateTrueColor($new_xthumb,$new_ythumb); imagecopyresampled($dst_img2,$src_img,0,0,0,0,$new_xthumb,$new_ythumb,$oldWidth,$oldHeight); $filenameResized="$mainFile.$type"; switch ($type) { case "jpg" : imagejpeg($dst_img2,$filenameResized); break; case "gif" : imagegif($dst_img2,$filenameResized); break; case "png" : imagepng($dst_img2,$filenameResized); break; default : break; } } else { $filenameResized="";// a resized pic was not made because original was less than 900 pixels.. so dont put it in db } imagedestroy($dst_img); @imagedestroy($dst_img2); imagedestroy($src_img); if ($allowedFileType!==1) { $checkType=$_FILES['Filedata']['type']; $error=1; } fwrite($fp, "error = $error \n"); if(empty($error))//no error code so add the data to the database. { fwrite($fp, "got inside no errors IF \n"); $name=$file; $name=strrev($name); $name=strstr($name, "."); $name=substr($name,1); $name=strrev($name); $name=strip_tags($name);//strip any html and php tags from the title //$name = str_replace(" ", "-", $name);//replace spaces with - so that URLS dont break //strip bad characters that cause URL errors $badchars = array("'", "@", "!", "#", "$", "%", "^", "&", "*", "(", ")", "<", ">", "[", "]", "{", "}",",","?",":",";","~","+","/","\\", "="); $name = str_replace($badchars, "", $name); //replace foreigh characters with the english equiv $aChars=array("à", "À", "á", "Á", "â", "Â", "ã", "Ã", "å", "Å"); $cChars=array("ç", "Ç"); $eChars=array("è", "È", "é", "É", "ê", "Ê", "ë", "Ë"); $iChars=array("ì", "Ì", "í", "Í", "î", "Î", "ï", "Ï"); $nChars=array("ñ", "Ñ"); $oChars=array("ò","Ò","ó","Ó","ô","Ô","õ","Õ","ö","Ö","ø","Ø"); $uChars=array("ù","Ù","ú","Ú","û","Û","ü","Ü"); $yChars=array("ý","Ý","ÿ"); $name = str_replace($aChars, "a", $name); $name = str_replace($cChars, "c", $name); $name = str_replace($eChars, "e", $name); $name = str_replace($iChars, "i", $name); $name = str_replace($nChars, "n", $name); $name = str_replace($oChars, "o", $name); $name = str_replace($uChars, "u", $name); $name = str_replace($yChars, "y", $name); $name=str_replace("_Thumbnail1","",$name); $theIP = getenv("REMOTE_ADDR"); fwrite($fp, "got to before image insert query \n"); $query="INSERT INTO images(id, name, server, thumbnail, main, original, galleryid, rndkey, originalheight, originalwidth, resizedheight, resizedwidth) values('', '$name', '$ulSubDomain', '$filenameThumb', '$filenameResized', '$filename', '$galleryid', '$rndkey', '$oldHeight', '$oldWidth', '$resizedHeight', '$resizedWidth')"; if(! mysql_query($query)) { die("error 123"); } //execute the query fwrite($fp, "got after image insert query \n"); }//end of empty error //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// }//end of filetype check. }//end of action==upload IF elseif($action=="complete") { $query="DELETE FROM ziptemp WHERE redirectkey='$redirectkey'"; if(! mysql_query($query)) { die("error 1"); } //execute the query } mysql_close(); echo "1"; ?>