View Full Version : thumbnail creation not working

09-06-2009, 12:02 AM
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>

09-06-2009, 12:25 AM
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:

ini_set('display_errors', 1);

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.

09-06-2009, 12:53 AM
thanks i forgot to change the access privileges for the folder i was writing to.