Schlo_50 Posted July 25, 2008 Share Posted July 25, 2008 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 More sharing options...
Skittalz Posted July 25, 2008 Share Posted July 25, 2008 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 Link to comment https://forums.phpfreaks.com/topic/116589-help-with-getting-files/#findComment-599528 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.