-
Ciao,
mi servirebbe uno script che elenchi dei file .txt e crei un link ai file di una directory che dico io.
Sapete come si può fare?
Io ne ho uno, ma elenca tutti i file della directory in cui si trova. Lo incollo, magari qualcuno può aiutarmi a fare le modifiche necessarie. (crea già i link)
[code:1:d7faa1c239]
<?php
Function fncLinkDir( $dirname )
{
/* Get rid of those stupid filenames */
/* Was I sleepy when I did this? Alrighty then. */
if ( is_file( $DOCUMENT_ROOT.$REQUEST_URI ) )
{
$REQUEST_URI = ereg_replace( $mefile = strrchr( $REQUEST_URI, "/" ), "/", $REQUEST_URI );
};
/* Open Current Working Directory for reading. */
if( !$dirid = @opendir( $dirname.$recurse ) )
{
print " &lt; - Unable to Open Directory";
return 1;
};
/* Read the contents of the directory one by one */
while ($entry = @readdir($dirid))
{
/* Begin File Exclusion;
for long lists use an array and while loop
to save you some editing time. PHP 4 races through loops.
*/
/* Do not list hidden files; begins with .
Why: Indexing . will cause infinite loop and eventually
a stack overfrow.
*/
if ( strpos( $entry, "." ) === 0 )
{
continue;
}
/* Do not list Microsoft Frontpage junk, either. */
if ( strpos( $entry, "_vti_" ) === 0 )
{
continue;
}
/* End File Exclusion */
/* Add this entry to the listing */
$dirEntries[] = $entry;
}
/* Sort listing alphabetically then reset to start */
sort( $dirEntries );
reset( $dirEntries );
/* HTML, Open an unordered list */
print "<ul>\n";
/* Walk through the current directory */
$i = 0;
while( $dirEntries[$i] )
{
/* Assign a short name */
$fileName = $dirname . "/" . $dirEntries[$i];
$fileNameShort = $dirEntries[$i];
if( is_dir( $fileName ) )
/* It is a directory structure */
{
/* HTML, Open directory list item */
print "\t<li class=\"folder\"><a href=\"$fileName\">$fileNameShort/</a>\n";
/* Recurse into subdirectory */
fncLinkDir( $fileName );
/* HTML, Close the directory list item */
print "</li>\n";
}
else
/* It is some type of file */
{
/* HTML, Create a list item entry. */
print "\t<li class=\"link\"><a href=\"$fileName\">$fileNameShort</li>\n";
}
/* Increment the index else we loop forever, doh! */
$i ++;
}
/* HTML, Close the unordered list */
print "</ul>\n";
/* Wait, we're finished? */
};
$indexuri = explode("?", $REQUEST_URI);
fncLinkDir(".", $recurse, $REQUEST_URI, $DOCUMENT_ROOT);
?>
[/code:1:d7faa1c239]
Ciao
-
:shock: :shock: UMAMMAMIA Che esagerazione, quello che hai postato è un sistema operativo!!!!! :D :D
allora, per elencare tutti i file .txt di una directory basta usare la funzione glob di php.....
<?php
foreach (glob("NOMEDIRECTORY/*.txt") as $filename) {
echo "$filename size " . filesize($filename) . "<br>";
}
?>
ora, se volessimo creare dei link, basta modificare la echo in questo modo:
echo "<a href='$filename'>$filename</a><br>";
non bisogna aggiungere la directory nel link, poichè la funzione glob, in $filename ci restituisce anche il path dalla dir corrente a quella del file interessato.........
ciao e buona fortuna! :wink:
-
Funziona, grazie mille!
Però mi da i nomi dei file così: "m_z/nomefile.txt"
Come faccio per non fargli scrivere m_z/?
-
eccoti accontentato, ora non ti esce più la dir!!!!!
:D :D
<?php
foreach (glob("DIRECTORY/*.txt") as $filename) {
echo "<a href='$filename'>".substr(strrchr($filename,'/'),1)."</a><br>";
}
?>
Cià Cià!!!
-
Funge!
Grazieeee!!!!!!!! :D
-
Prego, siamo quì per questo!!! :lol: :lol: :lol: