File Manipulation Code

  Home arrow File Manipulation Code arrow Universal downloader
FILE MANIPULATION CODE

Universal downloader
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 37
    2005-08-03

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    This is my favourite download-script, it works with files bigger than 10 MB on Apache 1.3 (or higher). I added the cache control to open also text files and others (without saving). Try the demo.

    By : olaf

    <?php
    // ver. 1.04 - added an example how to use this script with the filename from a query string
    // ver. 1.03 - moved the disposition header into the switch because the attachement attibute is sometimes needed
    // ver. 1.02 - use pathinfo() to get the fileinformation (extesnion) now
    // ver. 1.01 - Added the stringconv. to handle also extensions with caps

    // place this code inside a php file and call it f.e. "download.php"
    $path = $_SERVER['DOCUMENT_ROOT']."/path2file/"; // play with the path if the document root does noet exist
    $fullPath = $path.$_GET['downnload_file'];

    if ($fd = fopen ($fullPath, "r")) {
    $fsize = filesize($fullPath);
    $path_parts = pathinfo($fullPath);
    $ext = strtolower($path_parts["extension"]);
    switch ($ext) {
    case "pdf":
    header("Content-type: application/pdf"); // add here more headers for diff. extensions
    header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachement' to force a download
    break;
    default;
    header("Content-type: application/octet-stream");
    header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
    }
    header("Content-length: $fsize");
    header("Cache-control: private"); //use this to open files directly
    while(!feof($fd)) {
    $buffer = fread($fd, 2048);
    echo $buffer;
    }
    }
    fclose ($fd);
    exit;
    // example: place this kind of link into your document where the download is shown:
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More File Manipulation Code Articles
    More By Codewalkers

    blog comments powered by Disqus

    FILE MANIPULATION CODE ARTICLES

    - Bandwidth Control with pure PHP
    - Eazy Gallery
    - file_get_contents for PHP < 4.3.0
    - PHP Class: Image Snapshot 1.3
    - Universal downloader
    - Image Gallery v2.0
    - Free/Used Disk Space
    - Directory Lister
    - Directory image view, with selective hidden
    - Move or Copy a Directory (and files and sub ...
    - Ensure_Sub_Directory_Exists
    - Wedit
    - Form Examples Text Boxes to Drop Downs
    - myFiles
    - List files in a directory, no subdirectories


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap