Jump to content

picture upload and resize


angelsRock

Recommended Posts

help me in this code.. i can upload .. but cant get thumbnail.. please hlep..

 

<?php
$server="localhost";
$user="root";
$pass="";
$db="property";
?>

<?php

define ("MAX_SIZE","200"); 

function getExtension($str) 
{    
     $i = strrpos($str,".");   
 if (!$i) { return ""; }     
 $l = strlen($str) - $i;  
 $ext = substr($str,$i+1,$l); 
 return $ext; 
}

$errors=0;

  if(isset($_POST['Submit'])) 
   { 	
   	$image=$_FILES['image']['name']; 	
$yo=$_POST['alain']; 	

	if(!isset($_FILES['image_file'])) 
        	echo'An image was not found.'; 

//if it is not empty 
	if ($image && $yo)  	
	{ 	
		$filename = stripslashes($_FILES['image']['name']); 				
				$extension = getExtension($filename); 	
				$extension = strtolower($extension); 	



		 if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))  	
			{					
				echo '<h1>Unknown extension!</h1>'; 		
				$errors=1; 	
			} 	
		else 	
			{		

				unset($imagename); 
				$connection=mysql_connect($server, $user, $pass);
				if(!$connection)					
					die("Connection failed");		

				else
				{				
				  $size=filesize($_FILES['image']['tmp_name']);			
				  	
					  if ($size > MAX_SIZE*1024)
						  {	
							echo '<h1>You have exceeded the size limit!</h1>';
							$errors=1;
						  }					
						  
					 $image_name=time().'.'.$extension;				
					 $newname="images/".$image_name;	




				if(empty($image_name)) 
				$error["image_name"] = "The name of the image was not found."; 

				if(empty($error)) 
				{ 
					$newimage = "thumbs/" . $image_name; 
					//echo " ".$newimage; 
					$result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage); 
					if(empty($result)) 
						$error["result"] = "There was an error moving the uploaded file."; 
				} 




				 echo "<ul> 
                <li>File Uploaded...</li>"; 
				echo "    <li>Creating Thumbnail...</li>"; 
				$im = imagecreatefromjpeg("thumbs/$image_name" ); 
				$ox = imagesx( $im ); 
				$oy = imagesy( $im ); 

				$nx = 100; 
				$ny = floor( $oy * ( 100 / $ox ) ); 

				$nm = imagecreatetruecolor( $nx, $ny ); 

				imagecopyresized( $nm, $im, 0, 0, 0, 0, $nx, $ny, $ox, $oy ); 

				print "    <li>Creating thumb for $image_name</li>"; 

				imagejpeg( $nm, "thumbs/$image_name" ); 

				echo "    <li>Thumbnail Created...</li>"; 
				echo "    <li>Adding entries into the DB...</li>"; 



					mysql_select_db($db);

						 $query="insert into prem_propertyad(photo1,thumb, package)values('".$image_name."','".$thumbs/$image_name."', '".$yo."' )";
						$result=mysql_query($query);

				if(!$result){ 
							 echo 'There has been an error adding your image. Please contact the webmaster.'; 
        						} 
         
       				 else{ 
        				    echo"</ul>Thank You! Your image has been submitted.<br />You can view it in the art gallery."; 
         				   } 



						$copied = copy($_FILES['image']['tmp_name'], $newname);
						  if (!$copied)
							{	
								echo '<h1>Copy unsuccessfull!</h1>';
								$errors=1;
							}
				 }
			}


	 if(isset($_POST['Submit']) && !$errors) 
	  { 	
		 echo "<h1>File Uploaded Successfully! Try again!</h1>";
		 print("<img src=\"$newname\">");


		 $getpic= mysql_query("select photo1 from prem_propertyad")
		 or die (mysql_error());

		 while ($ros = mysql_fetch_array($getpic)){


		 echo "<td><img src=\"" . $image_name . >"

		 }



	  } 
	}
}


  
  ?>
				   
<form name="newad" method="post" enctype="multipart/form-data"  action="">
	 <table> 
		<tr><td>
			<input type="file" name="image"></td></tr> 	
	 <tr><td>
			<input name="Submit" type="submit" value="Upload image"></td></tr> 

			<tr><td><input type="textbox" name="alain"></td></tr>
	 </table>	 
 </form>

Link to comment
https://forums.phpfreaks.com/topic/66896-picture-upload-and-resize/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.