Results 1 to 7 of 7
  1. #1

    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");


    ?>

  2. #2
    Join Date
    Aug 2001
    Posts
    5,597
    So basically a directory index?

  3. #3
    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?

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

  5. #5
    yeah actually u can do save as! these are plain text files no extentions as such

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

  7. #7
    Join Date
    Aug 2001
    Posts
    5,597
    My point was that you dont need to write your own code for this.

Similar Threads

  1. Need help with how to make files downloadable on my website
    By mediaron in forum Web Design and Content
    Replies: 3
    Last Post: 03-14-2009, 08:48 PM
  2. Make All Files In A Directory Downloadable Using .htaccess
    By Daniel_G in forum Programming Discussion
    Replies: 3
    Last Post: 05-29-2008, 06:51 AM
  3. __Uploading NON DOWNLOADABLE music files ? ?
    By eyes2005 in forum Web Design and Content
    Replies: 2
    Last Post: 02-23-2007, 04:59 PM
  4. How to make PDF files downloadable ?
    By thomas.smith in forum Web Design and Content
    Replies: 9
    Last Post: 11-22-2004, 06:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •