For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > December 2006 > List of files in a folder...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author List of files in a folder...
Sean

2006-11-30, 3:57 am

Could anyone advise me if it's possible (with PHP) to list the files that
appear in a folder.

What I want to acheive is a webpage that will display all of the images from
within the /gallery/ directory of the website that I am working on.

Regards,

Sean




Ric

2006-11-30, 7:56 am

Sean schrieb:
> Could anyone advise me if it's possible (with PHP) to list the files that
> appear in a folder.
>
> What I want to acheive is a webpage that will display all of the images from
> within the /gallery/ directory of the website that I am working on.


If you just want to read files inside a given dir:

http://de3.php.net/manual/en/function.readdir.php


If you want to also list the folders, use:

http://de3.php.net/manual/en/function.scandir.php
>
> Regards,
>
> Sean
>
>
>
>

Sean

2006-11-30, 7:56 am

Thanks Ric,

Fast response!

Will try that later, but certainly looks the ticket for me.


"Ric" <antispam@randometry.com> wrote in message
news:ekmajl$76l$1@online.de...[color=darkred]
> Sean schrieb:
>
> If you just want to read files inside a given dir:
>
> http://de3.php.net/manual/en/function.readdir.php
>
>
> If you want to also list the folders, use:
>
> http://de3.php.net/manual/en/function.scandir.php



pangea33

2006-11-30, 9:59 pm

Sean wrote:[color=darkred]
> Thanks Ric,
>
> Fast response!
>
> Will try that later, but certainly looks the ticket for me.
>
>
> "Ric" <antispam@randometry.com> wrote in message
> news:ekmajl$76l$1@online.de...

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<link href="../stylesheet.css" rel="stylesheet" type="text/css">
</head>


<body>
<br><br>
<div>
<?php
$simpleAuth = ( isset($_REQUEST['letmein']) ? $_REQUEST['letmein'] :
0);
if ( $simpleAuth > 1 ) {
$pathStr = $_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"];
$dir = substr($pathStr, 0, strrpos($pathStr, "/")+1);
$aThisDir = explode('/',$dir);
$cThisDir = $aThisDir[count($aThisDir)-2];
//HTTP_HOST
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
$pos = strrpos($filename, ".");
if ( ( is_dir($filename) && $filename != ".") ||
substr($filename, strrpos($filename, "."), strrpos($filename,
".")+3) == ".gif" ||
substr($filename, strrpos($filename, "."), strrpos($filename,
".")+3) == ".jpg" ||
substr($filename, strrpos($filename, "."), strrpos($filename,
".")+3) == ".png"
) {
echo "<div>";
echo "<a href='".rawurlencode($filename)."'>".$filename."</a>";
echo "</div>";
}
}
}
?>

</div>
</body>
</html>

Koncept

2006-12-01, 6:57 pm

In article <1164943957.254024.22900@l12g2000cwl.googlegroups.com>,
pangea33 <pangea1013@gmail.com> wrote:
[color=darkred]

<?php
$galleryDir = 'gallery'; // The path to gallery
if ($handle = opendir($galleryDir)) {
$found = array();
while (false !== ($item = readdir($handle))) {
if ($item != "." && $item != "..") {
$found[] = $item;
}
}
closedir($handle);
}
// Reduce the array to include only the types we want
$reduced = preg_grep('/\.(jpe?g|png|gif|tiff?|bmp)$/i',$found);
if($reduced){
// Dump the images
$template = '<div><img src="%s" width="%d" height="%s" alt="%s"
/></div>';
foreach($reduced as $img){
$path = $galleryDir.'/'.$img;
list($width, $height, $type, $attr) = getimagesize($path);
printf($template,$path,$width,$height,$i
mg);
}
} else {
// No images found. Show warning
trigger_error( "No images to display", E_USER_WARNING );
}
?>

--
Koncept <<
"The snake that cannot shed its skin perishes. So do the spirits who are
prevented from changing their opinions; they cease to be a spirit." -Nietzsche
Gleep

2006-12-01, 9:56 pm

On Thu, 30 Nov 2006 09:53:34 -0000, "Sean" <sean.anderson@[nospam]oakleafgroup.biz> wrote:

>Could anyone advise me if it's possible (with PHP) to list the files that
>appear in a folder.
>
>What I want to acheive is a webpage that will display all of the images from
>within the /gallery/ directory of the website that I am working on.
>
>Regards,
>
>Sean
>
>
>



I've used this free php script for simple gallery system
http://chiliweb.com.pl/freesoft/quickgallery/
it's very easy to use and produces a nice gallery that can be modified
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com