I want to display the images on the php page. Can anybody help? heres the code.
Thanks in advance.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)">
    <meta name="created" content="Sat, 17 Dec 2011 01:37:35 GMT">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <title></title>
    
    <!--[if IE]>
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
  </head>
  <body>
   <?php
   		$reload=$_SERVER['PHP_SELF'];
   ?>
   <form name='download' method='post' name='download' action="<?php $reload?>">
   <?php
   		$dir="d:Upload/";
		if(is_dir($dir))
		{
	 	 if($folder=opendir($dir))
	 	 {
	  	  echo 'Current files: ';
	  	  while(($file=readdir($folder))!==false)
	  	  {
	   	   if(filetype($dir.$file)!='dir'){
	   	   		echo "<br>&nbsp&nbsp<input type='checkbox' name='boxes[]' value='$file'>'$file'</input>";
				}
		  }
	  	  closedir($folder);
	 	 }
		 session_start();
		 $_SESSION['dir']=$dir;
		}
   ?>
   <br>
   <input type="submit" name="submit" value="Download selected file/s"/>
   </form>
   <?php
		if(isset($_POST['submit']))
		{
		 $dir=$_SESSION['dir'];
		 $index=0;
		 echo 'Total count: '.count($_POST['boxes']).'';
		 while($index<count($_POST['boxes']))
		 {
		  if(isset($_POST['boxes'][$index]))
		  {
			$file=$_POST['boxes'][$index];
			$path="$dir$file";
			echo "<br>$path";
		  	
			 header('Content-Description: File Transfer');
    	 	 header('Content-Type: application/octet-stream');
    	 	 header('Content-Disposition: attachment; filename='.basename($path));
    	 	 header('Content-Transfer-Encoding: binary');
    	 	 header('Expires: 0');
    	 	 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    	 	 header('Pragma: public');
    	 	 header('Content-Length: ' . filesize($path));
    	 	 ob_clean();
    	 	 flush();
    	 	 readfile("$path");
			 
			 /*This is what I did but seems it has no changes at all, where have I done wrong?, and I'm new to this actually*/
			 $image=createimagefromjpeg("$path");
			 header('Content-Type:image/jpeg');
			 echo "imagejpeg($image)helo";
			 /*ends here*/
			 
		  }
		  else
		  	  echo "<br>Index: $index not set";
		  
		  $index++;
		 }
	    } 
   ?>



  </body>
</html>

Recommended Answers

All 5 Replies

YOu should also tell what is the problem in displaying.

Whats happening and whats NOT happening.

i have images from my server and I want to retrieve those by displaying it. So, currently, by now I have 5 images on my FOLDER "Images" and those paths were stored on my $path variable.
my upload code by the way is this in case if needed
HERE:

<?php
	 
	 echo $reload=$_SERVER['PHP_SELF'];

	 
?>
<form action="<?$reload?>" method="post" name="fileForm" enctype="multipart/form-data">
   File to upload:
 <table>
  <tr><td><input name="upfile" type="file"></td></tr>
  <tr><td><input type="submit" name="submitBtn" value="Upload"></td></tr>
  </table> 
</form>
<?php
if(isset($_POST['submitBtn']))
{
 if(file_exists("d:/Upload")==0)
 		echo mkdir("d:/Upload");
 $target_path="d:/Upload/";
 $x="d";
 $file_name=$_FILES['upfile']['name'];
 if(file_exists("d:/Upload/$file_name")==0)
 {
  echo '<br>Target Path: '.$target_path=$target_path.basename($_FILES['upfile']['name']).'';
  if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path))
  {
   echo "<br>File:". basename($_FILES['upfile']['name']).' uploaded...';
   echo "<br>Working directory :".getcwd();
  }
  else
 	 echo error;

 }
  else
  	  echo "<br>Error: File duplication";
 }
 
?>
<a href="downloadserver.php"><br>Download</a>

If you have further questions please free to ask. Thanks :D

oh I've fixed it .. lol. No need to answer this now guyz thanks

Just to share the idea, I want to post how I did display multiple image(thumbnails) on php
Here:

<html>
    <head>
        <meta charset="utf=8">
    <head>
    <body>
        <?php
            function createThumbs($pathToImages, $pathToThumbs, $thumbWidth)
            {
                $dir=opendir($pathToImages);
                while(($fname=readdir($dir))!==false)
                {
                    $info=pathinfo($pathToImages.$fname);
                    $path=$pathToImages.$fname;
                    if(strtolower($info['extension'])=='jpg')
                    {
                        echo "<br>creating thumbnail for $fname";
                        $image=imagecreatefromjpeg($path);
                        $width =imagesx($image);
                        $height=imagesy($image);
                        $new_width=$thumbWidth;
                        $new_height=floor($height*($thumbWidth/$width));
                        $tmp_image=imagecreatetruecolor($new_width, $new_height);
                        imagecopyresized($tmp_image, $image, 0,0,0,0, $new_width, $new_height, $width, $height);
                        if((file_exists($pathToThumbs))==0)
                            mkdir($pathToThumbs);
                        else
                            imagejpeg($tmp_image, "$pathToThumbs/.$fname");
                    }
                }
                closedir($dir);
            }
            createThumbs("d:Upload/", "Thumbs", 100);
            function createGallery($pathToThumbs)
            {
                $dir=opendir($pathToThumbs);
                while(($fname=readdir($dir))!==false)
                {
                    $path=$pathToThumbs.$fname;

                    if($fname!='.' && $fname!='..')
                    {
                        echo "<hr>";
                        echo "<img src='$path'>";
                    }
                }
                closedir($dir);
            }
            createGallery("Thumbs/");
        ?>
    </body>
</html>
<html>
	<head>
		<meta charset="utf=8">
	<head>
	<body>
		<?php
			function createThumbs($pathToImages, $pathToThumbs, $thumbWidth)
			{
				$dir=opendir($pathToImages);
				while(($fname=readdir($dir))!==false)
				{
					$info=pathinfo($pathToImages.$fname);
					$path=$pathToImages.$fname;
					if(strtolower($info['extension'])=='jpg')
					{
						echo "<br>creating thumbnail for $fname";
						$image=imagecreatefromjpeg($path);
						$width =imagesx($image);
						$height=imagesy($image);
						$new_width=$thumbWidth;
						$new_height=floor($height*($thumbWidth/$width));
						$tmp_image=imagecreatetruecolor($new_width, $new_height);
						imagecopyresized($tmp_image, $image, 0,0,0,0, $new_width, $new_height, $width, $height);
						if((file_exists($pathToThumbs))==0)
							mkdir($pathToThumbs);
						else
							imagejpeg($tmp_image, "$pathToThumbs/.$fname");
					}
				}
				closedir($dir);
			}
			createThumbs("d:Upload/", "Thumbs", 100);
			function createGallery($pathToThumbs)
			{
				$dir=opendir($pathToThumbs);
				while(($fname=readdir($dir))!==false)
				{
					$path=$pathToThumbs.$fname;
					
					if($fname!='.' && $fname!='..')
					{
						echo "<hr>";
						echo "<img src='$path'>";
					}
				}
				closedir($dir);
			}
			createGallery("Thumbs/");
		?>
	</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.