GeekyCorner
09 Oct read files name in folder using php Posted by Ben | 52 Comments
I am doing a script which converts JPG files to GIF but cannot make it read file names in one of my directories.

52 Replies to "read files name in folder using php"

Sasho Valkanov October 9, 2006 at 11:36 am | Reply

+13


$image_file_path = '/home/user/www/path/'; - this is the full server path to your images folder

$d = dir($image_file_path) or die("Wrong path: $image_file_path");
while (false !== ($entry = $d->read())) {
if($entry != '.' && $entry != '..' && !is_dir($dir.$entry))
$Images[] = $entry;
}
$d->close();

It creates an array $Images with all filenames


suganya March 2, 2007 at 1:34 pm | Reply

+1

Thanks it working fine
subhashish May 31, 2007 at 11:18 am | Reply

+5

<?php
if ($handle = opendir('/~path_to_directory/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$page_name=substr($file, 0, strpos($file, "."));
echo "$page_name<br>";
}
}
}
closedir($handle);
?>
Alin October 21, 2007 at 4:48 pm | Reply

0

It is possible to read an array using a loop ?
Like $array = array();
for ($i=...
To make the page print all the content of a directory.
Alin October 21, 2007 at 5:37 pm | Reply

0

I took a look at www.php.net/foreach , and my mind is now clear :-)
Thanks.
Hank Freid May 20, 2008 at 2:19 pm | Reply

0

Yes this helped me a lot....

Regards
Hank Freid
Bimlesh May 22, 2008 at 2:37 pm | Reply

+6

<?php
$dir = ".";

$dh = opendir($dir);

while (($file = readdir($dh)) !== false) {
echo $file;
}

closedir($dh);
?>
Shamick P. Gaworski June 20, 2008 at 5:20 pm | Reply

0

Thanks a lot, I like this, simple and it works
Ketan October 9, 2008 at 2:17 pm | Reply

+1


I want that user can choose a fodler thru window and can open it
bayyou November 11, 2008 at 4:44 am | Reply

0

it's very helpful, simple script. Thanks alot


Please be polite and helpful and do not spam or offend others. We promise you will be treated the same way.

Log in your free account or if you still haven't joined you can create your free account now.

Posting tip:
if you use code in your comments please put it in these tags [php], [sql], [css], [js]
PHP code example: [php] echo date("Y-m-d"); [/php]

Thank you,
~ PHPJabbers team ~