Can anyone tell me why this image gallery isn't working?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
slaterino
Forum Commoner
Posts: 46
Joined: Fri Jul 11, 2008 10:50 am

Can anyone tell me why this image gallery isn't working?

Post by slaterino »

I am trying to create a simple image gallery that resizes the images, saves the images to a directory on my server and creates a reference to the images in mySQL. I've created this code which was doing everything fine but once I started trying to make it resize the images I have been having problems and am now getting the following error:

Parse error: syntax error, unexpected ')' in /home/sites/thedaffodilsociety.com/public_html/testbox.php on line 57

Can anyone see what the problem might be? This is the code:

Code: Select all

 
<?php
error_reporting(0);
 
$uploadDir = '/home/sites/mydomain.com/public_html/images/new/';
    $max_width = 150;
    $max_height = 150;
 
    $upfile = $image;  //$_FILES['upfile']['tmp_name');
   
    $size = getimagesize($upfile);
    //print_r($upfile);
    $width = $size[0];
    $height = $size[1];
 
    $x_ratio = $max_width / $width;
    $y_ratio = $max_height / $height;
   
    if( ($width <= $max_width) && ($height <= $max_height) )
    {
        $tn_width = $width;
        $tn_height = $height;
    }
    elseif (($x_ratio * $height) < $max_height)
    {
        $tn_height = ceil($x_ratio * $height);
        $tn_width = $max_width;
    }
    else
    {
        $tn_width = ceil($y_ratio * $width);
        $tn_height = $max_height;
    }
 
   
    $src = imagecreatefromjpeg($upfile);
   
    $dst = imagecreatetruecolor($tn_width, $tn_height);
    imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
    imagepng($dst);
    imagedestroy($src);
    imagedestroy($dst);
 
if(isset($_POST['upload']))
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$member = $_POST['txtMember'];
$role = $_POST['txtRole'];
 
$filePath = $uploadDir . $fileName;
 
$result = move_uploaded_file($tmpName, $filePath,);
if (!$result) {
echo "Error uploading file";
exit;
}
 
include 'library/config.php';
include 'library/opendb.php';
 
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
 
$query = "INSERT INTO upload2 (name, size, type, path, member, role ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$filePath', '$member', '$role')";
 
mysql_query($query) or die('Error, query failed : ' . mysql_error());
 
include 'library/closedb.php';
 
echo "<br>Files uploaded<br>";
 
}
?>
 
<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" id="userfile">
<input name="txtMember" type="text" id="txtMember" size="40" maxlength="50">
<input name="txtRole" type="text" id="txtRole" size="40" maxlength="50">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
 
Thanks!!!
koen.h
Forum Contributor
Posts: 268
Joined: Sat May 03, 2008 8:43 am

Re: Can anyone tell me why this image gallery isn't working?

Post by koen.h »

Check the line that causes the error:

$result = move_uploaded_file($tmpName, $filePath,);

There's a ',' too much.
slaterino
Forum Commoner
Posts: 46
Joined: Fri Jul 11, 2008 10:50 am

Re: Can anyone tell me why this image gallery isn't working?

Post by slaterino »

How did that get there? Thanks so much for pointing out the blindingly obvious!!!
Post Reply