Results 1 to 7 of 7
-
10-07-2013, 01:48 AM #1Newbie
- Join Date
- Sep 2013
- Posts
- 15
how do i make the files beign displayed here as downloadable?
<?php
// open this directory
$myDirectory = opendir(".");
// get each entry
while($entryName = readdir($myDirectory)) {
$dirArray[] = $entryName;
}
// close directory
closedir($myDirectory);
// count elements in array
$indexCount = count($dirArray);
Print ("$indexCount files<br>\n");
// sort 'em
sort($dirArray);
// print 'em
print("<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks>\n");
print("<TR><TH>Filename</TH><th>Filetype</th><th>Filesize</th></TR>\n");
// loop through the array of files and print them all
for($index=0; $index < $indexCount; $index++) {
if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden files
print("<TR><TD><a href=\"$dirArray[$index]\">$dirArray[$index]</a></td>");
print("<td>");
print(filetype($dirArray[$index]));
print("</td>");
print("<td>");
print(filesize($dirArray[$index]));
print("</td>");
print("</TR>\n");
}
}
print("</TABLE>\n");
?>
-
10-07-2013, 02:15 AM #2Web Hosting Master
- Join Date
- Aug 2001
- Posts
- 5,597
So basically a directory index?
-
10-07-2013, 02:20 AM #3Newbie
- Join Date
- Sep 2013
- Posts
- 15
The code lists all the files present in the var/www directory now when i click on them they display the contens of the files present in the var/www directory now i want them to be able to be downloadable on the system. how do i do that?
-
10-07-2013, 02:42 AM #4Retired Moderator
- Join Date
- Feb 2005
- Location
- Australia
- Posts
- 5,849
If you can view the contents you can already download them: Right-click "Save link as" (or similar depending on your browser).
Or if you want them to download by default, there are a couple of options. What are the filename extensions of these files? You could either change them to something not recognized as text (eg. "example.dat") or set a special mime-type for the extensions you're using.Chris
"Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter
-
10-07-2013, 03:19 AM #5Newbie
- Join Date
- Sep 2013
- Posts
- 15
yeah actually u can do save as! these are plain text files no extentions as such
-
10-07-2013, 08:29 AM #6Junior Guru
- Join Date
- Sep 2009
- Location
- Denmark
- Posts
- 178
Or you can add the correct headers to the files you wish clients to download.
See the example in here.
http://www.w3.org/Protocols/rfc2616/...html#sec19.5.1
-
10-07-2013, 10:40 AM #7Web Hosting Master
- Join Date
- Aug 2001
- Posts
- 5,597
My point was that you dont need to write your own code for this.
Similar Threads
-
Need help with how to make files downloadable on my website
By mediaron in forum Web Design and ContentReplies: 3Last Post: 03-14-2009, 08:48 PM -
Make All Files In A Directory Downloadable Using .htaccess
By Daniel_G in forum Programming DiscussionReplies: 3Last Post: 05-29-2008, 06:51 AM -
__Uploading NON DOWNLOADABLE music files ? ?
By eyes2005 in forum Web Design and ContentReplies: 2Last Post: 02-23-2007, 04:59 PM -
How to make PDF files downloadable ?
By thomas.smith in forum Web Design and ContentReplies: 9Last Post: 11-22-2004, 06:24 PM