|
Posted by J.O. Aho on 07/25/06 04:02
Michael martin wrote:
> I'm trying to create a picture database for a site that I'm working on and I
> would like to do the following:
> - (main goal) Have a php script load an entire directory of photos into my
> mysql database in one swoop.
> - Display thumbnails on a general viewing page.
> - allow for viewing individual pictures by clicking on the thumbnails
>
> Got something like this;
> <?php
> error_reporting(E_ALL);
> $id = $_REQUEST["iid"];
> $link = mysql_connect("localhost", "root", "") or die("Could not connect:
> " . mysql_error());
>
> mysql_select_db("mysql") or die(mysql_error());
> $sql = "SELECT b1 FROM t1 where id in (1,2,3)";
>
> $result = mysql_query("$sql") or die("Invalid query: " . mysql_error());
> header("Content-type: image/jpeg");
>
> while ($row = mysql_fetch_array($result))
> {
> $fileContent = $row['b1'];
>
> $im = imagecreatefromstring($fileContent);
> $width = imagesx($im);
> $height = imagesy($im);
> $imgw = 50;
> $imgh = $height / $width * $imgw;
> $thumb = ImageCreate($imgw,$imgh);
>
> ImageCopyResized($thumb,$im,0,0,0,0,$imgw,$imgh,ImageSX($im),ImageSY($im));
> ImagejpeG($thumb);
>
> imagedestroy ($im);
> imagedestroy ($thumb);
> mysql_close ($link);
> }
> ?>
>
> But only displaying one image.
Yes, it's not that strange, try to use the html img-tag and show more than one
image with only one such tag. Even if you stream all the image data, you will
still only have one image.
The mysql_close() is suposed to be placed outside the while loop and not
inside (this change won't make your images be all displayed with only one use
of a script).
//Aho
Navigation:
[Reply to this message]
|