772 snippets from 1557 members, and growing!
|
login
|
join
about
bytebin
members
tags
snippets
join
Snippets
Submit a Snippet
Search Snippets
New Snippets
Top Snippets
Top Tags
PHP
(136)
JavaScript
(123)
Java
(66)
VBSCRIPT
(58)
String
(44)
CSS
(31)
CSharp
(28)
File
(28)
HTML
(27)
C
(24)
mysql
(24)
VB.NET
(24)
python
(24)
CPlusPlus
(23)
groovy
(23)
New Snippets
Consumer Complain...
Private Snippet?
Very lightweight ...
AutoComplete plug...
AutoComplete plug...
Connection Java -...
View PostgreSql
Store Procedure
Pygame - Simple p...
Python - Anagram ...
Venture Capital Jobs
New Members
kazumaniax
bmax1368
me
jamesmcm
Can
Kelmi
ysg
dannymo2
chorny
wallie
Top Members
dannyboy
sundaramkumar
mattrmiller
Pio
i_kenneth
ASmith
ctiggerf
sehrgut
bertheymans
SCoon
Home
/
Snippets
/
Display Contents of a Folder
/
Comments
Display Contents of a Folder
Snippet Menu
Revisions
Comments
Related Snippets
Add to Favorites
Email Snippet
Download Snippet
Print Snippet
Blog Snippet
snippet
|
revisions
|
comments
|
related
|
Add to Favorites
|
email
download
|
print
|
blog it
New Comment
A better way..
Sun. May. 20th, 2007 10:28 PM
SecondV
-SV
<?php
// Change to point to your directory
$handle
=
dir
(
'images/'
)
;
if
(
$handle
)
{
while
(
false
!==
(
$file
=
$handle
->
read
(
)
)
)
{
if
(
!
in_array
(
$file
,
array
(
'.'
,
'..'
)
)
)
{
echo
"<a href=
\"
http://yourdomain.com/images/$file
\"
>$file</a><br />"
;
//change to match your path
}
}
}
?>
Reply
Help
Thu. Mar. 29th, 2007 7:00 AM
seal
Hi I'm trying to show the contents of a folder (word docs) on a web page, without having to manually put each file name in. Is this the right bit of code to do this? If not does anyone know how to do this and can you help me.
Reply
RE: Help
Tue. Apr. 3rd, 2007 1:59 PM
dig412
Yes, this scans through a directory and prints out a line for each file found.
Reply
PHP 5 better way
Sat. Jun. 16th, 2007 1:15 PM
piotrlewandowski
You can do it better in PHP 5
$dirScan = "./img/"; if ($dirScan) { $dir = scandir($dirScan); array_shift($dir); array_shift($dir); $count = count($dir); echo "List of files [$count]:
"; foreach($dir as $file){ $file = $file."
"; echo $file; } } ?>
Reply
wrong inserted
Sat. Jun. 16th, 2007 1:17 PM
piotrlewandowski
previous comment was wrong inserted...
<?
$dirScan
=
"./img/"
;
if
(
$dirScan
)
{
$dir
= scandir
(
$dirScan
)
;
array_shift
(
$dir
)
;
array_shift
(
$dir
)
;
$count
=
count
(
$dir
)
;
echo
"List of files [$count]:<br />"
;
foreach
(
$dir
as
$file
)
{
$file
=
$file
.
"<br />"
;
echo
$file
;
}
}
?>
Reply
New Comment
-SV
// Change to point to your directory
$handle = dir('images/');
if ($handle)
{
while (false !== ($file = $handle->read()))
{
if (!in_array($file, array('.', '..')))
{
echo "<a href=\"http://yourdomain.com/images/$file\">$file</a><br />"; //change to match your path
}
}
}
?>
"; foreach($dir as $file){ $file = $file."
"; echo $file; } } ?>
<?
$dirScan = "./img/";
if ($dirScan) {
$dir = scandir($dirScan);
array_shift($dir);
array_shift($dir);
$count = count($dir);
echo "List of files [$count]:<br />";
foreach($dir as $file){
$file = $file."<br />";
echo $file;
}
}
?>