Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2009
    Thanked 0 Times in 0 Posts

    thumbnail creation not working

    i can't figure out why my thumbnail creation part of my script isn't working. can anyone see anything i'm doing wrong? code is line 55-73
    $username = $_POST['username'];
    $password = $_POST['password'];
    $password2 = $_POST['password2'];
    $email = $_POST['email'];
    $zip = $_POST['zip'];
    $image = $_FILES['image'];
    $imagename = $_FILES['image']['name'];
    $imagename = str_replace(' ', '_', $imagename);
    //echo $imagename;
    if($password != $password2)
       echo "<center>Passwords do not match.</center>";
    //checking to see if users came from the registration page
    if(array_key_exists('submit', $_POST))
       //saving image
       //setting up mysql connection 
       $connect = mysql_connect(localhost, $user, $pass);
       $db = mysql_select_db(user_data);
       //checking to see if username aready exists
       $sql = "SELECT * FROM user_data WHERE username='$username'";
       $result = mysql_query($sql);
       $num = mysql_num_rows($result);
       //if it doesn't info is saved to the database
       if($num == 0)
          //saving image
          $imageinfo = getimagesize($_FILES['image']['tmp_name']); 
          if($imageinfo['mime'] != 'image/gif' && $imageinfo['mime'] != 'image/jpeg' && $imageinfo['mime'] != 'image/jpe' && $imageinfo['mime'] != 'image/jpg')
             echo "<center>That is an invalid file type, you must upload either a JPEG or GIF file.<br/> Please use your browser's 'Back' button and try again.</center>"; 
          $uploaddir = "user_images/"; 
          $uploadfile = $uploaddir . basename($_FILES['image']['name']); 
          if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile)) { 
           echo "<center>File Upload Successful</center>";}
    //////////////////////////thumbanail creation///////////////////////////////////////////      
          $n_width=100; // Fix the width of the thumb nail images
          $n_height=100; // Fix the height of the thumb nail imaage
          $tsrc="user_images/thumbs/".$_FILES[image][name]; // Path where thumb nail image will be stored
          //echo $tsrc;
          $im= imagecreatefromjpeg($uploadfile);
          $width=imagesx($im); // Original picture width is stored
          $height=imagesy($im); // Original picture height is stored
          //echo $width;
          //echo $height;
          //echo $newimage;
          echo "<center>Thumbnail Creation Successful</center>";
    /////////////////////end thumbanail creation//////////////////////////////////////         
          //protecting from sql injections
          $username = stripslashes($username);
          $username = mysql_real_escape_string($username);
          $password = stripslashes($passowrd);
          $password = mysql_real_escape_string($password);
          $email = stripslashes($email);
          $email = mysql_real_escape_string($email);
          $zip = stripslashes($zip);
          $zip = mysql_real_escape_string($zip);
          $imagename = stripslashes($imagename);
          $imagename = mysql_real_escape_string($imagename);
          $password = md5($password);
          //inserting data
          $sql = "INSERT INTO `user_data`.`user_data` (`id`, `username`, `password`, `email`, `zipcode`, `picture_name`) VALUES (NULL, '$username', '$password', '$email','$zip', '$imagename');";
          echo "<center>Registration Successful</center>";
          echo "<center>Username Already Taken.</center>";
    <!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">
    <link REL="SHORTCUT ICON" HREF="favicon.ico">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Untitled Document</title>
    <body onload="document.getElementById('username').focus();">
    <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
    <form name="form1" method="post" action="process.php">
    <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
    <td colspan="3" align="center"><strong>Member Login </strong></td>
    <td width="78">Username</td>
    <td width="6">:</td>
    <td width="294"><input name="username" type="text" id="username"></td>
    <td><input name="password" type="password" id="password"></td>
    <td align="right"><input type="submit" name="login" value="Login"></td>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,662 Times in 2,631 Posts
    I haven't tested this, but it does look ok sofar.
    Open the original, scan dimensions, create a new image, and copy from the original to the new left|top to left|top size 100 x 100, and save. Granted the file path is missing the quotations in the $_FILES superglobal accessors, but PHP will assume its dealing with a string when a constant is unavailable.

    Enable error reporting using:
    PHP Code:
    To see what the particular error is. I'm thinking its either going to complain about being unable to open a file for reading, or unable to open a directory for writing (the reading one will also trigger an error on imagecopyresize indicating that $im is not a valid resource). Post back with those errors.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    riceje7 (09-06-2009)

  • #3
    New to the CF scene
    Join Date
    Sep 2009
    Thanked 0 Times in 0 Posts
    thanks i forgot to change the access privileges for the folder i was writing to.


    Posting Permissions

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