Make a thumb image

Discussion in 'PHP' started by snowLee, Apr 20, 2009.

  1. #1
    I have this demo on my website , where you login with demo and demo, but when I upload an image the script doesn't make the thumb. I find the original photo in the dir from that profile, but I can't see the error for thumb. I see only the broken link icon for thumb and if you click on that you will see the original image.

    If there is someone who can give me a hand I will appreciate that.

    This is the code for adding images and making thumbs:

    
    <?php
    session_start();
    include "db_connect.php";
    
    if($_SESSION['id'])
    {
    	$sql = "SELECT username FROM `users` WHERE `id`='".$_SESSION['id']."'";
    	$res = mysql_query($sql) or die(mysql_error());
    	
    	if(mysql_num_rows($res) != 1)
    	{
    		session_destroy();
    		echo "<script language=\"Javascript\" type=\"text/javascript\">document.location.href='index.php'</script>";
    	}
    	else
    	{
    	$row = mysql_fetch_assoc($res);
    	
    	$title = protect($_POST['title']);
    	
    	if(!$title)
    	{
    		echo "<script language=\"Javascript\" type=\"text/javascript\">
    				alert(\"You must choose a title for your picture!\")
    				document.location.href='profilecp.php'</script>";
    		
    	}
    	
    	$target = $row['username'];
    	if(!is_dir($target)) @mkdir($target);
    	$target = $target . '/pics';
    	
    	if(!is_dir($target)) @mkdir($target);
    	
    		$target = $target."/".basename($_FILES['pics']['name']) ;
    		$size = $_FILES['pics']['size'];
    		$pic = $_FILES['pics']['name'];
    		$type = $_FILES['pics']['type'];
    							
    			$sql2= "INSERT INTO `user_photos` (`profile_id`,`title`,`size`,`type`,`reference`)
    			VALUES ('".$_SESSION['id']."','$title','$size','$type','$pic'); ";
    			
    			$res2 = mysql_query($sql2) or die(mysql_error());
    
    				if(move_uploaded_file($_FILES['pics']['tmp_name'], $target))
    				{
    					echo "<script language=\"Javascript\" type=\"text/javascript\">
    					alert(\"Your picture has been uploaded\")
    					document.location.href='profilecp.php'</script>";
    				}
    				else
    				{
    					echo "<script language=\"Javascript\" type=\"text/javascript\">
    					alert(\"There was an error, try again\")
    					document.location.href='profilecp.php'</script>";
    				}
    			
    		
    		$target2 = $row['username'];
    		$target2 = $target2 . '/pics';
    		$target2 = $target2 . '/thumbs';
    		if(!is_dir($target2)) @mkdir($target2);
    		$target2 = $target2."/".basename($_FILES['pics']['name']) ;
    		createthumb($target,$target2,150,150);
    		
    	}
    }else echo "<script language=\"Javascript\" type=\"text/javascript\">document.location.href='index.php'</script>";
    
    ?>
    
    
    PHP:

     
    snowLee, Apr 20, 2009 IP
  2. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The code for creating thumbnails is presumably in the function createthumb() which you haven't included here.
     
    SmallPotatoes, Apr 20, 2009 IP
  3. snowLee

    snowLee Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    Thank you.
    That's why didn't work :). I forgot to put it and I was too blind to see that's missing :).
     
    snowLee, Apr 20, 2009 IP
  4. snowLee

    snowLee Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #4
    Because you helped me, if you need the full script for this DEMO(login: demo and demo), you can take it from here.
     
    snowLee, Apr 21, 2009 IP