Autor Zpráva
H13
Profil
Ahoj potřeboval bych poradit, jak udělat php skript, který vypíše data ze složky (soubory, podsložky), např.


vypis ze slozky 'slozka':

- slozka/obrazky/obrazek.png
- slozka/obrazky/druhy_obrazek.png
- slozka/soubory/prvni_soubor.png
- slozka/index.html ...


díky za jakoukoliv radu
Paulí
Profil *
zkus tohle :

<?
function recrusive_dirlist($base_dir)
{
global $getDirList_alldirs,$getDirList_allfiles;
function getDirList($base)
{
global $getDirList_alldirs,$getDirList_allfiles;
if(is_dir($base))
{
$dh = opendir($base);
while (false !== ($dir = readdir($dh)))
{
if (is_dir($base ."/". $dir) && $dir !== '.' && $dir !== '..') //note the change in this line
{
$subs = $dir ;
$subbase = $base ."/". $dir;//note the change in this line
$getDirList_alldirs[]=$subbase;
getDirList($subbase);
}
elseif(is_file($base ."/". $dir) && $dir !== '.' && $dir !== '..')//change in this line too
{
$getDirList_allfiles[]=$base ."/". $dir;//change in this line too
}
}
closedir($dh);
}
}

getDirList($base_dir);
$retval['dirs']=$getDirList_alldirs;
$retval['files']=$getDirList_allfiles;
return $retval;
}

// příklad použití:
echo '<pre>';
print_r(recrusive_dirlist('./'));
echo '</pre>';
?>

Ale musíš změnit složku , ve které chceš zobrazit soubory a podložky takže změň hodnotu na 3. řádku od spoda , jak tam je "print_r(recrusive_dirlist('./'));" tak to změň třeba na "print_r(recrusive_dirlist('/moje_slozka/'));" ......... chápeš ???
k
Profil *
Paulí
eh.. zajimavy zpusob psani kodu..
Paulí
Profil *
pro :"k"
A proč ???
k
Profil *
mit metodu v dalsi metode? Proc?
Paulí
Profil *
Ale funguje to - klidně ozkoušej !!!
k
Profil *
netvrdim ze to nefunguje(nevim - urcite to bude hazet par notice). tvrdim ze je to zajimave napsane.

function recrusive_dirlist($base)
{
$getDirList_alldirs = array();
$getDirList_allfiles = array();

if(is_dir($base))
{
$dh = opendir($base);
while (false !== ($dir = readdir($dh)))
{
if (is_dir($base ."/". $dir) && $dir !== '.' && $dir !== '..') //note the change in this line
{
$subs = $dir ;
$subbase = $base ."/". $dir;//note the change in this line
$getDirList_alldirs[]=$subbase;
getDirList($subbase);
}
elseif(is_file($base ."/". $dir) && $dir !== '.' && $dir !== '..')//change in this line too
{
$getDirList_allfiles[]=$base ."/". $dir;//change in this line too
}
}
closedir($dh);
}
}

$retval = array();
$retval['dirs']=$getDirList_alldirs;
$retval['files']=$getDirList_allfiles;
return $retval;
}

tohle udela to same a neni potreba mit v te metode dasli metodu..
H13
Profil
Paulí
k

díky moc
Paulí
Profil *
pro "k"
A jakto , že mě to nejde ??? a kde máš místo na zadání , ze které složky to má být zobrazeno ???
k
Profil *
Paulí
Prosimte..
Upravoval jsem tu funkci, proto jsem vypsal jen ji.
H13 urcite vi jak ji zavolat a predat ji parametr.
Toto téma je uzamčeno. Odpověď nelze zaslat.

0