List of files in a folder...

This is a discussion on List of files in a folder... within the PHP General forums, part of the PHP Programming Forums category; Could anyone advise me if it's possible (with PHP) to list the files that appear in a folder. What ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-30-2006
Sean
 
Posts: n/a
Default List of files in a folder...

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




Reply With Quote
  #2 (permalink)  
Old 11-30-2006
Ric
 
Posts: n/a
Default Re: List of files in a folder...

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
>
>
>
>

Reply With Quote
  #3 (permalink)  
Old 11-30-2006
Sean
 
Posts: n/a
Default Re: List of files in a folder...

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...
> 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
>>
>>
>>
>>




Reply With Quote
  #4 (permalink)  
Old 12-01-2006
pangea33
 
Posts: n/a
Default Re: List of files in a folder...

Sean wrote:
> 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...
> > 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
> >>
> >>
> >>
> >>


<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>

Reply With Quote
  #5 (permalink)  
Old 12-02-2006
Koncept
 
Posts: n/a
Default Re: List of files in a folder...

In article <1164943957.254024.22900@l12g2000cwl.googlegroups. com>,
pangea33 <pangea1013@gmail.com> 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.


<?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,$img);
}
} 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
Reply With Quote
  #6 (permalink)  
Old 12-02-2006
Gleep
 
Posts: n/a
Default Re: List of files in a folder...

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:02 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0