1934 snippets from 2404 members, and growing!
|
login
|
join
about
bytebin
members
tags
snippets
join
Snippets
Submit a Snippet
Search Snippets
New Snippets
Top Snippets
Top Tags
PHP
(160)
stablo
(139)
JavaScript
(138)
Battery
(96)
C
(74)
binarno
(72)
Dell
(68)
Java
(68)
adapter
(65)
polje
(62)
strukture
(60)
VBSCRIPT
(60)
HP
(50)
String
(45)
Batterie
(39)
New Snippets
CompCalc
Nettoyage de tapi...
Nettoyage de mate...
Zaglavlje za stab...
Jewellery trade f...
Industrial trade ...
Batterie asus a42...
Batera Lenovo T...
Batera Lenovo T...
Pokazivac zadatak...
Venture Capital Jobs
New Members
pimteam
zjakupec
Pushkartyagi
niprasnja
lzodan
mlcorak
bonikolic
mezestic1
rekapec
Kasimu
Top Members
dannyboy
sundaramkumar
mattrmiller
all-battery
Pio
Cloudgen
i_kenneth
ASmith
mycodeofshailendra
ctiggerf
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;
}
}
?>