Jump to content

Help with getting files


Schlo_50

Recommended Posts

I have written a script that find files stored in folders and prints out links to them. This works but now im having problems with an else statement. If there are no files in the folder I want to print a sentence but the sentence prints more than once..

 

Can somebody help please?

 

  if ($handle = opendir($dir_path))  { 
   while (false !== ($file = readdir($handle)))  { 
    if (eregi("\.". $doc_types ."$", $file) || eregi("\.". $xls_types ."$", $file) || eregi("\.". $pdf_types ."$", $file))  {
     $tmp_file_path = $dir_path . $file; 
     print "<img src=\"images/word_icon.jpg\"> <b><a href=\"$tmp_file_path\">$file</a></b><br>"; 
       } 
   else {
   print "No Agendas or Minutes available. Please select another year.";
   }
     }
  closedir($handle); 
}

 

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/116589-help-with-getting-files/
Share on other sites

Add a variable could be a quick fix.

 

 
$z = 0;

if ($handle = opendir($dir_path))  { 
   while (false !== ($file = readdir($handle)))  { 
    if (eregi("\.". $doc_types ."$", $file) || eregi("\.". $xls_types ."$", $file) || eregi("\.". $pdf_types ."$", $file))  {
     $tmp_file_path = $dir_path . $file; 
     print "<img src=\"images/word_icon.jpg\"> <b><a href=\"$tmp_file_path\">$file</a></b><br>"; 
       } 
   else if($z == 0) {
     print "No Agendas or Minutes available. Please select another year.";
                  $z = 1;
   }
     }
  closedir($handle); 
}

 

Cheers,

 

Steve

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.