Php Image display help

<?php $dirname = "Snaps/"; if(@is_dir($dirname) && @is_readable($dirname)) { $images = scandir($dirname); $ignore = Array(".", ".."); foreach($images as $curimg){ if(!in_array($curimg, $ignore)) { echo "

\n"; }; } } ?>

THE ABOVE CODES DISPLAYS THE IMAGE FROM DIRECTORY… If the is no image then no images get displayed… thats all fine… I WANNA KNOW IS IT POSSIBLE TO DISPLAY AN MESSAGE IF THR IS NO IMAGES FOUND IN DIRECTORY… msg in text like “NO IMAGES FOUND”…

So som1 please help ASAP…

mail it to [email protected]

You can ese a variable that count images showns, also you can use the function count,

if count($images>2) // Always are “.” and “…”

[php]<?php
$counter =0;
$dirname = “Snaps/”;

if(@is_dir($dirname) && @is_readable($dirname)) {
$images = scandir($dirname);
$ignore = Array(".", “…”);
foreach($images as $curimg){
if(!in_array($curimg, $ignore)) {
$counter++;
echo "



";

       }
  } 

}

if($counter==0){
echo" NO IMAGES FOUND
";
}

?>
[/php]

Warning: scandir(Snaps/) [function.scandir]: failed to open dir: No such file or directory in /html/sad.php on line 21

Warning: scandir() [function.scandir]: (errno 2): No such file or directory in /html/sad.php on line 21

Warning: Invalid argument supplied for foreach() in /html/sad.php on line 23
NO IMAGES FOUND

Getting error like this when thr is no images in dat particular folder… I just want “NO IMAGES FOUND” to be displayed…

Does directory exists?
if this exists, you have privileges to read and execute this?

the directory doesnt exist…

I have an upload page whr i can upload a image & then that image will be saved in a directory… so i want to display dat image using above codes… So if there is no image then i want to display “NO IMAGE FOUND”… & directory name is different for different users … Directory name is on user’s logged in user id…

try to remove @ from is_dir

This will not have error, if have error post this and let’s try to view an alternative result.

its working fine… thnks a lot… GOD BLESS YOU…

I need another favour from a genius like u…

Now i have two div tags …

1 showing upload img from directory. & another showing another img (it ll be uploaded by admin)

  • : 1st user uploads the pict then it gets uploaded to his directory n it ll be shown thru above codes…
    ** : after user upload admin upload another img in his directory & that gets displayed using same code in another div tag…

So i wanna know is lets say 1st div tag name is FIRST. ( here user’s uploaded img is displayed if img is uploaded by user)

& another div tag name as SECOND. ( here if user has not uploaded any img, den i want to show a text "DOES NOT EXIST " & if user uplaods then show another msg like “PROCESSING” & after admin uploads the img in dat directory den display da uploaded img by admin itself ) I hope u got wt i m sayin… :frowning:

If u did not understnd den please let me know… i ll surely explain properly in detail…

I’m not sure that you want it, but if you don’t please post it

I think that you want 2 div,
1 - with images uploads by user and confirmed by admin,
2- status of images upload, DOES NOT EXISTS or PROCESSING until admin confirmed

I don’t know how admin confirm, there are multiples solutions,

if you use database, you can mark inside confirm.
But in code that you post there is no database, i supposed that you don’t use.
[php]

<?php $counter =0; $dirname = "SnapsConfirmed/";
  if(is_dir($dirname) && is_readable($dirname)) {
        $images = scandir($dirname);
        $ignore = Array(".", "..");
        foreach($images as $curimg){
              if(!in_array($curimg, $ignore)) {
                    $counter++;
                    echo "<img src='Snaps/$curimg' /> <br/>
                             <br/>
                              ";

             }
       } 
 }
  ?>
<?php $counter =0; $dirname = "Snaps/";
  if(is_dir($dirname) && is_readable($dirname)) {
        $images = scandir($dirname);
        $ignore = Array(".", "..");
        foreach($images as $curimg){
              if(!in_array($curimg, $ignore)) {
                    $counter++;
                    echo "<img src='Snaps/$curimg' /> &nbsp; PROCESSING<br/>
                             <br/>
                              ";

             }
       } 
 }

 if($counter==0){
      echo" DOES NOT EXISTS<br>";
 }

  ?>
[/php]

Another solutions are move confirmed images to an other directory

There are many solutions alternatives, but try with this.

Sponsor our Newsletter | Privacy Policy | Terms of Service