image gallery image not displaying

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
angelic_devil
Forum Commoner
Posts: 74
Joined: Thu Apr 02, 2009 7:05 am

image gallery image not displaying

Post by angelic_devil »

i have a folder on the server and images already uploaded to that folder....the link to the folder is stored database in table - usersfolder under field- image-path.

now i m trying to get the browser to read the path from image_path and resize the image as thumbnail and display it on the browser.

but i m getting a blank page

here is my code

Code: Select all

 
<?php
 
// Database Constants
define("DB_SERVER", "localhost");
define("DB_USER", "lucky");
define("DB_PASS", "lucky");
define("DB_NAME", "stockphotos");
 
?>
<?php
 
 
// 1. Create a database connection
$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
if (!$connection) {
    die("Database connection failed: " . mysql_error());
}
 
// 2. Select a database to use 
$db_select = mysql_select_db(DB_NAME,$connection);
if (!$db_select) {
    die("Database selection failed: " . mysql_error());
}
?>
 
 
<?php
 
// generating a array with image paths 
 
$query_images = "SELECT image_path FROM userfolders" ;
$result_images = mysql_query($query_images);
confirm_query($result_images);
 
while ($record_images = mysql_fetch_assoc($result_images)) {
          $image_list[] = $record_images['image_path'] ;
          
?>
 
<?php
// generating a thumbnail 
 
$thumb_height = 100;
 
for ($i=0;$i<count($image_list);$i++)
{
// Content type
header('Content-type: image/jpeg');
$filename = $image_list[$i];
list($width, $height) = getimagesize($filename);
$ratio = ($height/$width);
$newheight = $thumb_height;
$newwidth = ($thumb_height/$ratio);
 
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
 
$thumbnail_rezised[$i] = imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
 
  // displaying thumbnail
 
$thumbnail[$i]= imagejpeg($thumb,$filename);
echo '<img src="'{$thumbnail[$i]}'">';
}
?>
 


error i m getting is
Parse error: parse error, expecting `','' or `';'' in D:\wamp\www\php_stockphotos\images_gallery.php on line 63
plz tell me what it is i can tfigure it out also if my code is right for wat i m trying to achieve
Last edited by Benjamin on Wed May 13, 2009 1:08 pm, edited 1 time in total.
Reason: Changed code type from text to php.
Defiline
Forum Commoner
Posts: 59
Joined: Tue May 05, 2009 5:34 pm

Re: image gallery image not displaying

Post by Defiline »

Code: Select all

<?php
 
// Database Constants
define("DB_SERVER", "localhost");
define("DB_USER", "lucky");
define("DB_PASS", "lucky");
define("DB_NAME", "stockphotos");
 
?>
<?php
 
 
// 1. Create a database connection
$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
if (!$connection) {
    die("Database connection failed: " . mysql_error());
}
 
// 2. Select a database to use 
$db_select = mysql_select_db(DB_NAME,$connection);
if (!$db_select) {
    die("Database selection failed: " . mysql_error());
}
?>
 
 
<?php
 
// generating a array with image paths 
 
$query_images = "SELECT image_path FROM userfolders" ;
$result_images = mysql_query($query_images);
confirm_query($result_images);
 
while ($record_images = mysql_fetch_assoc($result_images)) {
          $image_list[] = $record_images['image_path'] ;
          
?>
 
<?php
// generating a thumbnail 
 
$thumb_height = 100;
 
for ($i=0;$i<count($image_list);$i++)
{
// Content type
header('Content-type: image/jpeg');
$filename = $image_list[$i];
list($width, $height) = getimagesize($filename);
$ratio = ($height/$width);
$newheight = $thumb_height;
$newwidth = ($thumb_height/$ratio);
 
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
 
$thumbnail_rezised[$i] = imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
 
  // displaying thumbnail
 
$thumbnail[$i]= imagejpeg($thumb,$filename);
echo '<img src="'.$thumbnail[$i].'">';
}
?>
angelic_devil
Forum Commoner
Posts: 74
Joined: Thu Apr 02, 2009 7:05 am

Re: image gallery image not displaying

Post by angelic_devil »

the code u mentioned is not working still giving error however of parse however i figured it out.

now the browser displays the location of the php file on the browser like

http://localhost/test1.php can anyone tell me y its displaying the location of php and not the image file?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: image gallery image not displaying

Post by Benjamin »

Forum Rules wrote: 11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.
You may also want to read:
  1. General Posting Guidelines
  2. Posting Code in the Forums
  3. PHP Manual
  4. PHP Tutorials
angelic_devil
Forum Commoner
Posts: 74
Joined: Thu Apr 02, 2009 7:05 am

Re: image gallery image not displaying

Post by angelic_devil »

is there anyone who can help me out with this?
angelic_devil
Forum Commoner
Posts: 74
Joined: Thu Apr 02, 2009 7:05 am

Re: image gallery image not displaying

Post by angelic_devil »

since i tried echoing the $width & $height and it shows error

No such file or directory in D:\wamp\www\images\test3.php

plz tell me where i m going wrong

the directory with images is chmod to 777
Post Reply