This section of code collects data from a database and puts those values into some local variables. The object here is to loop through the values and display them, in this case, file names, via HTML to view within the broswer. I can get the basic process to work, but I’m attempting to incorportate additional PHP code to scale-down the images into thumbnails so that they arn’t squished.
The problem I’m having is that the file names from my database arn’t getting loaded into the Class. Currently the result I get is several empty image files with the correct captions for each.
Can anyone look at this code and offer any suggestions?
/*Following while loops the output until all images have
been displayed*/
while ($photo = mysql_fetch_array($photos)) {
/*The following assignments put values from the database
into local variables*/
$id = $photo['id'];
$caption = htmlspecialchars($photo['caption']);
$filename = ($photo['file_name']);
$filepath = 'photos/' . $filename;
$newfilepath = 'photos/new' . $filename;
/** PHP code to porportionally convert image
to a thumbnail **/
require_once("thumbnail.class.php");
$tn= new Thumbnail(200,200);
$image = file_get_contents($filepath );
$tn->loadData($image, 'image/jpeg');
/*******************************/
/*The following line of code outputs to the browser the recreated image from within the buildThumb() class function*****/
echo "<li><img src='" . $tn->buildThumb($newfilepath) .
"'alt='' width='200' height='200'>" . $caption . "</li>";
/*******************************************/
}
?>
src requires a string, you can’t stick a file in there. Usually you would do something like
<img src=“thumb_generator.php?size=200&img=path/to/image.jpg”>
if it is returning a string (what does view source have in it?) then I think that code looks ok, so you will have to debug a bit and find out where it breaks
require_once("thumbnail.class.php");
$tn= new Thumbnail(200,200);
var_dump($filepath); //debugging
$image = file_get_contents($filepath );
if(false === $image) echo 'file not read'; //debugging
$tn->loadData($image, 'image/jpeg');
hash–
Have you ever had one of those days when you just can’t think right? The whole problem was a simple error in code grammer. The problem was in the last line of PHP code that you indicated. I couldn’t figure out how to get the syntax correct to output the information. I took a break and came back later and fixed the problem in 5 minutes. Go figure…
Thanks for the offer of help anyway
<?php
$photos = @mysql_query($select . $from . $where);/*Refferences some
SQL not shown*/
if (!$photos) {
exit('<p>Error retrieving photos from database!<br />'.
'Error: ' . mysql_error() . '</p>');
}
/*Following while loops the output until all images have been
displayed*/
while ($photo = mysql_fetch_array($photos)) {
/*The following assignments put values from the database into local variables*/
$id = $photo['id'];
$caption = htmlspecialchars($photo['caption']);
$filename = ($photo['file_name']);
$filepath = 'photos/' . $filename;
$newfilepath = 'photos/new' . $filename;
/**** PHP code to porportionally convert image to a thumbnail ****/
require_once("thumbnail.class.php");
$tn= new Thumbnail(200,200);
$image = file_get_contents($filepath );
$tn->loadData($image, 'image/jpeg');
$tn->buildThumb($newfilepath)
/******************************************/
/*The following line of coade outputs to the browser the recreated image within the buildThumb() class function*****/
[B] ?>
<li><img src='<?php echo $newfilepath;?>' alt=''
width='<?php echo ( $tn->getThumbWidth());?>'
height='<?php echo ($tn->getThumbHeight());?>'>/*end of
<img>*/<?php echo $caption;?></li>
<?php [/B] }
?>