473,659 Members | 3,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP directory contents displayer

Hi

I have the following script, which lists files within a specified web
directory (as long as they are valid extension types). It works, but I
would like the file names to be links (i.e. with hrefs) that allow you
to open that file directly from the page. Purpose of the script is
purely to display a list of photos within the directory, with links to
view those photos. PHP is not my strong-point. Any suggestions would
be very gratefully received... Here's the script....


//This function retrieves all files within a directory (non recursive)
and outputs them onto the page
//You can limit the type of files to retrieve, such as images only, as
dictated by the file's extension
function getfiles($dirna me=".") {
$pattern="(\.jp g$)|(\.png$)|(\ .jpeg$)|(\.gif$ )"; //valid image
extensions
$files = array();
if($handle = opendir($dirnam e)) {
while(false !== ($file = readdir($handle ))){
if(eregi($patte rn, $file)) //if this file is a valid image
echo "$file <br />";
}

closedir($handl e);
}
return($files);
}
//EXAMPLE USAGE:
getfiles(); //List all image files within the directory the PHP script
is in
getfiles("/home/myserver/public_html/george"); //List all image files
within a specific directory on the server

Mar 30 '07 #1
1 1673
Message-ID: <11************ **********@y66g 2000hsf.googleg roups.comfrom
an****@david-andrews.net contained the following:
echo "$file <br />";
echo "<a href='$file'>$f ile</a><br />";

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Mar 30 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3917
by: Gema Gema | last post by:
I have a large collection of directories full of various files and am looking to create custom text files for the contents of each directory. Here is the situation: The directories are named with a name and number, i.e. Smith1234567. I am looking to create a text file named with the number portion of the directory name (1234567.txt). The contents of the text file would look similar to the following, where the "TIF" files at the end of...
2
1742
by: Luke Skywalker | last post by:
Hi, Currently, I use filters in Privoxy followed by a JavaScript embedded script to further filter a web page that is restricted to IE (because of incompatibilities of the DOM), and was wondering if it'd be feasible to write a Python GUI app with wxPython that would do the same, ie. fetch a web page, analyse its contents and filter/rewrite, before displaying it in a HTML renderer? Does wxWidgets offer an HTML displayer widget, and is it...
2
17633
by: Dean | last post by:
Hi I've got a question relating to using Javascript on an Intranet. I have a directory with a list of files in the format week36.xls, week37.xls and I want to write a script that will scan all the files in the directory and select the one with the highest week number then display in the browser window. A brief search hasn't revealed any code to do this so I just want to know if it is possible and what the function names are that...
1
4747
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem I have run into I am not sure how to fix, and really not sure what is causing it. Here's what is going on (test server - Windows 2003 Server): I have a page in a folder (under anonymous authentication in IIS6) that has a link on it that...
1
8555
by: Dave | last post by:
I am getting te following error in a ASP.Net app that is running on Win XP Pro (SP2): Server cannot access application directory 'C:\Documents and Settings\dave\My Documents\My Visual Studio ASP.NET\MyWebSite\'. The directory does not exist or is not accessible because of security settings. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information...
2
3089
by: Matthias Wohlmann | last post by:
Hi, I'm getting the following error when trying to start my application using Internet Explorer: "Server cannot access application directory D:\xxx. The directory does not exist or is not accessible because of security settings." In IIS I have set Directory Security for my application to allow Anonymous access (using IUSR_<Server>) and Integrated Windows authentication. In the web.config i have set impersonation="true" userName="test"....
2
2112
by: Rob_S | last post by:
I have a program which saves time stamped files into time stamped directories. When I want to read these files, I get the current date and check for the existence of the directory using.... while (!(_chdir(dirname)) == 0) {reduce the directory name (time) and check again} This method quickly finds the last directory but I don't know anything about
4
3246
by: techusky | last post by:
I have a *very* simple script written that displays the directory listing of the current working directory, but I am having some difficulty when I try to change folders. Basically, I have my $dir variable set to this: --- $dir = getcwd() . "\\" . $nav; --- but for some reason the script does not actually display the contents of the directory if you change from the directory the script is located in. Here is my code if someone is willing...
2
4934
by: Nathan Sokalski | last post by:
I have an ASP.NET application which displays the directories & files in a specified directory on the server. I use the System.IO.Directory.GetDirectories() and System.IO.Directory.GetFiles() to retrieve the lists of files and directories. I have two very similar versions of this that I am debugging, both of which use the methods mentioned above. However, one of them is returning the contents of the specified directory and the other is...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8337
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8748
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8628
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.