Hi can any one Fix this problem,

I am Uploading images to a folder , There i displays images but unfortunately display only the file name and not the image can any help me, BELOW IS THE CODE

[LIST=1]


[*]<?php
[*]	include 'dbcon.php';
[*]?>

[*]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
[*]<html>
[*]<head>
[*]<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
[*]<title>DISPLAY IMAGES</title>
[*]</head>

[*]<body>
[*]<form action="display.php" method="post">

[*]<?php
[*]include 'aindex.php';
[*]$qry = "select * from tbl_album order by 'image_name'"; 
[*]$rst=mysql_query($qry,$con);
[*]$img_src="C:/wamp/www/prawin/new/locations/test/upload/image/";
[*]//$dir ="../display/uplaod/";
[*]  $filename=basename($_FILES['uploadfile']['name']);
[*]        $handle = opendir ("$img_src");
[*]?>
[*]	<table width="70%" cellpadding=" 5px " cellspacing="45" 
align="center" id="index">
[*]<?php
[*]		$cnt=0;
[*]        while (false !== ($file = readdir($handle))) {
[*]            if($file != "." && $file != ".." && $file != basename(__FILE__)) {
[*]				if(preg_match('/.*\.(.*)/',$file,$result)){
[*]					$ext = $result[1];
[*]				}
[*]				if($file != ""){
[*]					if($ext == 'gif' || $ext == 'jpg' || $ext == 'jpeg' || $ext == 'png'){
[*]						if($cnt == 0){
[*]							echo '<tr>';
[*]						}		
[*]						echo '<td><img src="'.$file.'"/><br/>'.$file.'</td>';
[*]						if($cnt == 2){
[*]							echo "</tr>";
[*]							$cnt=0;
[*]						}else{
[*]							$cnt++;
[*]						}
[*]					}
[*]				}
[*]				if($filename != "")
[*]				 echo '<img src="'.$filename.'"/>';
[*]            }
[*]        }
[*]?>		
[*]</table>
[*]<?
[*]if(!rst)
[*]{
[*]die("error"  .mysql_error());
[*]}
[*]mysql_close($con);

[*]?>


[*]</form>


[*]</body>
[*]</html> [/LIST]

Edit your post. Use [code] tags to wrap your code for better readability (and better response).

Post your code in code tags. Not everything! Before you click 'Submit' click on 'Preview' button. See if it is readable. If it is readable, then click on submit. :confused:

Okay! So.. When I checked the source of the script, there was only name and not the path.. You have to give the path to your images.. Secondly, You don't have to give the whole path, ie.,

$img_src="C:/wamp/www/prawin/new/locations/test/upload/image/";

Since you are executing the script from http://localhost, this should work just fine.

$img_src="prawin/new/locations/test/upload/image/";

Lastly, you have to concat $img_src to $filename to get the path of the image.

echo '<img src="'.$img_src.$filename.'"/>';

And please indent your code. Indentation is very helpful when you have more than 2 lines of code. :)

Hi,

Giving Full path to the img src="" will display the image....

As nav33 told...

Regards,
Fatty

Hello nav33n,
Thanks For UR Reply , but No RESULT ,Same as of BEFORE .

<?php	include 'dbcon.php';?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>DISPLAY IMAGES</title>
</head>
<body>
<form action="display.php" method="post">
<?php 
include 'aindex.php';
$qry = "select * from tbl_album order by 'image_name'";
$rst=mysql_query($qry,$con);
$img_src="./images/";
//$dir ="../display/uplaod/";  
$filename=basename($_FILES['uploadfile']['name']);        
$handle = opendir ("$img_src");?>
<table width="70%" cellpadding=" 5px " cellspacing="45" align="center" id="index">
<?php
$cnt=0;
while (false !== ($file = readdir($handle))) {
	if($file != "." && $file != ".." && $file != basename(__FILE__)) {
	  if(preg_match('/.*\.(.*)/',$file,$result)){
   		$ext = $result[1];
	  }
	  if($file != ""){
		if($ext == 'gif' || $ext == 'jpg' || $ext == 'jpeg' || $ext == 'png'){
	    	if($cnt == 0){
				 echo '<tr>';						
			}
			echo '<td><img src="'.$img_src.$file.'"/><br/>'.$file.'</td>';
			if($cnt == 2){
				 echo "</tr>";
				 $cnt=0;
	 		} else {
				 $cnt++;
			}
		}
	}
	if($filename != "")				 
		echo '<img src="'.$img_src.$filename.'"/>';            
	}
}
?>
</table>
<?if(!rst){
 die("error"  .mysql_error());
 }
mysql_close($con);
?>
</form>
</body>
</html>

:icon_rolleyes: Change $img_src to the folder which has images. And make sure you have given the right path.
I have this script in www folder and images is a folder in www.

P.S It works for me. So, if it doesn't work for you, then it has to be the path.

Hello nav33n,
Thanks For UR Reply , but No RESULT ,Same as of BEFORE .

hi can u check the $filename extention.....extention is there or not?

In HTML code, find the source code by pressing ctrl+u.... Then check the image src is displayed.... (i.e) Check the src has been displayed.... and copy the src and paste in new tab..... If the image is displayed there..... then it should display in ur HTML

Jus check that one and see
Also echo ur $file and $img_src, check wt it is displaying

Thank u for all who giving solutions to me,
Unfortunately with all these solns , iam unable to get image, what i am trying is , i actually use on line 16 $handle = opendir ("./") instead of $handle = opendir ("$img_src"); this small modification displays all the images in the folder where my program is residing. What i am trying to get now is to get the images from the folder Images ie $img_src="C:/wamp/www/prawin/new/locations/test/upload/image/";

#
$img_src="./images/";
$handle = opendir ("$img_src");

but i get here is only the file name and i didnt get the images.

Where have you placed your script ? In which folder ?

Did you check the above script I gave you ? Did you try replacing $img_src="./images/"; with your path ?

              $dir1="./images"                               
                           if ($open_dir = opendir($dir1)) 
               { 
                            while (($file = readdir($open_dir)) !== false) 
            {
                $file_name = $file;
                $dirPath = $dir1."/".$file."";
                if(is_file($dirPath))
                                    {
                                       //check for image type if so then display
                                        <img src='".$dirPath."'>
                                     }
                           }
                           }

Edited 3 Years Ago by mike_2000_17: Fixed formatting

HI nav33n,
this code displays images and image name
on line 16

$handle = opendir ("./") 
script path--- C:\wamp\www\prawin\new\locations\test

where images are also in this path .

and for

$img_src="./image/";
$handle = opendir ("$img_src");
script  path : C:\wamp\www\prawin\new\locations\test
imagespath : C:\wamp\www\prawin\new\locations\test\upload\image

for this code it displays only the image name.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

$dir1="./images"
if ($open_dir = opendir($dir1))
{
while (($file = readdir($open_dir)) !== false)
{
$file_name = $file;
$dirPath = $dir1."/".$file."";
if(is_file($dirPath))
{
//check for image type if so then display
<img src='".$dirPath."' border="0">
}
}
}

prawin@123 : Jus use this code and see

Images are displaying for me

Check out..... Please....

This article has been dead for over six months. Start a new discussion instead.