Ok, Here's what I want to do. I want to be able to display all the
files in a directory as links on webpage so that the user can just
click the link to download the appropriate file. I can make this work
with the following bit of code. The files all have basically the same
format:
backup-<date created>.sql.ta r
What the following code does not do is to show the files in
alphabetical or chronological order. I think I could read the names
into an array and then sort them, but it seems that there must be an
easier way. Any suggestions?
Thanks,
Mike
<?php
//create the html to display the selection page
echo '<html>';
echo '<body>';
echo '<h1>Click on the backup file to save it to your PC.</h1>';
echo '<ul>';
//open the data directory and read the names of all the files
//into a list to be displayed on the page
$handle=opendir ('/www/htdocs/backups/data/');
while (false !== ($file = readdir($handle ))){
//if the list returns . or .. skip the display step
//and continue looping
if(($file == ".") OR ($file == "..")){continue ;}
//print out the name of the file so that it can be
//selected for download
echo '<li><a href="/tmaster/backups/data/'.$file.'">'.$f ile.'</a></li>';
}
//close the direcotry
closedir($handl e);
echo '</ul>';
echo '</body>';
echo '</html>';
?> 3 1705
On 4 Mar 2004 08:39:45 -0800, mi**@dogstar1.c om (mike) wrote: Ok, Here's what I want to do. I want to be able to display all the files in a directory as links on webpage so that the user can just click the link to download the appropriate file. I can make this work with the following bit of code. The files all have basically the same format:
backup-<date created>.sql.ta r
What the following code does not do is to show the files in alphabetical or chronological order. I think I could read the names into an array and then sort them, but it seems that there must be an easier way.
That _is_ the easier way. :-)
If using PHP5 there's scandir which does that for you:
<http://uk2.php.net/manual/en/function.scandi r.php>
Or just do it:
$handle = opendir('/www/htdocs/backups/data/');
$files = array();
while (false !== ($file = readdir($handle ))){
//if the list returns . or .. skip the display step
//and continue looping
if(($file == ".") OR ($file == "..")){continue ;}
$files[] = $file;
}
natsort($files) ;
foreach ($files as $file) {
//print out the name of the file so that it can be
//selected for download
echo '<li><a href="/tmaster/backups/data/'.$file.'">'.$f ile.'</a></li>';
}
--
Andy Hassall <an**@andyh.co. uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk > / <http://www.andyhsoftwa re.co.uk/space>
Use glob("*.tar"). It sorts the list before returning it, I think.
Uzytkownik "mike" <mi**@dogstar1. com> napisal w wiadomosci
news:80******** *************** ***@posting.goo gle.com... Ok, Here's what I want to do. I want to be able to display all the files in a directory as links on webpage so that the user can just click the link to download the appropriate file. I can make this work with the following bit of code. The files all have basically the same format:
backup-<date created>.sql.ta r
What the following code does not do is to show the files in alphabetical or chronological order. I think I could read the names into an array and then sort them, but it seems that there must be an easier way. Any suggestions?
Thanks,
Mike <?php
//create the html to display the selection page echo '<html>'; echo '<body>'; echo '<h1>Click on the backup file to save it to your PC.</h1>'; echo '<ul>';
//open the data directory and read the names of all the files //into a list to be displayed on the page $handle=opendir ('/www/htdocs/backups/data/'); while (false !== ($file = readdir($handle ))){ //if the list returns . or .. skip the display step //and continue looping if(($file == ".") OR ($file == "..")){continue ;} //print out the name of the file so that it can be //selected for download echo '<li><a href="/tmaster/backups/data/'.$file.'">'.$f ile.'</a></li>'; }
//close the direcotry closedir($handl e);
echo '</ul>'; echo '</body>'; echo '</html>'; ?>
mike wrote: Ok, Here's what I want to do. I want to be able to display all the files in a directory as links on webpage so that the user can just click the link to download the appropriate file. I can make this work with the following bit of code. The files all have basically the same format:
backup-<date created>.sql.ta r
What the following code does not do is to show the files in alphabetical or chronological order. I think I could read the names into an array and then sort them, but it seems that there must be an easier way. Any suggestions?
Don't use php, create a .htaccess-file for Your directory like:
Options +Indexes
AddType application/x-tar .tar
FancyIndexing on
AddIcon tar.gif *.tar
HeaderName index.txt
IndexOptions IconsAreLinks NameWidth=* ScanHTMLTitles
IndexOrderDefau lt Descending Date
....
and an index.txt with everything You want to tell the user about Your
directory.
Don't forget the icon tar.gif, if You're using the example.
Rudi This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ralph Freshour |
last post by:
I have a PHP web app using MySQL - when I save a .jpg file named
test's.jpg I see that the filename on the unix server is: test\'s.jpg
- the filename I end up saving in my SQL table is named test's.jpg -
when I use an image tag to display the photo on my web page, no image
displays.
I tried to strip the slash out of the filename but the image still
won't display on the web page - maybe I'm all goofed up here and don't
understand what's...
|
by: Robert Wagstaff |
last post by:
I have an interesting challenge. I have a client that is
putting pictures into a single folder on the web server.
The files are specific in that the first 5 characters of
the filename are the same ORDER#. The challenge is simply
to find all the filenames with the initial 5 characters
being input on an HTML form. That way I can establish
links to each one of the pictures on the results page.
So for instance if Order # 12345 was input...
|
by: Waguih Boctor |
last post by:
Hi,
I have a number of ASP pages where some JPGs and GIFs are displaying in the
browser and some are not. I have included an excerpt from the HTML below. In
this example, the gif file at the bottom of the example is displaying (I
have others that don't), while the jpg file at the top isn't. Both files are
in the same folder (visible bith physical in WE and virtual in CM) as the
asp file itself. WHen not displaying, it displays instead...
|
by: rbutch |
last post by:
guys, i need a little help with this.
this is working (well sort of)
i get the info, but it's not moving to a new line as it iterates thru the array
and all of the fields are like ONE HUGE LONG string
'declare an array
Dim filenames() As String
filenames = Directory.GetFiles("C:\Re_Class")
Dim i, o As Integer
Dim info As String
|
by: n33470 |
last post by:
We have a web site that is being converted from the 1.1 format into
2.0. I've noticed that after the web project has been converted, the
first time that the solution is opened in VS, all of the aspx and ascx
filenames are changed to lowercase.
The filenames are not being changed during the conversion process.
After conversion completes, the filenames remain unchanged. However,
the first time that the solution is opened in VS2005, the...
| |
by: Marcus Kwok |
last post by:
I have written a class (Windows Form) in Managed C++ that accepts an
array of image filenames and will display them sequentially. All images
will be the same size. I got it to work, but I know something is not
right because of the way I am using Application::DoEvents() (ref:
http://www.codinghorror.com/blog/archives/000159.html and
http://www.codinghorror.com/blog/archives/000370.html ), along with the
fact that I get a crash when I try...
|
by: hestres |
last post by:
Hello,
I'm working on some link styles for this page:
http://www.house.gov/velazquez/lh0205tres/reports.html
I want all the links to always display in red (#CC0000), but in IE6
and 7 they display in gray. In FF and Opera they work fine. I've
looked all over the code and can't find what might be causing this. Is
it an IE quirk I don't know about? Thanks,
|
by: chongming |
last post by:
Hi, i want to display all the filenames on browser. However i found that if there are many filenames in that folder, result will be it will display a long list of filenames on that browser.
My question is how do i iterate the file names with 5 filenames on each page?
I have manage to retrieve and display the filenames with the codes below. Can anyone help me or give advice on how to do the iteration?
The codes are below and able to...
|
by: ted |
last post by:
I have an old link that was widely distributed. I would now like to
put a link on that old
page that will go to a new page without displaying anything.
|
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...
|
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,...
| |
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...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
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...
| |