include_once "includes/dbConn.php";
include_once "includes/loggedOnPop.php";
if( $_REQUEST["theAction"] == "updateIt" ){
$sql = "UPDATE photos SET Caption = '" . ereg_replace("'","´",$_REQUEST['caption']) . "' WHERE User_ID = '" . $_SESSION['sessionUserID'] . "' AND ID = '" . $_REQUEST['picID'] . "' ";
$result = MySQL($dbName,$sql) or die(mysql_error());
}
if( $_REQUEST["theAction"] == "delete" ){
//GET FILE NAME TO DELETE
$SelectStr = "SELECT * FROM photos where User_ID = '" . $_SESSION['sessionUserID'] . "' AND ID = '" . $_REQUEST['picID'] . "' ";
$result = MySQL($dbName,$SelectStr) or die(mysql_error());
IF($myrow=MySQL_fetch_array($result)){
$image = $myrow["Image"];
}
unlink("userPhotos/images/" . $image);
unlink("userPhotos/tiny/" . $image);
unlink("userPhotos/thumbnails/" . $image);
$sql = "DELETE FROM photos WHERE User_ID = '" . $_SESSION['sessionUserID'] . "' AND ID = '" . $_REQUEST['picID'] . "' ";
$result = MySQL($dbName,$sql) or die(mysql_error());
}
//***************************************************
//insert photo1
//***************************************************
if( $_FILES['Photo1']['name'] > " ")
{
//make sure this directory is writable!
$path_thumbs = "userPhotos/thumbnails/";
//the new width of the resized image, in pixels.
$img_thumb_width = 90; //
$extlimit = "yes"; //Limit allowed extensions? (no for all extensions allowed)
//List of allowed extensions if extlimit = yes
$limitedext = array(".gif",".jpg",".png",".jpeg",".bmp");
//the image -> variables
$file_type = $_FILES['Photo1']['type'];
$file_name = $_FILES['Photo1']['name'];
$file_size = $_FILES['Photo1']['size'];
$file_tmp = $_FILES['Photo1']['tmp_name'];
//check the file's extension
$ext = strrchr($file_name,'.');
$ext = strtolower($ext);
//uh-oh! the file extension is not allowed!
if (($extlimit == "yes") && (!in_array($ext,$limitedext))) {
echo "Wrong file extension.
--back";
exit();
}
//so, whats the file's extension?
$getExt = explode ('.', $file_name);
$file_ext = $getExt[count($getExt)-1];
//create a random file name
$rand_name_ext = md5(time());
$rand_name_ext = rand(0,999999999);
$rand_name = $_SESSION['sessionUserID'] . "-" . $rand_name_ext;
//the new width variable
$ThumbWidth = $img_thumb_width;
/////////////////////////////////
// CREATE THE THUMBNAIL //
////////////////////////////////
//keep image type
if($file_size){
if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){
$new_img = imagecreatefromjpeg($file_tmp);
}elseif($file_type == "image/x-png" || $file_type == "image/png"){
$new_img = imagecreatefrompng($file_tmp);
}elseif($file_type == "image/gif"){
$new_img = imagecreatefromgif($file_tmp);
}
//list the width and height and keep the height ratio.
list($width, $height) = getimagesize($file_tmp);
//calculate the image ratio
$imgratio=$width/$height;
if ($imgratio>1){
$newwidth = $ThumbWidth;
$newheight = $ThumbWidth/$imgratio;
}else{
$newheight = $ThumbWidth;
$newwidth = $ThumbWidth*$imgratio;
}
//make sure the image is big enough to resize
if (($newwidth > $width) || ($newheight > $height) ){
$newwidth = $width;
$newheight = $height;
}
//function for resize image.
if (function_exists(imagecreatetruecolor)){
$resized_img = imagecreatetruecolor($newwidth,$newheight);
}else{
die("Error: Please make sure you have GD library ver 2+");
}
//the resizing is going on here!
imagecopyresampled($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
//finally, save the image
ImageJpeg ($resized_img,"$path_thumbs/$rand_name.$file_ext");
ImageDestroy ($resized_img);
ImageDestroy ($new_img);
}
//make sure this directory is writable!
$path_thumbs = "userPhotos/images/";
//the new width of the resized image, in pixels.
$img_thumb_width = 700; //
$extlimit = "yes"; //Limit allowed extensions? (no for all extensions allowed)
//List of allowed extensions if extlimit = yes
$limitedext = array(".gif",".jpg",".png",".jpeg",".bmp");
//the image -> variables
$file_type = $_FILES['Photo1']['type'];
$file_name = $_FILES['Photo1']['name'];
$file_size = $_FILES['Photo1']['size'];
$file_tmp = $_FILES['Photo1']['tmp_name'];
//check if you have selected a file.
if(!is_uploaded_file($file_tmp)){
echo "Error: Please select a file to upload2!.
--back";
exit(); //exit the script and don't process the rest of it!
}
//check the file's extension
$ext = strrchr($file_name,'.');
$ext = strtolower($ext);
//uh-oh! the file extension is not allowed!
if (($extlimit == "yes") && (!in_array($ext,$limitedext))) {
echo "Wrong file extension.
--back";
exit();
}
//so, whats the file's extension?
$getExt = explode ('.', $file_name);
$file_ext = $getExt[count($getExt)-1];
//create a random file name
//$rand_name_ext = md5(time());
//$rand_name_ext = rand(0,999999999);
//$rand_name = $_SESSION['sessionUserID'] . "-" . $rand_name_ext;
//the new width variable
$ThumbWidth = $img_thumb_width;
/////////////////////////////////
// CREATE THE THUMBNAIL //
////////////////////////////////
//keep image type
if($file_size){
if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){
$new_img = imagecreatefromjpeg($file_tmp);
}elseif($file_type == "image/x-png" || $file_type == "image/png"){
$new_img = imagecreatefrompng($file_tmp);
}elseif($file_type == "image/gif"){
$new_img = imagecreatefromgif($file_tmp);
}
//list the width and height and keep the height ratio.
list($width, $height) = getimagesize($file_tmp);
//calculate the image ratio
$imgratio=$width/$height;
if ($imgratio>1){
$newwidth = $ThumbWidth;
$newheight = $ThumbWidth/$imgratio;
}else{
$newheight = $ThumbWidth;
$newwidth = $ThumbWidth*$imgratio;
}
//make sure the image is big enough to resize
if (($newwidth > $width) || ($newheight > $height) ){
$newwidth = $width;
$newheight = $height;
}
//function for resize image.
if (function_exists(imagecreatetruecolor)){
$resized_img = imagecreatetruecolor($newwidth,$newheight);
}else{
die("Error: Please make sure you have GD library ver 2+");
}
//the resizing is going on here!
imagecopyresampled($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
//finally, save the image
ImageJpeg ($resized_img,"$path_thumbs/$rand_name.$file_ext");
ImageDestroy ($resized_img);
ImageDestroy ($new_img);
}
//make sure this directory is writable!
$path_thumbs = "userPhotos/tiny";
//the new width of the resized image, in pixels.
$img_thumb_width = 78; //
$extlimit = "yes"; //Limit allowed extensions? (no for all extensions allowed)
//List of allowed extensions if extlimit = yes
$limitedext = array(".gif",".jpg",".png",".jpeg",".bmp");
//the image -> variables
$file_type = $_FILES['Photo1']['type'];
$file_name = $_FILES['Photo1']['name'];
$file_size = $_FILES['Photo1']['size'];
$file_tmp = $_FILES['Photo1']['tmp_name'];
//check if you have selected a file.
if(!is_uploaded_file($file_tmp)){
echo "Error: Please select a file to upload2!.
--back";
exit(); //exit the script and don't process the rest of it!
}
//check the file's extension
$ext = strrchr($file_name,'.');
$ext = strtolower($ext);
//uh-oh! the file extension is not allowed!
if (($extlimit == "yes") && (!in_array($ext,$limitedext))) {
echo "Wrong file extension.
--back";
exit();
}
//so, whats the file's extension?
$getExt = explode ('.', $file_name);
$file_ext = $getExt[count($getExt)-1];
//create a random file name
//$rand_name_ext = md5(time());
//$rand_name_ext = rand(0,999999999);
//$rand_name = $_SESSION['sessionUserID'] . "-" . $rand_name_ext;
//the new width variable
$ThumbWidth = $img_thumb_width;
/////////////////////////////////
// CREATE THE THUMBNAIL //
////////////////////////////////
//keep image type
if($file_size){
if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){
$new_img = imagecreatefromjpeg($file_tmp);
}elseif($file_type == "image/x-png" || $file_type == "image/png"){
$new_img = imagecreatefrompng($file_tmp);
}elseif($file_type == "image/gif"){
$new_img = imagecreatefromgif($file_tmp);
}
//list the width and height and keep the height ratio.
list($width, $height) = getimagesize($file_tmp);
//calculate the image ratio
$imgratio=$width/$height;
if ($imgratio>1){
$newwidth = $ThumbWidth;
$newheight = $ThumbWidth/$imgratio;
}else{
$newheight = $ThumbWidth;
$newwidth = $ThumbWidth*$imgratio;
}
//make sure the image is big enough to resize
if (($newwidth > $width) || ($newheight > $height) ){
$newwidth = $width;
$newheight = $height;
}
//function for resize image.
if (function_exists(imagecreatetruecolor)){
$resized_img = imagecreatetruecolor($newwidth,$newheight);
}else{
die("Error: Please make sure you have GD library ver 2+");
}
//the resizing is going on here!
imagecopyresampled($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
//finally, save the image
ImageJpeg ($resized_img,"$path_thumbs/$rand_name.$file_ext");
ImageDestroy ($resized_img);
ImageDestroy ($new_img);
}
$sql = "INSERT INTO photos (User_ID, Image, Caption) values ( '" . $_SESSION['sessionUserID'] . "', '$rand_name.$file_ext', '" . ereg_replace("'","´",$_REQUEST['Caption1']) . "')";
$result = MySQL($dbName,$sql) or die(mysql_error());
}
//end of photo1
?>
![]() view my photos |
|
|||||