Jump to content
  • 0

pomoc Problém S Opendir()


jenkings

Dotaz

Ahoj

 

Mám takový problém s fcí opendir :/

 

Mám tenhle kód na vypsání všech složek z dané složky:

<?php
$handle=opendir("../style/");
echo "Soubory:";
while (($file = readdir($handle))!==false):
if (!is_dir($file)) continue;
echo "$file\n";
endwhile;
closedir($handle);
?>

 

Ale netuším proč mi to nefunguje, protože když změním druhý řádek na výpis aktuální složky, tak to normálně vypisuje:

 

$handle=opendir("./");

 

Neví někdo prosím kde dělám chybu ?

Link to comment
Share on other sites

4 odpovědí na tuto otázku

Recommended Posts

  • 0

<?php
$dir = "../style/";
if (is_dir($dir))
{
$handle = opendir($dir);
while (($file = readdir($handle))!==false):
echo "$file\n";
endwhile;
closedir($handle);
}
?>

 

// pokiaľ nechceš aby ti vypísovali zbytočne bodky tak takto:

 

<?php
$dir = "../style/";
if (is_dir($dir))
{
$handle = opendir($dir);
while (($file = readdir($handle))!==false):
if ($file != "." && $file != ".."):
echo "$file\n";
endif;
endwhile;
closedir($handle);
}
?>

  • Líbí se mi to! (+1) 1
Link to comment
Share on other sites

  • 0

Díky ;)

 

P.S. Kdyby to někdo potřeboval taky , tak jsem to ještě trochu upravil aby to nevypisovalo ještě zbytečně tečky:

 

<?php
$dir = "../style/";
if (is_dir($dir))
{
$handle = opendir($dir);
while (($file = readdir($handle))!==false)
{
 if ($file != "." && $file != "..")
{
echo "$file <br>";
}
}
closedir($handle);
}
?>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...