RyanMinor Posted July 13, 2010 Share Posted July 13, 2010 Hi everyone! My most recent project entails inserting photo gallery information. I have it set up like this: (1) The user enters details about the photo gallery (thumbnail file name, caption, description, model) and the thumbnail is resized. (2) After entering gallery information, they are taken to a page (addphoto.php) with 16 photo upload fields where they are resized and thumbnails are created. I'm stuck on the addgallery.php page. For some reason I am getting a parse error on line 193. It has to do with the bracket found on that line. When I take the bracket away however, my form and anything below it does not display. Any help is greatly appreciated. Here is my code: <?php require_once('Connections/DBConnect.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "uploadgallery")) { // define a constant for the maximum uploadable size define ('MAX_FILE_SIZE', 256000); if (array_key_exists('upload', $_POST)) { // set the location of the folder to upload the images to define('UPLOAD_DIR', 'C:/wamp/www/test/photos/'); // replace any spaces in original filename with underscores // at the same time, assign to a simpler variable $file = str_replace(' ', '_', $_FILES['image']['name']); // convert the maximum size to KB $max = number_format(MAX_FILE_SIZE/1024, 1).'KB'; // create an array of permitted MIME types $permitted = array('image/gif','image/jpeg','image/pjpeg','image/png'); // begin by assuming the file is unacceptable $sizeOK = false; $typeOK = false; // check that file is within the permitted size if ($_FILES['image']['size'] > 0 && $_FILES['image']['size'] <= MAX_FILE_SIZE) { $sizeOK = true; } // check that file is of a permitted MIME type foreach ($permitted as $type) { if ($type == $_FILES['image']['type']) { $typeOK = true; break; } } if ($sizeOK && $typeOK) { switch($_FILES['image']['error']) { case 0: // define constants define('MAX_WIDTH', 150); define('MAX_HEIGHT', 150); // process the uploaded image if (is_uploaded_file($_FILES['image']['tmp_name'])) { $original = $_FILES['image']['tmp_name']; // begin by getting the details of the original list($width, $height, $type) = getimagesize($original); // calculate the scaling ratio if ($width <= MAX_WIDTH && $height <= MAX_HEIGHT) { $ratio = 1; } elseif ($width > $height) { $ratio = MAX_WIDTH/$width; } else { $ratio = MAX_HEIGHT/$height; } // strip the extension off the image filename $imagetypes = array('/\.gif$/', '/\.jpg$/', '/\.jpeg$/', '/\.png$/'); $name = preg_replace($imagetypes, '', basename($original)); // create an image resource for the original switch($type) { case 1: $source = @ imagecreatefromgif($original); if (!$source) { $result = 'Cannot process GIF files. Please use JPEG or PNG.'; } break; case 2: $source = imagecreatefromjpeg($original); break; case 3: $source = imagecreatefrompng($original); break; default: $source = NULL; $result = 'Cannot identify file type.'; } // make sure the image resource is OK if (!$source) { $result = 'Problem copying original'; } else { // calculate the dimensions of the thumbnail $thumb_width = round($width * $ratio); $thumb_height = round($height * $ratio); // create an image resource for the thumbnail $thumb = imagecreatetruecolor($thumb_width, $thumb_height); // create the resized copy imagecopyresampled($thumb, $source, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height); // save the resized copy switch($type) { case 1: if (function_exists('imagegif')) { $success = imagegif($thumb, UPLOAD_DIR.$name.'_thb.gif'); $thumb_name = $name.'_thb.gif'; } else { $success = imagejpeg($thumb, UPLOAD_DIR.$name.'_thb.jpg', 50); $thumb_name = $name.'_thb.jpg'; } break; case 2: $success = imagejpeg($thumb, UPLOAD_DIR.$name.'_thb.jpg', 100); $thumb_name = $name.'_thb.jpg'; break; case 3: $success = imagepng($thumb, UPLOAD_DIR.$name.'_thb.png'); $thumb_name = $name.'_thb.png'; } if ($success) { $insertSQL = sprintf("INSERT INTO tblmembergallery (gallerythumbname, gallerycaption, gallerydescription, modelid, `date`) VALUES (%s, %s, %s, %s, %s)", GetSQLValueString($_POST['gallerythumbname'], "text"), GetSQLValueString($_POST['gallerycaption'], "text"), GetSQLValueString($_POST['gallerydescription'], "text"), GetSQLValueString($_POST['modelid'], "int"), GetSQLValueString($_POST['date'], "date")); mysql_select_db($database_DBConnect, $DBConnect); $Result1 = mysql_query($insertSQL, $DBConnect) or die(mysql_error()); } // remove the image resources from memory imagedestroy($source); imagedestroy($thumb); } } break; case 3: $result = "Error uploading $file. Please try again."; default: $result = "System error uploading $file. Contact webmaster."; } } elseif ($_FILES['image']['error'] == 4) { $result = 'No file selected'; } else { $result = "$file cannot be uploaded. Maximum size: $max. Acceptable file types: gif, jpg, png."; } } } $insertGoTo = "addphoto.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_DBConnect, $DBConnect); $query_rsgetmodel = "SELECT modelid, modelname FROM tblmembermodel ORDER BY modelname ASC"; $rsgetmodel = mysql_query($query_rsgetmodel, $DBConnect) or die(mysql_error()); $row_rsgetmodel = mysql_fetch_assoc($rsgetmodel); $totalRows_rsgetmodel = mysql_num_rows($rsgetmodel); ?> <!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=utf-8" /> <title>Add Photo Gallery</title> </head> <body> This is a test page that will enable the administrator to create a photo gallery and upload 16 photos to it.<br /> <br /> <br /> <div align="center"> <?php // if the form has been submitted, display result if (isset($result)) { echo "<p><strong>$result</strong></p>"; } ?> </div> <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="uploadgallery" id="uploadgallery"> <table width="40%" border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td valign="top"><div align="right">Gallery Thumbnail:</div></td> <td valign="top"><input name="MAX_FILE_SIZE" type="hidden" id="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?>" /> <input type="file" name="gallerythumbname" id="gallerythumbname" /></td> </tr> <tr> <td valign="top"><div align="right">Gallery Caption:</div></td> <td valign="top"><input type="text" name="gallerycaption" id="gallerycaption" /></td> </tr> <tr> <td valign="top"><div align="right">Gallery Description:</div></td> <td valign="top"><textarea name="gallerydescription" id="gallerydescription" cols="35" rows="3"></textarea></td> </tr> <tr> <td valign="top"><div align="right">Model:</div></td> <td valign="top"><select name="modelid" id="modelid"> <?php do { ?> <option value="<?php echo $row_rsgetmodel['modelid']?>"><?php echo $row_rsgetmodel['modelname']?></option> <?php } while ($row_rsgetmodel = mysql_fetch_assoc($rsgetmodel)); $rows = mysql_num_rows($rsgetmodel); if($rows > 0) { mysql_data_seek($rsgetmodel, 0); $row_rsgetmodel = mysql_fetch_assoc($rsgetmodel); } ?> </select> <input name="date" type="hidden" id="date" value="<?php echo date ("Y-m-d H:m:s"); ?>" /></td> </tr> <tr> <td colspan="2"><div align="center"> <input type="submit" name="upload" id="upload" value="Submit and Add Photos" /> </div></td> </tr> </table> <input type="hidden" name="MM_insert" value="uploadgallery" /> </form> <br /> <br /> Then, I will grab the insert id and send it to the next page which will contain 16 photo upload fields. </body> </html> <?php mysql_free_result($rsgetmodel); ?> Link to comment https://forums.phpfreaks.com/topic/207607-creating-photo-gallery/ Share on other sites More sharing options...
gwolgamott Posted July 13, 2010 Share Posted July 13, 2010 That bracket on line 193 has not open bracket partner. That's why it's bulking on that bracket. EDIT: Remove the bracket & then start debugging further down where it stops working. Link to comment https://forums.phpfreaks.com/topic/207607-creating-photo-gallery/#findComment-1085361 Share on other sites More sharing options...
RyanMinor Posted July 13, 2010 Author Share Posted July 13, 2010 OK, I did that. Now, when i load the page (addgallerybackup.php) it sends me right to addphoto.php (which is the page I have it sending the user to after the insert record and image upload is complete. I think my code needs moved around a little. Can you help with that? Link to comment https://forums.phpfreaks.com/topic/207607-creating-photo-gallery/#findComment-1085394 Share on other sites More sharing options...
gwolgamott Posted July 13, 2010 Share Posted July 13, 2010 yeah give me a few to look it over. Link to comment https://forums.phpfreaks.com/topic/207607-creating-photo-gallery/#findComment-1085438 Share on other sites More sharing options...
gwolgamott Posted July 13, 2010 Share Posted July 13, 2010 Move the entire block of code here up into the the bracket above it. Try this, not familiar with but after a quick glance think this should fix it. I think that bracket on 193 did need to be there but the bracket above on line 185 was an extra one. But don't bother with that just try the code below and see if it does what u want. <?php require_once('Connections/DBConnect.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "uploadgallery")) { // define a constant for the maximum uploadable size define ('MAX_FILE_SIZE', 256000); if (array_key_exists('upload', $_POST)) { // set the location of the folder to upload the images to define('UPLOAD_DIR', 'C:/wamp/www/test/photos/'); // replace any spaces in original filename with underscores // at the same time, assign to a simpler variable $file = str_replace(' ', '_', $_FILES['image']['name']); // convert the maximum size to KB $max = number_format(MAX_FILE_SIZE/1024, 1).'KB'; // create an array of permitted MIME types $permitted = array('image/gif','image/jpeg','image/pjpeg','image/png'); // begin by assuming the file is unacceptable $sizeOK = false; $typeOK = false; // check that file is within the permitted size if ($_FILES['image']['size'] > 0 && $_FILES['image']['size'] <= MAX_FILE_SIZE) { $sizeOK = true; } // check that file is of a permitted MIME type foreach ($permitted as $type) { if ($type == $_FILES['image']['type']) { $typeOK = true; break; } } if ($sizeOK && $typeOK) { switch($_FILES['image']['error']) { case 0: // define constants define('MAX_WIDTH', 150); define('MAX_HEIGHT', 150); // process the uploaded image if (is_uploaded_file($_FILES['image']['tmp_name'])) { $original = $_FILES['image']['tmp_name']; // begin by getting the details of the original list($width, $height, $type) = getimagesize($original); // calculate the scaling ratio if ($width <= MAX_WIDTH && $height <= MAX_HEIGHT) { $ratio = 1; } elseif ($width > $height) { $ratio = MAX_WIDTH/$width; } else { $ratio = MAX_HEIGHT/$height; } // strip the extension off the image filename $imagetypes = array('/\.gif$/', '/\.jpg$/', '/\.jpeg$/', '/\.png$/'); $name = preg_replace($imagetypes, '', basename($original)); // create an image resource for the original switch($type) { case 1: $source = @ imagecreatefromgif($original); if (!$source) { $result = 'Cannot process GIF files. Please use JPEG or PNG.'; } break; case 2: $source = imagecreatefromjpeg($original); break; case 3: $source = imagecreatefrompng($original); break; default: $source = NULL; $result = 'Cannot identify file type.'; } // make sure the image resource is OK if (!$source) { $result = 'Problem copying original'; } else { // calculate the dimensions of the thumbnail $thumb_width = round($width * $ratio); $thumb_height = round($height * $ratio); // create an image resource for the thumbnail $thumb = imagecreatetruecolor($thumb_width, $thumb_height); // create the resized copy imagecopyresampled($thumb, $source, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height); // save the resized copy switch($type) { case 1: if (function_exists('imagegif')) { $success = imagegif($thumb, UPLOAD_DIR.$name.'_thb.gif'); $thumb_name = $name.'_thb.gif'; } else { $success = imagejpeg($thumb, UPLOAD_DIR.$name.'_thb.jpg', 50); $thumb_name = $name.'_thb.jpg'; } break; case 2: $success = imagejpeg($thumb, UPLOAD_DIR.$name.'_thb.jpg', 100); $thumb_name = $name.'_thb.jpg'; break; case 3: $success = imagepng($thumb, UPLOAD_DIR.$name.'_thb.png'); $thumb_name = $name.'_thb.png'; } if ($success) { $insertSQL = sprintf("INSERT INTO tblmembergallery (gallerythumbname, gallerycaption, gallerydescription, modelid, `date`) VALUES (%s, %s, %s, %s, %s)", GetSQLValueString($_POST['gallerythumbname'], "text"), GetSQLValueString($_POST['gallerycaption'], "text"), GetSQLValueString($_POST['gallerydescription'], "text"), GetSQLValueString($_POST['modelid'], "int"), GetSQLValueString($_POST['date'], "date")); mysql_select_db($database_DBConnect, $DBConnect); $Result1 = mysql_query($insertSQL, $DBConnect) or die(mysql_error()); } // remove the image resources from memory imagedestroy($source); imagedestroy($thumb); } } break; case 3: $result = "Error uploading $file. Please try again."; default: $result = "System error uploading $file. Contact webmaster."; } } elseif ($_FILES['image']['error'] == 4) { $result = 'No file selected'; } else { $result = "$file cannot be uploaded. Maximum size: $max. Acceptable file types: gif, jpg, png."; } } ///////////I moved block of code below to here $insertGoTo = "addphoto.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); /////////////moved block of code above here } mysql_select_db($database_DBConnect, $DBConnect); $query_rsgetmodel = "SELECT modelid, modelname FROM tblmembermodel ORDER BY modelname ASC"; $rsgetmodel = mysql_query($query_rsgetmodel, $DBConnect) or die(mysql_error()); $row_rsgetmodel = mysql_fetch_assoc($rsgetmodel); $totalRows_rsgetmodel = mysql_num_rows($rsgetmodel); ?> <!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=utf-8" /> <title>Add Photo Gallery</title> </head> <body> This is a test page that will enable the administrator to create a photo gallery and upload 16 photos to it.<br /> <br /> <br /> <div align="center"> <?php // if the form has been submitted, display result if (isset($result)) { echo "<p><strong>$result</strong></p>"; } ?> </div> <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="uploadgallery" id="uploadgallery"> <table width="40%" border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td valign="top"><div align="right">Gallery Thumbnail:</div></td> <td valign="top"><input name="MAX_FILE_SIZE" type="hidden" id="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?>" /> <input type="file" name="gallerythumbname" id="gallerythumbname" /></td> </tr> <tr> <td valign="top"><div align="right">Gallery Caption:</div></td> <td valign="top"><input type="text" name="gallerycaption" id="gallerycaption" /></td> </tr> <tr> <td valign="top"><div align="right">Gallery Description:</div></td> <td valign="top"><textarea name="gallerydescription" id="gallerydescription" cols="35" rows="3"></textarea></td> </tr> <tr> <td valign="top"><div align="right">Model:</div></td> <td valign="top"><select name="modelid" id="modelid"> <?php do { ?> <option value="<?php echo $row_rsgetmodel['modelid']?>"><?php echo $row_rsgetmodel['modelname']?></option> <?php } while ($row_rsgetmodel = mysql_fetch_assoc($rsgetmodel)); $rows = mysql_num_rows($rsgetmodel); if($rows > 0) { mysql_data_seek($rsgetmodel, 0); $row_rsgetmodel = mysql_fetch_assoc($rsgetmodel); } ?> </select> <input name="date" type="hidden" id="date" value="<?php echo date ("Y-m-d H:m:s"); ?>" /></td> </tr> <tr> <td colspan="2"><div align="center"> <input type="submit" name="upload" id="upload" value="Submit and Add Photos" /> </div></td> </tr> </table> <input type="hidden" name="MM_insert" value="uploadgallery" /> </form> <br /> <br /> Then, I will grab the insert id and send it to the next page which will contain 16 photo upload fields. </body> </html> <?php mysql_free_result($rsgetmodel); ?> Link to comment https://forums.phpfreaks.com/topic/207607-creating-photo-gallery/#findComment-1085442 Share on other sites More sharing options...
RyanMinor Posted July 14, 2010 Author Share Posted July 14, 2010 I will play with it tomorrow at work. Thanks! Link to comment https://forums.phpfreaks.com/topic/207607-creating-photo-gallery/#findComment-1085617 Share on other sites More sharing options...
RyanMinor Posted July 14, 2010 Author Share Posted July 14, 2010 Everything worked out OK, but I ended up not redirecting the user to the addphoto.php page automatically. In the result message I put a link to go to the addphoto.php page and passed a session variable (galleryid) to it. From there the user can upload unlimited images to that specific gallery one at a time. Is there a place that I can paste my code for others to use if they want? I've received a good deal of help from this forum that I figured I'd give something back. Link to comment https://forums.phpfreaks.com/topic/207607-creating-photo-gallery/#findComment-1085881 Share on other sites More sharing options...
gwolgamott Posted July 14, 2010 Share Posted July 14, 2010 Cool. Glad it worked. They don't have a repository for user posted code.. at least I don't think. Could just post the code here for the final solution you used and mark it solved in case someone stumbles across this in a search. Other then that I think it's encouraged to help others out if you received some help in return. Link to comment https://forums.phpfreaks.com/topic/207607-creating-photo-gallery/#findComment-1085916 Share on other sites More sharing options...
RyanMinor Posted July 17, 2010 Author Share Posted July 17, 2010 Here is the code that finally worked. What this does is allow people who want to create a photo gallery to upload a photo (that is turned into a thumbnail) and also add some info about the gallery. It then displays a result message allowing you to go to the photo.php page where you add photos. <?php require_once('Connections/DBConnect.php'); ?> <?php session_start(); if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "uploadgallery")) { // make the gallery name available for the result message $gallery = $_POST['gallerycaption']; // define a constant for the maximum uploadable size define ('MAX_FILE_SIZE', 256000); // convert the maximum size to KB $max = number_format(MAX_FILE_SIZE/1024, 1).'KB'; // create an array of permitted MIME types $permitted = array('image/gif','image/jpeg','image/pjpeg','image/png'); // begin by assuming the file is unacceptable $sizeOK = false; $typeOK = false; // check that file is within the permitted size if ($_FILES['gallerythumbname']['size'] > 0 && $_FILES['gallerythumbname']['size'] <= MAX_FILE_SIZE) { $sizeOK = true; } // check that file is of a permitted MIME type foreach ($permitted as $type) { if ($type == $_FILES['gallerythumbname']['type']) { $typeOK = true; break; } } if ($sizeOK && $typeOK) { switch($_FILES['gallerythumbname']['error']) { case 0: // define constants define('UPLOAD_DIR', 'C:/wamp/www/test/photos/thumbs/'); define('MAX_WIDTH', 175); define('MAX_HEIGHT', 175); // process the uploaded image if (is_uploaded_file($_FILES['gallerythumbname']['tmp_name'])) { $original = $_FILES['gallerythumbname']['tmp_name']; // begin by getting the details of the original list($width, $height, $type) = getimagesize($original); // calculate the scaling ratio if ($width <= MAX_WIDTH && $height <= MAX_HEIGHT) { $ratio = 1; } elseif ($width > $height) { $ratio = MAX_WIDTH/$width; } else { $ratio = MAX_HEIGHT/$height; } // strip the extension off the image filename $imagetypes = array('/\.gif$/', '/\.jpg$/', '/\.jpeg$/', '/\.png$/'); $name = preg_replace($imagetypes, '', basename($_FILES['gallerythumbname']['name'])); // create an image resource for the original switch($type) { case 1: $source = @ imagecreatefromgif($original); if (!$source) { $result = 'Cannot process GIF files. Please use JPEG or PNG.'; } break; case 2: $source = imagecreatefromjpeg($original); break; case 3: $source = imagecreatefrompng($original); break; default: $source = NULL; $result = 'Cannot identify file type.'; } // make sure the image resource is OK if (!$source) { $result = 'Problem copying original'; } else { // calculate the dimensions of the thumbnail $thumb_width = round($width * $ratio); $thumb_height = round($height * $ratio); // create an image resource for the thumbnail $thumb = imagecreatetruecolor($thumb_width, $thumb_height); // create the resized copy imagecopyresampled($thumb, $source, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height); // save the resized copy switch($type) { case 1: if (function_exists('imagegif')) { $success = imagegif($thumb, UPLOAD_DIR.$name.'.gif'); $thumb_name = $name.'_thb.gif'; } else { $success = imagejpeg($thumb, UPLOAD_DIR.$name.'.jpg', 50); $thumb_name = $name.'_thb.jpg'; } break; case 2: $success = imagejpeg($thumb, UPLOAD_DIR.$name.'.jpg', 100); $thumb_name = $name.'_thb.jpg'; break; case 3: $success = imagepng($thumb, UPLOAD_DIR.$name.'.png'); $thumb_name = $name.'_thb.png'; } if ($success) { $insertSQL = sprintf("INSERT INTO tblmembergallery (gallerythumbname, gallerycaption, gallerydescription, modelid, `date`) VALUES (%s, %s, %s, %s, %s)", GetSQLValueString($thumb_name, "text"), GetSQLValueString($_POST['gallerycaption'], "text"), GetSQLValueString($_POST['gallerydescription'], "text"), GetSQLValueString($_POST['modelid'], "int"), GetSQLValueString($_POST['date'], "date")); mysql_select_db($database_DBConnect, $DBConnect); $Result1 = mysql_query($insertSQL, $DBConnect) or die(mysql_error()); $galleryid = mysql_insert_id(); $_SESSION['galleryid'] = $galleryid; $result = "$gallery created sucessfully. Click <a href='addphoto.php'>here</a> to add photos."; } else { $result = 'Problem resizing image'; } // remove the image resources from memory imagedestroy($source); imagedestroy($thumb); } } break; case 3: $result = "Error uploading $file. Please try again."; default: $result = "System error uploading $file. Contact webmaster."; } } elseif ($_FILES['gallerythumbname']['error'] == 4) { $result = 'No file selected'; } else { $result = "$file cannot be uploaded. Maximum size: $max. Acceptable file types: gif, jpg, png."; } } mysql_select_db($database_DBConnect, $DBConnect); $query_rsgetmodel = "SELECT modelid, modelname FROM tblmembermodel ORDER BY modelname ASC"; $rsgetmodel = mysql_query($query_rsgetmodel, $DBConnect) or die(mysql_error()); $row_rsgetmodel = mysql_fetch_assoc($rsgetmodel); $totalRows_rsgetmodel = mysql_num_rows($rsgetmodel); ?> <!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=utf-8" /> <title>Add Photo Gallery</title> </head> <body> <div align="center"> <?php // if the form has been submitted, display result if (isset($result)) { echo "<p>$result</p>"; } ?> </div> <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="uploadgallery" id="uploadgallery"> <table width="40%" border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td valign="top"><div align="right">Gallery Thumbnail:</div></td> <td valign="top"><input name="MAX_FILE_SIZE" type="hidden" id="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?>" /> <input type="file" name="gallerythumbname" id="gallerythumbname" /></td> </tr> <tr> <td valign="top"><div align="right">Gallery Caption:</div></td> <td valign="top"><input type="text" name="gallerycaption" id="gallerycaption" /></td> </tr> <tr> <td valign="top"><div align="right">Gallery Description:</div></td> <td valign="top"><textarea name="gallerydescription" id="gallerydescription" cols="35" rows="3"></textarea></td> </tr> <tr> <td valign="top"><div align="right">Model:</div></td> <td valign="top"><select name="modelid" id="modelid"> <?php do { ?> <option value="<?php echo $row_rsgetmodel['modelid']?>"><?php echo $row_rsgetmodel['modelname']?></option> <?php } while ($row_rsgetmodel = mysql_fetch_assoc($rsgetmodel)); $rows = mysql_num_rows($rsgetmodel); if($rows > 0) { mysql_data_seek($rsgetmodel, 0); $row_rsgetmodel = mysql_fetch_assoc($rsgetmodel); } ?> </select> <input name="date" type="hidden" id="date" value="<?php echo date ("Y-m-d H:m:s"); ?>" /> <input type="hidden" name="MM_insert" value="uploadgallery" /></td> </tr> <tr> <td colspan="2"><div align="center"> <input type="submit" name="upload" id="upload" value="Create Gallery" /> </div></td> </tr> </table> </form> </body> </html> <?php mysql_free_result($rsgetmodel); ?> Link to comment https://forums.phpfreaks.com/topic/207607-creating-photo-gallery/#findComment-1087477 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.