Location: PHPKode > projects > BuzzyWall > buzzywallSETUP/upresize.php
<?php

if(isset($_POST['submit']))
	{
	
	$user_name  =	$_POST['user_name'];
		$email  =	$_POST['email'];
		$url  =	$_POST['url'];
		$cat_id  =	$_POST['cat_id'];
		$title  =	$_POST['title'];
		$description  =	$_POST['description'];
		$keyword = $_POST['keyword'];
include("db_connect.php");

$resultx = @mysql_query("SELECT * FROM bw_categories WHERE link_name='".$cat_id."';");
$datax = @mysql_fetch_array($resultx);

$category = $datax['category'];

$resulty = @mysql_query("SELECT * FROM bw_categories WHERE id='".$datax['superior']."';");
$datay = @mysql_fetch_array($resulty);

$resultz = @mysql_query("SELECT * FROM bw_main ORDER BY wp_id DESC LIMIT 1;");
$dataz = @mysql_fetch_array($resultz);
$recent_id = $dataz['wp_id']+1;


$wp_link_cat = $datay['link_name'];


$wp_link_img = $title;
for($i=0;$i<strlen($title);$i++){
	if($title[$i]==" ")
		$wp_link_img[$i]="-";
}

$wp_link_img=$wp_link_img."-".$recent_id;
		
		//make sure this directory is writable!
		$path_thumbs = "wallpapers/thumbs";
		$path_big = "wallpapers/full";
		//the new width of the resized image, in pixels.
		$img_thumb_width = 120; // 

		$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['imgfile']['type'];
        $file_name = $_FILES['imgfile']['name'];
        $file_size = $_FILES['imgfile']['size'];
        $file_tmp = $_FILES['imgfile']['tmp_name'];

        //check if you have selected a file.
        if(!is_uploaded_file($file_tmp)){
           echo "Error: Please select a file to upload!. <br>--<a href=\"$_SERVER[PHP_SELF]\">back</a>";
           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.  <br>--<a href=\"$_SERVER[PHP_SELF]\">back</a>";
          exit();
       }
       //so, whats the file's extension?
       $getExt = explode ('.', $file_name);
       $file_ext = "jpg";

       //create a random file name
       $rand_name = md5(time());
       $rand_name= rand(0,999999999);
       //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;
           }
           //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
	      $thumby = "_thumb";
           ImageJpeg ($resized_img,"$path_thumbs/$rand_name$thumby.$file_ext",85);
           ImageDestroy ($resized_img);
           ImageDestroy ($new_img);
           move_uploaded_file ($file_tmp, "$path_big/$rand_name.$file_ext");
           
        }

        //ok
		move_uploaded_file ($file_tmp, "$path_big/$rand_name.$file_ext");
		$image = "$rand_name";


  $in_query = "INSERT into bw_main VALUES (NULL,'$image','$user_name ','$email','$url','$category','$title','$description','$keyword','0','1','$wp_link_cat','$cat_id','$wp_link_img','$wb_upgst','0'); ";
  if($adding = @mysql_query($in_query))
  
	//exit();
	
		
		//and you should be set!
             
		//success message, redirect to main page.	
?> 
<td width="80%" valign="top">

 <?php  

echo "<br /><br /><br /><center><font face='verdana'>Thank You $user_name for submitting the wallpaper.The information has been stored in our database.</font></center><br />";
echo "<center><img src=\"$path_thumbs/$rand_name$thumby.$file_ext\" /></center><br />";
echo "<center><a href='admin/add_wallp.php'><font face='verdana'>Upload another?</font></a></center>";
?>
</td>
<?	


}
else{
	
echo "<b><center>ERROR IN SUBMISSION</center></b>" ;

}

?>
Return current item: BuzzyWall