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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 > > > > |
|
|||
|
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 >> >> >> >> |
|
|||
|
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> |
|
|||
|
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 |
|
|||
|
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 |