You are here: Re: [PHP] need help arranging files! « PHP « IT news, forums, messages
Re: [PHP] need help arranging files!

Posted by Michael Hulse on 10/02/70 11:37

On Jan 16, 2006, at 6:10 PM, Nicholas Couloute wrote:
> I tried the script but it keeps saying it is not an array!

Hmm, I just set-it-up on my server:

http://www.ambiguism.com/php/readDirSort.php

Seems to work for me. Code:

$file_path = $_SERVER['DOCUMENT_ROOT'].'/php/test/';
$the_dir = opendir($file_path);
# Loop through directory and add files to array $html:
while ($file = readdir($the_dir)) {
# Check if it's a file, and it has a valid extension:
if(eregi("(\.pdf|\.html|\.htm|\.php|\.txt)$", $file)) {
# Add file to array $html:
$html[] = $file;
}
}
# Close the stream:
closedir($the_dir);
# Generate the drop-down menu:
if($html == null) { die("There are no files in this directory!"); } //
If no content is found, alert user.
sort($html);
foreach($html as $html => $value) {
echo '<br />'.$value;
}

Keep in mind, the above code is very minimal... you could probably
spend a bit of time making more secure/robust... I pulled it out of a
function I use.

You might want to read-up on sorting via PHP.net (in comments section)
for more robust user-defined functions...

Hth!
Cheers,
Micky

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация