Zdravím...
Potrebujem prehľadať zložku v zadanom umiestnení (povedzme $path = "./directory1/") a všetky súbory aj s príponou zapísať do pola $pole[] ...
Tuším, že to má byť pomocou foreach ale absolútne netuším, ktorá z mnohých funkcií (súborových) to je. Prosím pomoc! Móóóc ďakujem!
Fórum › PHP
Prehľadávanie zložky [PHP]

:D ahoj
zrovna v dotazu co jsem položil před tebou jsem použil script, co bys mohl použít.. řeším tam sice problém s tím, že mi f-ce is_dir nechce rozpoznat složku od adresáře, ale jinak zbytek je naprosto funkční...
jinak v manuálu můžeš najít:
<?php
$dir = '/tmp';
$files1 = scandir($dir);
$files2 = scandir($dir, 1);
print_r($files1);
print_r($files2);
?>
Outputs something like:
Array
(
[0] => .
[1] => ..
[2] => bar.php
[3] => foo.txt
[4] => somedir
)
Array
(
[0] => somedir
[1] => foo.txt
[2] => bar.php
[3] => ..
[4] => .
)
Je to funkce co ti rovnou vyplivne to pole co potřebuješ..
To ench: pise to tuto hlasku:
Fatal error: Call to undefined function: scandir() in /home/free/tym.sk/<cenzura>/index.php on line 15
Kod:
13: <?php
14: $dir = '/foto/';
15: $pole[] = scandir($dir, 1);
16: echo($pole[0]);
17: ?>
Do kelu co sa zas deje? Nepozna to funkciu scandir() ? Inak diky moc za pomoc! :) Az vyriesim tento problem a spoznam viac tieto funkcie, problem mam vyrieseny :)
Nj, ani s priponou php5 mi to neslo.. Ale uz som dal nieco uplne ineho.. hen: :)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=windows-1250" http-equiv="Content-Type">
<link rel="stylesheet" href="./styles.css" type="text/css">
<title>FOTOGALÉRIA</title>
</head>
<body>
<div id="galeria">
<center>
<h2>Galéria</h2>
<?php
////////
function Pripona($filename)
{
$path_info = pathinfo($filename);
return $path_info['extension'];
}
$dir = "./foto";
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
//print_r($files[3]);
$fotky = array();
foreach ($files as $key => $subor) {
if(pripona($subor)=="jpg"){
//ak to je obrazok vo formate JPG
$fotky[] = $subor;
}
}
sort($fotky);
$pocet_fotiek = count($fotky);
if(isset($_GET['show'])){
//zobrazenie detailneho rozmeru fotky
$src = "./foto/".$_GET['show'];
echo "<center><span><img src=\"$src\" alt=\"$src\"/></span></center>";
}
else {
//vypis fotiek
for ($start = 0; $start < $pocet_fotiek; $start++)
{
$aktualne_foto = $fotky[$start];
echo "<a href=\"?show=$aktualne_foto\" title=\"Klikni pre zväčšenie\">
<img src=\"./foto/$aktualne_foto\" height=\"150\" width=\"150\" alt=\"stôl\" title=\"Klikni pre zväčšenie\">
<span><strong>$aktualne_foto</strong>
</span></a>";
}
}
?>
<h2>Galéria</h2>
</center>
</div>
</body>
</html>
A CSS:
*
{
font-family: arial, "Trebuchet MS", tahoma, verdana, sans-serif;
text-align: center;
background: #fff;
color: #000;
margin: 0;
padding: 0;
}
#galeria
{
width: 800px;
margin: 0 auto;
}
#galeria h2
{
margin: 0;
padding: 5px;
width: 100%;
background: #F3D8A9;
font-family: georgia, serif;
border: 4px solid #B17101;
font-size: 1em;
clear: both;
}
#galeria img
{
margin: 0;
padding: 0;
}
#galeria a
{
display: block;
background: #D4F3A9;
width: 160px;
float: left;
font-size: 0.8em;
padding: 4px;
margin: 8px;
border: 1px solid #F3D8A9;
}
#galeria a, a:hover, a:active
{
text-decoration: none;
}
#galeria a:hover
{
background: #ACD277;
}
#galeria a:active
{
border: 1px solid #000;
}
#galeria a img
{
border: 1px solid #ddd;
text-decoration: none;
}
#galeria span
{
display: block;
margin: 0;
padding: 4px;
background: none;
text-align: left;
}
#galeria span strong
{
background: none;
}
Toto som cely cas robil :) A uz to vsetko ide!!

Přidej příspěvek
Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×






























































Uživatelé prohlížející si toto vlákno
Uživatelé on-line: 0 registrovaných, 81 hostů
Podobná vlákna
Prehľadávanie siete — založil mimi
Prehladavanie adresarovej struktury — založil Zajcev
Prava na zlozky(adresare) — založil george
Pridanie .DLL do zložky — založil yterbium
Zistenie obsahu zložky — založil Michal115
Moderátoři diskuze