www.webdeveloper.com
Results 1 to 5 of 5

Thread: downloading script

  1. #1
    Join Date
    Apr 2007
    Posts
    99

    Thumbs up downloading script

    How do I write a Php script that will allow user to download a word file form the server to his local computer .

  2. #2
    Join Date
    Jan 2010
    Posts
    20
    hello, arpit_vavadia
    I think this is a huge question and one can't explain in one post.
    take a tutorial in google, that should definitely help

    in my signature, there's FAQs so it's mentioned there as well))

  3. #3
    Join Date
    Jul 2009
    Location
    Falls Church, Va.
    Posts
    780
    Quote Originally Posted by arpit_vavadia View Post
    How do I write a Php script that will allow user to download a word file form the server to his local computer .
    Does it have to be PHP? Why not FTP? If you own a Mac or Linux system you can even use wget, scp or rcp in terminal mode on the local computer.

    If no to all of those, please take the time to explain if you need to automate it so a file is sent without user intervention via a task scheduler, or if you need a human being to initiate the download? If the latter, what would be your perfect scenario to accomplish that?

    For now, the advice is pretty generic beyond what I said in my first paragraph. Install a file manager in PHP on the server like this one, configure it to allow access from a given username for that file or folder which contains it, the user on the local computer browses to the web site hosting the file manager and downloads directly. This means setup a simple website on the server.

    I note with caution that simply allowing world access to the server, i.e. a simple web site without PHP, i.e. just a directory index display allowing anyone to download the file is a security vulnerability. But, alas, it's another way, too. So my advice about the file manager software is to allow a secure environment, plus the uploads on the server can be managed too. Just thinking ahead!

    -jim

  4. #4
    Join Date
    Jan 2010
    Posts
    13
    from what i understand you require a link to a .doc which upon clicking will do a forced download
    hope this helps

  5. #5
    Join Date
    Jul 2009
    Location
    Falls Church, Va.
    Posts
    780
    Nikiitea's advice is excellent. I wish to expand a bit on that...

    In previous replies it seems Virtuemart and I thought you meant a complete solution as you mentioned both server and local, hence my questions and suggestion to use a file manager which really is excellent for this type of thing. File managers typically use the function noted by nikiitea or code that does similar.

    If all you need is the portion of PHP code to specifically read a .doc file on the server and initiate a client download dialog box please consider the following to be added within your existing script:

    PHP Code:
    $file 'example.doc';

    if (
    file_exists($file)) {
        
    header('Content-Description: File Transfer');
        
    header('Content-Type: application/msword');
        
    header('Content-Disposition: attachment; filename='.basename($file));
        
    header('Content-Transfer-Encoding: binary');
        
    header('Expires: 0');
        
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        
    header('Pragma: public');
        
    header('Content-Length: ' filesize($file));
        
    ob_clean();
        
    flush();
        
    readfile($file);
        exit;

    -jim
    Last edited by SrWebDeveloper; 01-27-2010 at 10:08 AM. Reason: fixed a typo in the code, all better now

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