Codice PHP:
function cartelle($cartella)
{
echo "<div id='headgalls'>\r";
echo "<div id='foldimg'>\r";
$startdir=DRGALLS;
$cartella=str_ireplace("_"," ",$cartella);
$directories = array_filter(glob($cartella.'*',GLOB_ONLYDIR ));
if($startdir!=$cartella)
{
$parentdir=dirname($cartella);
if (($parentdir.'/')==DRGALLS)
{
echo "<a href='".$_SERVER['PHP_SELF']."'><img src='".PAIMG."folderup.png'><h6>..</h6></a>\r";
}
else
{
$dirup=str_ireplace($startdir, '', $parentdir);
$dirup=str_ireplace(" ","_",$dirup);
echo "<a href=".$_SERVER['PHP_SELF']."?cartella=".$dirup."><img src='".PAIMG."folderup.png'><h6>..</h6></a>\r";
}
}
foreach ($directories as $key => $value)
{
$dir= str_ireplace($startdir,'',$value);
$du= $_GET['cartella'].'/';
$du=str_ireplace("_"," ",$du);
$dirx=str_ireplace($du,'',$dir);
$dir=str_ireplace(" ","_",$dir);
echo "<a href=".$_SERVER['PHP_SELF']."?cartella=".$dir."><img src='".PAIMG."folder.png'><h6>$dirx</h6></a>\r";
}
echo "</div>\r";
echo "<div id='titlefold'>\r";
if ($cartella!=DRGALLS)
{
$h3 =str_ireplace($parentdir,'',$cartella);
$h3=str_ireplace('/','',$h3);
$h2='HOME - ';
if ($parentdir.'/' !=DRGALLS)
{
$temph=str_ireplace(DRGALLS,'',$parentdir);
$bc= explode('/',$temph);
foreach ($bc as $k=>$v)
{
$h2.=strtoupper($v).' - ';
}
}
}
else
{
$h2='';
$h3="GALLERY";
}
$h2=substr($h2,0,strlen($h2)-3);
echo "<h2>".$h2."</h2>\r";
echo "<h3>".$h3."</h3>\r";
echo "</div>\r";
echo "</div>\r";
echo "<div id='imggalls'>\r";
$imggalls=array_filter(glob($cartella.'*.{png,jpg}', GLOB_BRACE));
echo "<ul class='gallery clearfix'>\r";
foreach ($imggalls as $key => $value)
{
$imgv=str_ireplace($cartella,'',$value);
$value=str_ireplace($cartella,'',$value);
$cart=str_ireplace(DRGALLS,PAGALLS,$cartella);
$imgurl=$cart.$value;
echo "<a href='$imgurl' rel='prettyPhoto[pp_gal]'><img src='$imgurl'></a>\r";
}
echo "</ul>\r";
echo "</div>\r";
}
?>
<div id='galleria'>
<?php
if (isset($_GET['cartella']))
{
$tempdir=$_GET['cartella'];
cartelle(DRGALLS.$tempdir.'/');
}
else
{
cartelle(DRGALLS);
}
?>
</div>
Ora io vado in questa parte a selezionare la cartella le cui immagini verranno visualizzate nel div sottostante (chiamato galleria)
[PHP]echo "<div id='headgalls'>\r";
echo "<div id='foldimg'>\r";
$startdir=DRGALLS;
$cartella=str_ireplace("_"," ",$cartella);
$directories = array_filter(glob($cartella.'*',GLOB_ONLYDIR ));
if($startdir!=$cartella)
{
$parentdir=dirname($cartella);
if (($parentdir.'/')==DRGALLS)
{
echo "<a href='".$_SERVER['PHP_SELF']."'><img src='".PAIMG."folderup.png'><h6>..</h6></a>\r";
}
else
{
$dirup=str_ireplace($startdir, '', $parentdir);
$dirup=str_ireplace(" ","_",$dirup);
echo "<a href=".$_SERVER['PHP_SELF']."?cartella=".$dirup."><img src='".PAIMG."folderup.png'><h6>..</h6></a>\r";
}
}
foreach ($directories as $key => $value)
{
$dir= str_ireplace($startdir,'',$value);
$du= $_GET['cartella'].'/';
$du=str_ireplace("_"," ",$du);
$dirx=str_ireplace($du,'',$dir);
$dir=str_ireplace(" ","_",$dir);
echo "<a href=".$_SERVER['PHP_SELF']."?cartella=".$dir."><img src='".PAIMG."folder.png'><h6>$dirx</h6></a>\r";
}
echo "</div>\r";
La mia idea era di gestire lo script tramite ajax in modo da andare a lavorare solo sul div della galleria lasciando intatto il resto (Anche in modo da non intaccare la cache della pagina gallery.php.