SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict sorin21us's Avatar
    Join Date
    Mar 2009
    Posts
    279
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Make a thumb image

    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 folder 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 Code:
    <?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>";

    ?>

  2. #2
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are the 'target' directories being created? Are you using the full path to the 'target' directory/file? Is createthumb your function? Could we see the code to check it as well?

  3. #3
    SitePoint Addict sorin21us's Avatar
    Join Date
    Mar 2009
    Posts
    279
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spiderling View Post
    Are the 'target' directories being created? Are you using the full path to the 'target' directory/file? Is createthumb your function? Could we see the code to check it as well?
    In the code that's above I create with mkdir the pics dir that has inside the thumb dir. Only with that code I make dir.
    The path is correct: usename/pics/thumbs

    PHP Code:
                    $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); 

  4. #4
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We'll be needing to see the code for your createthumb function as well.

  5. #5
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spiderling View Post
    Are the 'target' directories being created? Are you using the full path to the 'target' directory/file? Is createthumb your function? Could we see the code to check it as well?
    What I meant was, can you see the directories via FTP to see if they were created? With the full path, I meant '/server/path/to/root/usename/pics/thumbs/'.

  6. #6
    SitePoint Addict sorin21us's Avatar
    Join Date
    Mar 2009
    Posts
    279
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by World Wide Weird View Post
    We'll be needing to see the code for your createthumb function as well.

    This is the function:

    PHP Code:
    function createthumb($name,$filename,$new_w,$new_h)
    {
    $system=explode(".",$name);
    if (
    preg_match("/jpg|jpeg/",$system[1])){$src_img=imagecreatefromjpeg($name);}
    if (
    preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);}
    $old_x=imageSX($src_img);
    $old_y=imageSY($src_img);
    if (
    $old_x $old_y
    {
    $thumb_w=$new_w;
    $thumb_h=$old_y*($new_h/$old_x);
    }
    if (
    $old_x $old_y
    {
    $thumb_w=$old_x*($new_w/$old_y);
    $thumb_h=$new_h;
    }
    if (
    $old_x == $old_y
    {
    $thumb_w=$new_w;
    $thumb_h=$new_h;
    }
    $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
    imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 
    if (
    preg_match("/png/",$system[1]))
    {
    imagepng($dst_img,$filename); 
    } else {
    imagejpeg($dst_img,$filename); 
    }
    imagedestroy($dst_img); 
    imagedestroy($src_img); 


  7. #7
    SitePoint Addict sorin21us's Avatar
    Join Date
    Mar 2009
    Posts
    279
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you.

    I forgot to put the function in the script .

  8. #8
    SitePoint Addict sorin21us's Avatar
    Join Date
    Mar 2009
    Posts
    279
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because you helped me, if you need the full script for this DEMO(login: demo and demo), you can take it from here.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •