Jump to content

[SOLVED] Show images that are listed in directory


pcw

Recommended Posts

Hi, I am having a problem with the following script. It prints out the filename for each of the images in the directory but just shows a red cross instead of the image.

 

When I click on properties on the right click menu of the red cross, it shows the wrong directory path. I dont know why, and cant work out how to fix this :(

 

<?php
$username = "paul2";
$path = "../../members/uploads/$username/";
$dir_handle = @opendir($path) or die("Unable to open folder");

while (false !== ($file = readdir($dir_handle))) {

if($file == ".")
continue;
if($file == "..")
continue;

echo "<form action=img.php method=POST>";
echo "<input type=CHECKBOX name=$file>";
echo "<img src='$file' alt='$file'><br />";
echo "<input type=submit name=delete value=Delete>";
echo "</form>";
}
closedir($dir_handle);

?>

 

The code for this is different from an earlier post I made for showing an image for each upload and I cannot use it to solve this problem.

instead of reading it yourself you could also just use scandir()

 

http://be2.php.net/manual/en/function.scandir.php

 

btw

 

if($file == ".")
continue;
if($file == "..")
continue;

 

is the same as:

 

if ($file[0] === '.') continue;

 

which also covers both

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.