Patent has expired in the U.S. The later date is when the Patent expires world wide (IIRC).Originally Posted by Dr Livingston
| SitePoint Sponsor |
Patent has expired in the U.S. The later date is when the Patent expires world wide (IIRC).Originally Posted by Dr Livingston
Jason Sweat ZCE - jsweat_php@yahoo.com
Book: PHP Patterns
Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
Detestable (adjective): software that isn't testable.




my preupload.phpand my upload.phpPHP Code:<? include_once("../header.php" ); ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><img src="../img/banner2.jpg" border="0" vspace="0" hspace="0" name="banner"></td>
</tr>
<tr>
<td valign=top width=16% class="menu">
<? include_once("../menu2.php" ); ?>
</td>
<td width="*%" valign=top>
<?
// include the database specific information
include_once("../inc/db.php" );
// make a connection to the rrc database
dbConnect();
$images_dir = 'photos';
// initialization
$photo_upload_fields = "";
$counter = 1;
// Default number of fields
$number_of_fields = 5;
// If we want more fields, then use, preupload.php?number_of_fields=20
if( $_GET['number_of_fields'])
$number_of_fields = (int) ($_GET['number_of_fields']);
// Firstly Lets build the category list
$query = "SELECT category_id,category_name FROM gallery_category";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
$photo_category_list .= <<<__HTML_END
<option value="$row[0]">$row[1]</option>\n
__HTML_END;
}
mysql_free_result($result);
// Lets build the Image Uploading fields
while($counter <= $number_of_fields) {
$photo_upload_fields .= <<<__HTML_END
<tr><td>
Photo ($counter):
<input name='photo_filename[]' type='file' />
</td></tr>
<tr><td>
Caption:
<textarea name='photo_caption[]' cols='30' rows='1'></textarea>
</td></tr>
__HTML_END;
$counter++;
}
// Final Output
echo <<<__HTML_END
<form enctype='multipart/form-data' action='upload.php' method='post' name='upload_form'>
<table width='90%' border='0' align='center' style='width: 90%;'>
<tr><td>
Select Category
<select name='category'>
$photo_category_list
</select>
</td></tr>
<tr><td>
<p> </p>
</td></tr>
<!--Insert the image fields here -->
$photo_upload_fields
<tr><td>
<input type='submit' name='submit' value='Add Photos' />
</td></tr>
</table>
</form>
__HTML_END;
?>
</td>
</tr>
</table>
<? include_once("../footer.php" ); ?>I have been playing around and I can upload 3 images at once with comments and all is completed properly and all works and is entered into the database but I do more than three then it has a sad and displays the page cannot be displayed errorPHP Code:<? include_once("../header.php" ); ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><img src="../img/banner2.jpg" border="0" vspace="0" hspace="0" name="banner"></td>
</tr>
<tr>
<td valign=top width=16% class="menu">
<? include_once("../menu2.php" ); ?>
</td>
<td width="*%" valign=top>
<?
// include the database specific information
include_once("../inc/db.php" );
// make a connection to the rrc database
dbConnect();
$images_dir = 'photos';
// initialization
$result_final = "";
$counter = 0;
// list of known photo types
$photo_types = array(
'image/pjpeg' => 'jpg',
'image/jpeg' => 'jpg',
'image/gif' => 'gif',
'image/bmp' => 'bmp',
'image/x-png' => 'png'
);
// GD Function suffix
$gd_function_suffix = array (
'image/pjpeg' => 'JPEG',
'image/jpeg' => 'JPEG',
'image/gif' => 'GIF',
'image/bmp' => 'WBMP',
'image/x-png' => 'PNG'
);
// Fetch the image array sent by preuploaed.php
$photos_uploaded = $_FILES['photo_filename'];
// Fetch the image caption array
$photo_caption = $_POST['photo_caption'];
while($counter <= count($photos_uploaded) ) {
if($photos_uploaded['size'][$counter] > 0) {
if(!array_key_exists($photos_uploaded['type'][$counter], $photo_types)) {
$result_final .= "File " . ($counter + 1) . " is not a photo<br />";
} else {
// Great the file is an image, we will add this file
$query = "INSERT INTO gallery_photos (photo_filename, photo_caption, photo_category) VALUES ('0','" . $photo_captions[$counter] . "','" . $_POST['category'] . "')";
mysql_query($query);
$new_id = mysql_insert_id(); // New Id generated
// Get the filetype of the uploaded file
$filetype = $photos_uploaded['type'][$counter];
// Get the extension for the new name
$extension = $known_photo_types[$filetype];
// Generate a new name
$filename = "$new_id.$extension";
// let's update the filename now
$query = "UPDATE gallery_photos SET photo_filename = '$filename' WHERE photo_id = '$new_id'";
mysql_query($query);
// Store the original file
copy($photos_uploaded['tmp_name'][$counter], $images_dir . "/" . $filename);
// Let's go the thumbnail size
$size = GetImageSize($images_dir . "/" . $filename);
// Settings
$Config_tbwidth_wide = 100; // width of wide image
$Config_tbheight_wide = 75; // height of wide image
$Config_tbwidth_tall = 75; // width of tall image
$Config_tbheight_tall = 100; // height of tall image
// The code
if($size[0] > $size[1])
{
$thumbnail_width = $Config_tbwidth_wide;
$thumbnail_height = (int)($Config_tbwidth_wide * $size[1] / $size[0]);
if($thumbnail_height > $Config_tbheight_wide)
{
$thumbnail_height = $Config_tbheight_wide;
$thumbnail_width = (int)($Config_tbheight_wide * $size[0] / $size[1]);
}
}
else
{
$thumbnail_width = (int)($Config_tbheight_tall * $size[0] / $size[1]);
$thumbnail_height = $Config_tbheight_tall;
if($thumbnail_width > $Config_tbwidth_tall)
{
$thumbnail_width = $Config_tbwidth_tall;
$thumbnail_height = (int)($Config_tbwidth_tall * $size[1] / $size[0]);
}
}
// Build Thumbnail with GD 1.x.x, you can use the other methods described too
$function_suffix = $gd_function_suffix[$filetype];
$function_to_read = "ImageCreateFrom".$function_suffix;
$function_to_write = "Image".$function_suffix;
// Read the source file
$source_handle = $function_to_read($images_dir."/".$filename);
if ($source_handle) {
// Let's create a blank image for the thumbnail
$destination_handle = ImageCreate($thumbnail_width, $thumbnail_height);
// Now we resize it
ImageCopyResized($destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1]);
}
// Lets save the thumbnail
$function_to_write($destination_handle, $images_dir."/tb_".$filename);
ImageDestroy($destination_handle);
$result_final .= "<img src="".$images_dir. "/tb_".$filename.""/> File ".($counter+1)." Added<br />";
}
}
$counter++;
}
// Print Result
echo <<<__HTML_END
$result_final
__HTML_END;
?>
</td>
</tr>
</table>
<? include_once("../footer.php" ); ?>
Hello,
Im getting a parse error from this line:
// Firstly Lets build the Category List
$result = mysql_query('SELECT category_id,category_name FROM gallery_category');
while($row = mysql_fetch_array($result)) {
$photo_category_list .= <<<__HTML_END
<option value="$row[0]">$row[1]</option>\n
__HTML_END;
}
mysql_free_result( $result );
I have no idea what that means!
Jake
the total size of files you can upload at one go is limited to the value set in your php.ini for, upload_max_filesizeOriginally Posted by noddy
By default it is set to 2M (= 2 MB)
at which line no. do you get the error?Originally Posted by rutters





That was it SweatjeCouldn't exactly remember what it was that's all
...




now that I got my gallery finished and completed i had images that were pulled from the old files that contained the images but now its all in the db how do i modify this code as so the images display themselves again?
and the display onePHP Code:<? $dirname="./pic/photos" ;
$files = array();
$dir = opendir( $dirname );
while( $file = readdir( $dir ) ) {
if (eregi("\.jpe?g$", $file) ||
eregi("\.gif$", $file) ||
eregi("\.png$", $file)) {
$files[] = $file;
}
}
?>
<?
$pictures = $files;
shuffle($pictures);
?>
I want to use the same thumbs nails from the db which are in a folder but it doesnt have a name have everyone elses been like that too?PHP Code:<?
for ($i = 0; $i < 3; $i++)
{
echo "<td align=center valign=middle><a href=""\"./pic/photos/$pictures[$i]\" target=\"_blank\"><img src=""\"./pic/photos/";
echo $pictures[$i];
echo "\" width=180 heigh=180 alt=$pictures></a></td>";
}
?>
hmm ... well i am not sure what you are trying to say ... can you explain a little ...
great, do post your gallery url (if its public) ...




sure is http://radiorally.lionslair.net.au/goto/list_all_cats
users can add their own pics and categories the admin stuff i wil do later in the meantime ill just edit it through phpmyadmin![]()
Nice tutorial, but it is a bit of re-inventing the wheel. Gallery is open source, full featured and supported by a huge community:
http://gallery.menalto.com/index.php
It's always good to improve skills, but why not stand on the shoulders of others and make something even better?
Excellent tutorial. i'm a complete php newbie, and this was a good introduction to some new techniques for me. however...
i would like to have sub-categories within my categories, and have tried various things that haven't worked (i've only been learning a week or so, so my efforts haven't been too impressive!). could anyone give me any hints or pointers about what i should be doing?
![]()
Noddy, I agree that 'Gallery' already solves the problem of displaying images, but some of us use tutorials to learn from and not just to copy and paste code. For me, 'Gallery' is overkill and a pain in the a** to brand to my site. I think the information in this article is excellently presented for a novice/intermediate coder to understand and use in their own situations. I wish I could have found all this information in one place when I was needing to implement thumbnail resizing.




Yeah sorry but although the display that I have out putted and used is much the same I will be using and changing it in the future but you got to start somewhere mate and now I have read through and used this one I will be abe to go through and expand on it later myself!Originally Posted by Anonymous
Thank You!! I am been looking for something like this for a long time!!
I love being able to drop this into my current website layout.
I am in the process of redesigning my site according to xhtml 1.0 standards using pure css for layout with no tables. I successfully altered this script to use my "float class" The results can be seen here.
http://www.anglersforchrist.com/test/viewgallery.php
I had to set it to only resize by the height of the thumbnail and not the width. Otherwise, it would not wrap around properly. The pictures would be liquid or "self-wrapping" depending on screen size if I didn't have them in a nested DIV.
What is was wondering is how I could limit the width of the picture to about 400 pixels. I know a separate resize function would need to be written, but I cannot figure out how to implement it.
Any help would be appreciated. I will post my css and viewgallery.php if anyone is interested in tackling a no-tables version. Thanks again for this wonderful tutorial. I am very grateful.
Last edited by animal777; Aug 27, 2003 at 02:52.
I am trying to format the output of the Full size view of the beads by having the fields output into a table, but I am getting a :
Parse error: parse error, unexpected T_LNUMBER in /hsphere/local/home/selena/mirabilusdesigns.com/viewgallery.php on line 184
The table so far looks like this (I have a few extra fields because I am using this as an artist's portfolio)
(starting at line 184)
The whole section is:Code:$result_final .= "<tr>\n\t<td rowspan="3"> <img src="".$images_dir."/".$beads_filename."" border='0' alt='".$beads_title."'/></td> <td colspan="2">Title:</td> <td colspan="2">$beads_title</td> </tr> <tr> <td>Date Available as of:</td> <td>$beads_date_avail</td> <td>Size:</td> <td>$beads_size</td> </tr> <tr> <td colspan="2">Details:</td> <td colspan="2">$beads_caption</td> </tr>"; } }
Can someone help me out?Code:else if( $pid ) { $result = mysql_query( " SELECT beads_filename, beads_title, beads_size, beads_caption, beads_date_avail, FROM portfolio_beads WHERE beads_id='".addslashes($pid)."' " ); list($beads_filename, $beads_title, $beads_size, $beads_date_avail, $beads_caption) = mysql_fetch_array( $result ); $nr = mysql_num_rows( $result ); mysql_free_result( $result ); if( empty( $nr ) ) { $result_final = "\t<tr><td>No Beads in this Category right now, check back later!</td></tr>\n"; } else { $result = mysql_query( " SELECT category_name FROM portfolio_category WHERE category_id='".addslashes($cid)."'" ); list($category_name) = mysql_fetch_array( $result ); mysql_free_result( $result ); $result_final .= "<tr>\n\t<td> <a href="viewgallery.php">Categories</a> > <a href="viewgallery.php?cid=$cid">$category_name</a></td>\n</tr>\n"; $result_final .= "<tr>\n\t<td rowspan="3"> <img src="".$images_dir."/".$beads_filename."" border='0' alt='".$beads_title."'/></td> <td colspan="2">Title:</td> <td colspan="2">$beads_title</td> </tr> <tr> <td>Date Available as of:</td> <td>$beads_date_avail</td> <td>Size:</td> <td>$beads_size</td> </tr> <tr> <td colspan="2">Details:</td> <td colspan="2">$beads_caption</td> </tr>"; } }
Thanks!
Corinne




Originally Posted by MirabilusDesigns
Try
PHP Code:$result_final .= "<tr>\n\t<td rowspan='3'>
<img src=".$images_dir."/".$beads_filename." border='0' alt='".$beads_title."'"/></td>
<td colspan="2">Title:</td>
<td colspan="2">$beads_title</td>
</tr>
<tr>
<td>Date Available as of:</td>
<td>$beads_date_avail</td>
<td>Size:</td>
<td>$beads_size</td>
</tr>
<tr>
<td colspan="2">Details:</td>
<td colspan="2">$beads_caption</td>
</tr>"; }
}

Following Mayank's tutorial, I've successfully built a working gallery system. Now, on page 8 of his tutorial he adds references to more functionality one might build in. Thus far I've not been able to determine how to place these functions.
Specifically Add Category:
It seems to me any of them would be part of the preupload.php file, and yet adding them so that this same file would return itself ...I'm finding to be difficult.
The page should return itself by means of the form submit button in order to display the newly added category in the drop down list, something like;
and yet in Mayank's plan, the preupload.php file has a form which submits and returns the 'upload.php'. It seems to me a large if/else statement should be implemented depending upon what data is being submitted.Code:<form action="<?=$_SERVER['PHP_SELF']?>" method='post' >
And as I go along this line of thought, I remember his words that "...that might sound like a lot of work, but actually, it isn't..." and his simple few lines of code make me feel as though I'm making a mountain of this mole hill.
Could someone please advise? I cannot imagine I'm the only person trying to do this, hopefully any help submitted would be received by many.
Try this code to have a single upload file instead of 2:
Save this page and set the form action to the same name.Code:<?php include("config.inc.php"); if ($_SERVER['REQUEST_METHOD'] == "POST") { <insert upload.php contents here> } else { <insert preupload.php contents here> } ?>
I had trouble with PHP_SELF
Last edited by animal777; Sep 2, 2003 at 19:29.
yes you can use that way too (quite innovative way) ... but i meant in the last section was to give a brief idea of how to make a administration secion ... as i felt not many would be interested so i kept it a little short ...
for Adding / Deleting categories can be done via separate page (make it sure it is not accessiable by anyone but you) ...
similarly you can add the rest of the functions ...PHP Code:<?php
include("config.inc.php");
if( empty($_POST['action']) )
{
// Firstly Lets build the Category List
$result = mysql_query( "SELECT category_id,category_name FROM gallery_category" );
while( $row = mysql_fetch_array( $result ) )
{
$category_list .=<<<__HTML_END
<option value="$row[0]">$row[1]</option>\n
__HTML_END;
}
mysql_free_result( $result );
$category_list = '<select name="categoryid">'.$category_list.'</select>';
?>
<form name="add_category" action="admin.php" method="post">
<b>Add Category:</b><br />
Name: <input type="text" name="cname" />
<input type="submit" value="add" name="action" />
</form>
<br /><br />
<form name="edit_category" action="admin.php" method="post">
<b>Edit Category:</b><br />
New Name: <input type="text" name="cname" />
<?php echo($category_list); ?>
<input type="submit" value="edit" name="action" />
</form>
<br /><br />
<form name="delete_category" action="admin.php" method="post">
<b>Delete Category:</b><br />
<?php echo($category_list); ?>
<input type="submit" value="delete" name="action" />
</form>
<?php
}
else
{
if( strcasecmp($_POST['action'], "add")==0 && !empty( $_POST['cname'] ) )
{
add_category($_POST['cname']);
}
else if( strcasecmp($_POST['action'], "edit")==0 && !empty( $_POST['cname'] ) && !empty( $_POST['categoryid'] ) )
{
edit_category($_POST['categoryid'], $_POST['cname']);
}
else if( strcasecmp($_POST['action'], "delete")==0 && !empty( $_POST['categoryid'] ) )
{
delete_category($_POST['categoryid']);
}
else
{
echo("Action not understood"); exit;
}
echo("Process completed!");
}
// the functions here
function edit_category($category_id, $new_name)
{
mysql_query("
UPDATE gallery_category SET
category_name = '" . addslashes($new_name) . "'
WHERE category_id = '" . addslashes($category_id) . "'");
}
function add_category($category_name)
{
mysql_query("
INSERT INTO gallery_category (
category_name
) VALUES (
'" . addslashes($category_name) . "'
)");
}
function delete_category($category_id)
{
global $images_dir;
$result = mysql_query("
SELECT photo_filename
FROM gallery_photo
WHERE photo_category='" . addslashes($category_id) . "'");
while ($row = @mysql_fetch_array($result)) {
unlink($images_dir . '/' . $row[0]);
}
mysql_query("
DELETE FROM gallery_photo
WHERE photo_category='" . addslashes($category_id) . "'");
mysql_query("
DELETE FROM gallery_category
WHERE category_id='" . addslashes($category_id) . "'");
}
?>
i hope this helps ..

What a great learning experience! Three different camps in this prairie, thank you all.
Noddy,
I'm quite interested in your method as well. Would you add to your idea, perhaps show how you've added Mayank's function to your upload.php?
Animal777,
I'm interested in your table-less CSS approach which you mentioned in another post. I'm designing most everything with the goal of using only CSS and I think you would have much to teach with your example. Are you designing the forms too?
Mayank,
Thank you for responding. I have to say that as is, the code you have posted is not returning a page for me (I realize it is probably do to my own php limitations and not your code). I'm working through it though and your insight is important to me.
I would disagree with you that "not many would be interested in this" because to me, control is the whole purpose of creating an automated gallery section. Would you agree that editing a tool such as 'automated gallery' is just as important as creating it in the first place?
Is the admin.php yet another page, or is that what you've named the page you have illustrated in the code you've posted above?
Also, in your tutorial, when you say, "Well, that might sound like a lot of work, but actually, it isn't" and you post functions ...well, it seems to me, at this moment anyway, that understanding these 'helpful additions' would benefit students greatly if explained further.Code:<form name="delete_category" action="admin.php" method="post">
I know..I know...I'm a newbie, but I am unable to figure out what __HTML_END is all about. Is this a funtion, or a comment? Any links to an explaination. Thank you SOOOO much...excellant article btw!!!
Bookmarks