PHP Image Resize problem

Discussion in 'OT Technology' started by Ancoats, Feb 10, 2009.

  1. Ancoats

    Ancoats New Member

    Joined:
    Oct 7, 2004
    Messages:
    135,775
    Likes Received:
    0
    Location:
    Benchill, Manchester, UK
    Hey ;)

    I have a page/form which is a member profile page, where the basic idea is that the user, once logged in, will be able to create a personal member profile, and have the option to select an image they wish to upload... all this works fine (the image selected gets uploaded and moved to the specified folder I have set for it.)

    However, I am currently having problems getting the uploaded image to 'resize' to 150 px 150px (ignore the example in this code, I know its set to half the image size... but even this doesnt work) but this doesnt seem to be working... as the original image size is on the server. Been trying to work out where I am going wrong and assume that maybe its something to do with the overall code, not just the actual bit that resizes?

    Anyway, any help or pointers would be helpful. (I am not a PHP guru so go easy, lol)

    Code is


    Code:
    [COLOR=#000000][COLOR=#0000BB]<?php
    [/COLOR][COLOR=#FF8000]//start the session
    [/COLOR][COLOR=#0000BB]session_start[/COLOR][COLOR=#007700]();
    
    [/COLOR][COLOR=#FF8000]//connect to database
    [/COLOR][COLOR=#007700]include ([/COLOR][COLOR=#DD0000]'includes/db.php'[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]?>[/COLOR][/COLOR]
    
    
      
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    
    
    [COLOR=#000000][COLOR=#0000BB]<?php
    
    [/COLOR][COLOR=#FF8000]//FORM CODE
    
    //function to generate errors
    [/COLOR][COLOR=#007700]function [/COLOR][COLOR=#0000BB]errors[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$error[/COLOR][COLOR=#007700]){
    if (!empty([/COLOR][COLOR=#0000BB]$error[/COLOR][COLOR=#007700]))
    {
    [/COLOR][COLOR=#0000BB]$i [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700];
    while ([/COLOR][COLOR=#0000BB]$i [/COLOR][COLOR=#007700]< [/COLOR][COLOR=#0000BB]count[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$error[/COLOR][COLOR=#007700])){
    echo [/COLOR][COLOR=#DD0000]"<p><span class=\"warning\"><b>"[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$error[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]$i[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#DD0000]"</b></span></p>\n"[/COLOR][COLOR=#007700];
    [/COLOR][COLOR=#0000BB]$i [/COLOR][COLOR=#007700]++;}
    
    } [/COLOR][COLOR=#FF8000]// close if empty errors
    [/COLOR][COLOR=#007700]} [/COLOR][COLOR=#FF8000]//close function
    
    
    
    //code that runs if the form has been submitted
    [/COLOR][COLOR=#007700]if (isset([/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'submit'[/COLOR][COLOR=#007700]]))
    {
    
    [/COLOR][COLOR=#FF8000]//check fields are not empty
    [/COLOR][COLOR=#0000BB]$firstname [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]trim[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'firstname'[/COLOR][COLOR=#007700]]);
    if ([/COLOR][COLOR=#0000BB]strlen[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$firstname[/COLOR][COLOR=#007700]) < [/COLOR][COLOR=#0000BB]2[/COLOR][COLOR=#007700]) {
    [/COLOR][COLOR=#0000BB]$error[/COLOR][COLOR=#007700][] = [/COLOR][COLOR=#DD0000]'first name must be between 2 and 20 chars'[/COLOR][COLOR=#007700];
    }
    
    [/COLOR][COLOR=#0000BB]$lastname [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]trim[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'lastname'[/COLOR][COLOR=#007700]]);
    if ([/COLOR][COLOR=#0000BB]strlen[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$lastname[/COLOR][COLOR=#007700]) < [/COLOR][COLOR=#0000BB]3[/COLOR][COLOR=#007700]) {
    [/COLOR][COLOR=#0000BB]$error[/COLOR][COLOR=#007700][] = [/COLOR][COLOR=#DD0000]'last name must be between 3 and 20 chars'[/COLOR][COLOR=#007700];
    }
    
    [/COLOR][COLOR=#0000BB]$userDOB [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]trim[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'userDOB'[/COLOR][COLOR=#007700]]);
    if ([/COLOR][COLOR=#0000BB]strlen[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userDOB[/COLOR][COLOR=#007700]) < [/COLOR][COLOR=#0000BB]3[/COLOR][COLOR=#007700]) {
    [/COLOR][COLOR=#0000BB]$error[/COLOR][COLOR=#007700][] = [/COLOR][COLOR=#DD0000]'date of birth must be between 3 and 20 chars'[/COLOR][COLOR=#007700];
    }
    
    [/COLOR][COLOR=#0000BB]$userGend [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]trim[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'userGend'[/COLOR][COLOR=#007700]]);
    if ([/COLOR][COLOR=#0000BB]strlen[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userGend[/COLOR][COLOR=#007700]) < [/COLOR][COLOR=#0000BB]3[/COLOR][COLOR=#007700]) {
    [/COLOR][COLOR=#0000BB]$error[/COLOR][COLOR=#007700][] = [/COLOR][COLOR=#DD0000]'Gender must be between 3 and 20 chars'[/COLOR][COLOR=#007700];
    }
    
    [/COLOR][COLOR=#0000BB]$userLoc [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]trim[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'userLoc'[/COLOR][COLOR=#007700]]);
    if ([/COLOR][COLOR=#0000BB]strlen[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userLoc[/COLOR][COLOR=#007700]) < [/COLOR][COLOR=#0000BB]3[/COLOR][COLOR=#007700]) {
    [/COLOR][COLOR=#0000BB]$error[/COLOR][COLOR=#007700][] = [/COLOR][COLOR=#DD0000]'Location must be between 3 and 255 chars'[/COLOR][COLOR=#007700];
    }
    
    [/COLOR][COLOR=#0000BB]$userInt [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]trim[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'userInt'[/COLOR][COLOR=#007700]]);
    if ([/COLOR][COLOR=#0000BB]strlen[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userInt[/COLOR][COLOR=#007700]) < [/COLOR][COLOR=#0000BB]3[/COLOR][COLOR=#007700]) {
    [/COLOR][COLOR=#0000BB]$error[/COLOR][COLOR=#007700][] = [/COLOR][COLOR=#DD0000]'Interests must be more than 3 characters'[/COLOR][COLOR=#007700];
    }
    
    [/COLOR][COLOR=#0000BB]$userDesc [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]trim[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'userDesc'[/COLOR][COLOR=#007700]]);
    if ([/COLOR][COLOR=#0000BB]strlen[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userDesc[/COLOR][COLOR=#007700]) < [/COLOR][COLOR=#0000BB]3[/COLOR][COLOR=#007700]) {
    [/COLOR][COLOR=#0000BB]$error[/COLOR][COLOR=#007700][] = [/COLOR][COLOR=#DD0000]'Description must be more than 3 characters'[/COLOR][COLOR=#007700];
    }
    
    
    [/COLOR][COLOR=#FF8000]//checks for allowed file type (jpg, gif or png)
    [/COLOR][COLOR=#007700]switch ([/COLOR][COLOR=#0000BB]$_FILES[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'userPic'[/COLOR][COLOR=#007700]][[/COLOR][COLOR=#DD0000]'type'[/COLOR][COLOR=#007700]])
    
    {
    case [/COLOR][COLOR=#0000BB]$_FILES[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'userPic'[/COLOR][COLOR=#007700]][[/COLOR][COLOR=#DD0000]'type'[/COLOR][COLOR=#007700]] == [/COLOR][COLOR=#DD0000]'image/jpg'[/COLOR][COLOR=#007700]:
    break;
    
    case [/COLOR][COLOR=#0000BB]$_FILES[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'userPic'[/COLOR][COLOR=#007700]][[/COLOR][COLOR=#DD0000]'type'[/COLOR][COLOR=#007700]] == [/COLOR][COLOR=#DD0000]'image/jpeg'[/COLOR][COLOR=#007700]:
    break;
    
    
    case [/COLOR][COLOR=#0000BB]$_FILES[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'userPic'[/COLOR][COLOR=#007700]][[/COLOR][COLOR=#DD0000]'type'[/COLOR][COLOR=#007700]] == [/COLOR][COLOR=#DD0000]'image/gif'[/COLOR][COLOR=#007700]:
    break;
    
    case [/COLOR][COLOR=#0000BB]$_FILES[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'userPic'[/COLOR][COLOR=#007700]][[/COLOR][COLOR=#DD0000]'type'[/COLOR][COLOR=#007700]] == [/COLOR][COLOR=#DD0000]'image/png'[/COLOR][COLOR=#007700]:
    break;
    
    default:
    [/COLOR][COLOR=#0000BB]$error[/COLOR][COLOR=#007700][] = [/COLOR][COLOR=#DD0000]'wrong file type'[/COLOR][COLOR=#007700];
    
    }
    
    [/COLOR][COLOR=#FF8000]//checks if file size is over 2mb, and if it is, refuse
    [/COLOR][COLOR=#007700]switch ([/COLOR][COLOR=#0000BB]$_FILES[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"userPic"[/COLOR][COLOR=#007700]][[/COLOR][COLOR=#DD0000]"size"[/COLOR][COLOR=#007700]]) {
    case [/COLOR][COLOR=#0000BB]$_FILES[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"userPic"[/COLOR][COLOR=#007700]][[/COLOR][COLOR=#DD0000]"size"[/COLOR][COLOR=#007700]] > [/COLOR][COLOR=#0000BB]2097152[/COLOR][COLOR=#007700]:
        [/COLOR][COLOR=#0000BB]$error[/COLOR][COLOR=#007700][] = [/COLOR][COLOR=#DD0000]'Image size cannot be bigger then 2MB!'[/COLOR][COLOR=#007700];[/COLOR][COLOR=#0000BB]   
        break;
    }
    
    if(![/COLOR][COLOR=#0000BB]$error[/COLOR][COLOR=#007700])
    {
    
    
    [/COLOR][COLOR=#FF8000]//moves uploaded file from temp folder to set folder (which will be ../images/userpics folder)
    [/COLOR][COLOR=#0000BB]move_uploaded_file [/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$_FILES[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'userPic'[/COLOR][COLOR=#007700]][[/COLOR][COLOR=#DD0000]'tmp_name'[/COLOR][COLOR=#007700]], [/COLOR][COLOR=#DD0000]"images/userpics/"[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$_FILES[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'userPic'[/COLOR][COLOR=#007700]][[/COLOR][COLOR=#DD0000]'name'[/COLOR][COLOR=#007700]]) 
    or die ([/COLOR][COLOR=#DD0000]"Could not move"[/COLOR][COLOR=#007700]);
    
    
    [/COLOR][COLOR=#FF8000]//Assign the paths needed to variables for use in the script
    [/COLOR][COLOR=#0000BB]$filePathFull [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]"images/userpics/"[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$_FILES[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"userPic"[/COLOR][COLOR=#007700]][[/COLOR][COLOR=#DD0000]"name"[/COLOR][COLOR=#007700]];
    [/COLOR][COLOR=#0000BB]$filePathThumb [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]"images/userpics/"[/COLOR][COLOR=#007700];
    
    [/COLOR][COLOR=#FF8000]//Assign the files TMP name and TYPE to variable for use in the script
    [/COLOR][COLOR=#0000BB]$tmpName [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$_FILES[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"userPic"[/COLOR][COLOR=#007700]][[/COLOR][COLOR=#DD0000]"tmp_name"[/COLOR][COLOR=#007700]];
    [/COLOR][COLOR=#0000BB]$imageType [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$_FILES[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"userPic"[/COLOR][COLOR=#007700]][[/COLOR][COLOR=#DD0000]"type"[/COLOR][COLOR=#007700]];
    
    [/COLOR][COLOR=#FF8000]//Use a switch statement to check the extension of the file type. If file type is not valid echo an error
    [/COLOR][COLOR=#0000BB]   switch ([/COLOR][COLOR=#0000BB]$imageType[/COLOR][COLOR=#007700]) {
    [/COLOR][COLOR=#0000BB]   case [/COLOR][COLOR=#0000BB]$imageType [/COLOR][COLOR=#007700]== [/COLOR][COLOR=#DD0000]"image/gif"[/COLOR][COLOR=#007700]:
    [/COLOR][COLOR=#0000BB]move_uploaded_file[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$tmpName[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000BB]$filePathFull[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]   break;
    [/COLOR][COLOR=#0000BB]   case [/COLOR][COLOR=#0000BB]$imageType [/COLOR][COLOR=#007700]== [/COLOR][COLOR=#DD0000]"image/jpeg"[/COLOR][COLOR=#007700]:
    [/COLOR][COLOR=#0000BB]move_uploaded_file[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$tmpName[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000BB]$filePathFull[/COLOR][COLOR=#007700]);[/COLOR][COLOR=#0000BB]   break;
    [/COLOR][COLOR=#0000BB]   case [/COLOR][COLOR=#0000BB]$imageType [/COLOR][COLOR=#007700]== [/COLOR][COLOR=#DD0000]"image/pjpeg"[/COLOR][COLOR=#007700]:
    [/COLOR][COLOR=#0000BB]move_uploaded_file[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$tmpName[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000BB]$filePathFull[/COLOR][COLOR=#007700]);[/COLOR][COLOR=#0000BB]   break;[/COLOR][COLOR=#0000BB]   case [/COLOR][COLOR=#0000BB]$imageType [/COLOR][COLOR=#007700]== [/COLOR][COLOR=#DD0000]"image/png"[/COLOR][COLOR=#007700]:
    [/COLOR][COLOR=#0000BB]move_uploaded_file[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$tmpName[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000BB]$filePathFull[/COLOR][COLOR=#007700]);[/COLOR][COLOR=#0000BB]   break;
    [/COLOR][COLOR=#0000BB]   case [/COLOR][COLOR=#0000BB]$imageType [/COLOR][COLOR=#007700]== [/COLOR][COLOR=#DD0000]"image/x-png"[/COLOR][COLOR=#007700]:
    [/COLOR][COLOR=#0000BB]move_uploaded_file[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$tmpName[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000BB]$filePathFull[/COLOR][COLOR=#007700]);[/COLOR][COLOR=#0000BB]   break;[/COLOR][COLOR=#0000BB]   default:
    [/COLOR][COLOR=#0000BB]   echo [/COLOR][COLOR=#DD0000]'Wrong image type selected. Only JPG, PNG or GIF formats accepted!.'[/COLOR][COLOR=#007700];
    [/COLOR][COLOR=#0000BB]   }
    
    [/COLOR][COLOR=#FF8000]// Get information about the image
            [/COLOR][COLOR=#007700]list([/COLOR][COLOR=#0000BB]$src_width[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$src_height[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$type[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$attr[/COLOR][COLOR=#007700]) = [/COLOR][COLOR=#0000BB]getimagesize[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$filePathFull[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#FF8000]//Create the correct file type based on imagetype
            [/COLOR][COLOR=#007700]switch( [/COLOR][COLOR=#0000BB]$type [/COLOR][COLOR=#007700]) {
            case [/COLOR][COLOR=#0000BB]IMAGETYPE_JPEG[/COLOR][COLOR=#007700]:
                    [/COLOR][COLOR=#0000BB]$starting_image [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]imagecreatefromjpeg[/COLOR][COLOR=#007700]( [/COLOR][COLOR=#0000BB]$filePathFull [/COLOR][COLOR=#007700]);
                    break;
            case [/COLOR][COLOR=#0000BB]IMAGETYPE_PNG[/COLOR][COLOR=#007700]:
                    [/COLOR][COLOR=#0000BB]$starting_image [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]imagecreatefrompng[/COLOR][COLOR=#007700]( [/COLOR][COLOR=#0000BB]$filePathFull [/COLOR][COLOR=#007700]);
                    break;
            case [/COLOR][COLOR=#0000BB]IMAGETYPE_GIF[/COLOR][COLOR=#007700]:
                    [/COLOR][COLOR=#0000BB]$starting_image [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]imagecreatefromgif[/COLOR][COLOR=#007700]( [/COLOR][COLOR=#0000BB]$filePathFull [/COLOR][COLOR=#007700]);
                    break;
            default:
                    return [/COLOR][COLOR=#0000BB]false[/COLOR][COLOR=#007700];
            }
    
    
    [/COLOR][COLOR=#FF8000]//Get the image to create thumbnail from
        [/COLOR][COLOR=#0000BB]$starting_image[/COLOR][COLOR=#007700]; 
    [/COLOR][COLOR=#FF8000]//Get image height and width
    [/COLOR][COLOR=#0000BB]$width [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]imagesx[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$starting_image[/COLOR][COLOR=#007700]);
        [/COLOR][COLOR=#0000BB]$height [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]imagesy[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$starting_image[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#FF8000]//Create the dimesnsions for the thumbnail
    [/COLOR][COLOR=#0000BB]$thumb_width [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$width[/COLOR][COLOR=#007700]/[/COLOR][COLOR=#0000BB]2[/COLOR][COLOR=#007700];
    [/COLOR][COLOR=#0000BB]$thumb_height [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$height[/COLOR][COLOR=#007700]/[/COLOR][COLOR=#0000BB]2[/COLOR][COLOR=#007700];
    
    [/COLOR][COLOR=#FF8000]//Create the thumbnail with true colours
        [/COLOR][COLOR=#0000BB]$thumb_image [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]imagecreatetruecolor[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$thumb_width[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$thumb_height[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#FF8000]//Generate the resized image image
    [/COLOR][COLOR=#0000BB]imagecopyresized[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$thumb_image[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$starting_image[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700],  [/COLOR][COLOR=#0000BB]$thumb_width[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$thumb_height[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$width[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$height[/COLOR][COLOR=#007700]);[/COLOR][COLOR=#FF8000]//Generate a random number to append the filename.
    [/COLOR][COLOR=#0000BB]$ran [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]"thumb_"[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]rand [/COLOR][COLOR=#007700]() ;[/COLOR][COLOR=#0000BB]$thumb2 [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$ran[/COLOR][COLOR=#007700].[/COLOR][COLOR=#DD0000]".jpg"[/COLOR][COLOR=#007700];
    [/COLOR][COLOR=#FF8000]//global $thumb_Add_thumb;
    [/COLOR][COLOR=#FF8000]//Create the path to store the thumbnail in.
    [/COLOR][COLOR=#0000BB]$thumb_Add_thumb [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$filePathThumb[/COLOR][COLOR=#007700];
    [/COLOR][COLOR=#0000BB]$thumb_Add_thumb [/COLOR][COLOR=#007700].= [/COLOR][COLOR=#0000BB]$thumb2[/COLOR][COLOR=#007700];[/COLOR][COLOR=#FF8000]//Create the new image and put it into the thumbnails folder.
    [/COLOR][COLOR=#0000BB]imagejpeg[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$thumb_image[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]"" [/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$filePathThumb[/COLOR][COLOR=#007700]. [/COLOR][COLOR=#DD0000]"$thumb2"[/COLOR][COLOR=#007700]); 
    
    
    
    
    
    
    
    [/COLOR][COLOR=#FF8000]//escapes data is magic quotes are disabled on the server
    [/COLOR][COLOR=#007700]if(![/COLOR][COLOR=#0000BB]get_magic_quotes_gpc[/COLOR][COLOR=#007700]())
    {
    [/COLOR][COLOR=#0000BB]$firstname [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]addslashes[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$firstname[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]$lastname [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]addslashes[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$lastname[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]$userDOB [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]addslashes[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userDOB[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]$userGend [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]addslashes[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userGend[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]$userLoc [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]addslashes[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userLoc[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]$userInt [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]addslashes[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userInt[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]$userDesc [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]addslashes[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userDesc[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]$userPic [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]addslashes[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userPic[/COLOR][COLOR=#007700]);
    }
    
    
    [/COLOR][COLOR=#FF8000]//escape any harmful code and prevent sql injection attacks
    [/COLOR][COLOR=#0000BB]$firstname [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]mysql_real_escape_string[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$firstname[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]$lastname [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]mysql_real_escape_string[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$lastname[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]$userDOB [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]mysql_real_escape_string[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userDOB[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]$userGend [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]mysql_real_escape_string[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userGend[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]$userLoc [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]mysql_real_escape_string[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userLoc[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]$userInt [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]mysql_real_escape_string[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userInt[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]$userDesc [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]mysql_real_escape_string[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userDesc[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]$userPic [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]mysql_real_escape_string[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userPic[/COLOR][COLOR=#007700]);
    
    
    [/COLOR][COLOR=#FF8000]//prevents escaped code showing
    [/COLOR][COLOR=#0000BB]$firstname [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]strip_tags[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$firstname[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]$lastname [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]strip_tags[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$lastname[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]$userDOB [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]strip_tags[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userDOB[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]$userGend [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]strip_tags[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userGend[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]$userLoc [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]strip_tags[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userLoc[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]$userInt [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]strip_tags[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userInt[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]$userDesc [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]strip_tags[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userDesc[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]$userPic [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]strip_tags[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$userPic[/COLOR][COLOR=#007700]);
    
    
    [/COLOR][COLOR=#FF8000]//reference the ismember session 
    [/COLOR][COLOR=#0000BB]$memberID [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$_SESSION[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'ismember'[/COLOR][COLOR=#007700]];
    
    
    [/COLOR][COLOR=#FF8000]//insert data into the memberprofile table
    [/COLOR][COLOR=#0000BB]$sql [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]mysql_query[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"INSERT INTO memberprofile (firstname, lastname, userDOB, userGend, userLoc, userInt, userDesc, userPic)
                   VALUES('$firstname', '$lastname', '$userDOB', '$userGend', '$userLoc', '$userInt', '$userDesc', '"[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$_FILES[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'userPic'[/COLOR][COLOR=#007700]][[/COLOR][COLOR=#DD0000]'name'[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#DD0000]"')    WHERE memberID='$memberID'"[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#FF8000]//if data has been inserted
    [/COLOR][COLOR=#007700]echo [/COLOR][COLOR=#DD0000]"<p>Thank you. Your member profile has been created</p>"[/COLOR][COLOR=#007700];[/COLOR][COLOR=#0000BB]   
    
    }[/COLOR][COLOR=#FF8000]//if no error
    [/COLOR][COLOR=#007700]}[/COLOR][COLOR=#FF8000]//close form if sumbit         
    [/COLOR][COLOR=#FF8000]//print any errors
    [/COLOR][COLOR=#0000BB]errors[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$error[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]?>[/COLOR][/COLOR]

    Any idea where I'm going wrong? :hs:
     
  2. retorq

    retorq What up bitch??

    Joined:
    Dec 14, 2006
    Messages:
    6,061
    Likes Received:
    0
    Location:
    Mohave Desert
    My code is very similar, you have that extra bit that mine doesn't ...

    Code:
    list($x, $y) = getimagesize("$file");
    
            if($x > $y){
               $max = $x;
               $min = $y;
            }
            if($x <= $y){
               $max = $y;
               $min = $x;
            }
    
        $new_max_size = '205';
    
        $rate = $max/$new_max_size;
        $final_x = $x/$rate;
        $final_y = $y/$rate;
    
        if($final_x > $x) {
                $final_x = $x;
                $final_y = $y;
        }
    
        $final_x = ceil($final_x);
        $final_y = ceil($final_y);
    
    $image_p = imagecreatetruecolor($final_x, $final_y);
    $new_image = imagecreatefromjpeg($file);
    @imagecopyresampled($image_p, $new_image, 0, 0, 0, 0, $final_x, $final_y, $x, $y);
    imagejpeg($image_p, "tmp/$filename", 50);
    $random_pic = '<a href="'.$file.'" rel="lightbox" target="_blank"><img width="205" alt="RANDOM PIC" src="tmp/'.$filename.'" /></a>';
    
    
     

Share This Page