www.webdeveloper.com
Results 1 to 4 of 4

Thread: downloading files

  1. #1
    Join Date
    Nov 2005
    Posts
    42

    downloading files

    i was writing here a couple of days ago about uploading files and thanks to some help here i was able to upload files using php code already im using files and i made a folder named uploads but i have one problem now.. i dont have any idea how i could put all of the files in a page and let the user's download the files that were uploaded can anyone guide me here? please thanks

  2. #2
    Join Date
    Oct 2005
    Posts
    843
    maybe something like so:
    PHP Code:
    <?
    echo ("<h1>File Directory:</h1>");
    function 
    getFiles($path) {
       
    $files = array();
       
    $fileNames = array();
       
    $i 0;
      
       if (
    is_dir($path)) {
           if (
    $dh opendir($path)) {
               while ((
    $file readdir($dh)) !== false) {
                   if (
    $file == "." || $file == "..") continue;
                   
    $fullpath $path "/" $file;
                   
    $fkey strtolower($file);
                   while (
    array_key_exists($fkey,$fileNames)) $fkey .= " ";
                   
    $a stat($fullpath);
                   
    $files[$fkey]['size'] = $a['size'];
                   if (
    $a['size'] == 0$files[$fkey]['sizetext'] = "-";
                   else if (
    $a['size'] > 1024$files[$fkey]['sizetext'] = (ceil($a['size']/1024*100)/100) . " K";
                   else if (
    $a['size'] > 1024*1024$files[$fkey]['sizetext'] = (ceil($a['size']/(1024*1024)*100)/100) . " Mb";
                   else 
    $files[$fkey]['sizetext'] = $a['size'] . " bytes";
                   
    $files[$fkey]['name'] = $file;
                   
    $files[$fkey]['type'] = filetype($fullpath);
                   
    $fileNames[$i++] = $fkey;
               }
               
    closedir($dh);
           } else die (
    "Cannot open directory:  $path");
       } else die (
    "Path is not a directory:  $path");
       
    sort($fileNames,SORT_STRING);
       
    $sortedFiles = array();
       
    $i 0;
       foreach(
    $fileNames as $f$sortedFiles[$i++] = $files[$f];
      
       return 
    $sortedFiles;
    }

    $files getFiles("./");
    foreach (
    $files as $file) print "<li><a href=\"$file[name]\">$file[name]</a></li>";
    ?>
    Welsh

  3. #3
    Join Date
    Feb 2005
    Location
    Tauranga
    Posts
    2,062
    Or as you upload the files to be downloaded you can add the names and path's into a database. Then allowing other things like you can track the number of times the file has been downloaded.


    When you upload add a simple INSERT statement and on your downloads page just pull a query to display them.

  4. #4
    Join Date
    Nov 2005
    Posts
    42
    thanks for the upload.. but err how do i let other people download it?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles