Buon pomeriggio, ho la necessità di dover assegnare un id univoco ai link di un menu ad albero che strutturo attraverso una funzione ricorsiva.
Praticamente, attraverso una path di una cartella contenente, cartelle, sottocartelle e file, compongo questo menu.
la funzione è la seguente:
Praticamente devo assegnare ai link rimuovi un id univoco...Codice PHP:
$path="../DOC/";
$out = dirExplorer( trim($path) , "" , 0 , 200 );
echo $out."\n";
function dirExplorer( $path , $str , $step , $stepLimit )
{
// SPACES calculates spaces
$s = "" ;
for($i=0 ; $i<$step ;$i++)
$s.= "\t" ;
// CASI BASE
if( !file_exists($path) )
{
return "";
}
$c = strrpos($path, "/");
$d = substr($path, $c+1);
if( !is_dir($path) ){
return "[*]<a href=\"".$path."\" onclick=\"window.open(this.href);return false;\">".strtoupper($d)."</a> -
<a id='delFile".$i."' href=\"javascript:void(0)\" title='".$d."'>rimuovi</a>\n" ;
}
if( $step > $stepLimit )
{
return $s."[*][X]Recursion limit reached - ".$path."\n" ;
}
// RICORSIONE PRINCIPALE
//$str1 = $s."<ul>\n".$s."[*]".$path."\n" ;
// scorre le sotto dir
$subs = scandir( $path ) ;
if($path!="../DOC/"){
$str1 = "[*]<a href=\"javascript:void(0)\">".$d."</a> - <a id='delFile".$i."' href=\"javascript:void(0)\" title='".$d."'>rimuovi3</a>\n";
}
else{
$str1 = "\n";
}
$str1 .= "<div class=\"tree-menu\">";
$str1 .= "[list=1]" ;
foreach( $subs as $n=>$v )
{
// Filtra il caricamento dei file "." e ".."
if( $v!="" && $v!="." && $v!="..")
{
// FORMATTAZIONE PERCORSO
$npath = $path."/".$v ;
//echo $npath . "\n
";
if( $path[ strlen($path)-1 ] == "/" )
$npath = $path.$v ;
// se vuoi organizzare files e directories devi formattare
// degli array che scorrerai sotto spostando la chiamata ricorsiva
// scorrendo tali arrays cosi' puoi gestire prima le dir e poi i files
// echo "\n
Npath: " . $npath . " STR1: " . $str1 . " Step: " . ++$step . " - StepLimit: " . $stepLimit;
$str1 .= "".dirExplorer( $npath , $str1 , ++$step , $stepLimit )."" ;
}
}
$str1 .= "[/list]";
$str1 .= "</div>";
$str1 .= $s."\n".$s."\n
" ;
return $str1;
}
Come faccio?
grazie mille...
Aiutatemi per favore...