1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Best way to let users download a .docx file?

Discussion in 'HTML & Website Design' started by Anveto, Jun 10, 2010.

  1. #1
    If I was running a website and wanted to make a download link for a .docx file to let users download it what would be the best way?

    I do not want to zip or rar it, or compress it in any way

    If i create a normal a href link to the file it will download incorrectly or create problems for some or most users

    Thanks
     
    Anveto, Jun 10, 2010 IP
  2. krsix

    krsix Peon

    Messages:
    435
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Pass it as a filetype of force download.
     
    krsix, Jun 10, 2010 IP
  3. Norebbo

    Norebbo Active Member

    Messages:
    489
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #3
    What kinds of problems? I can't recall ever seeing an issue with an href link to a source doc, but then again, it's been a while since I tried.
     
    Norebbo, Jun 10, 2010 IP
  4. Chance

    Chance Peon

    Messages:
    70
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I've never heard of any delivery issues with doc or docx files and I support thousands of people who deliver files.

    The only thing anyone ever complains about is that they can't open the newer Office 2007 / 2010 docx format because they don't have the compatibility pack update installed.
     
    Chance, Jun 10, 2010 IP
  5. irving

    irving Peon

    Messages:
    65
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You have two options, depending on whether you have access to your server config or if you have a server-side script. If you're using php, you can use something like:

    
    <?php
    //define content as a docx
    header('Content-type: application/docx');
    // set the filename
    header('Content-Disposition: attachment; filename=download.docx');
    // set the filesize
    header('Content-Length: '.filesize("download.docx"));
    // say where the file is
    //read the file to be downloaded - path/to/document/file.docx
    readfile_as_chunks("path/to/document/file.docx");
    
    function readfile_as_chunks($filename){ 
     $chunksize = 1*(1024*1024); // how many bytes per chunk 
     $buffer = ''; 
     $handle = fopen($filename, 'rb'); 
     if ($handle === false) { 
     return false; 
     } 
     while (!feof($handle)) { 
       $buffer = fread($handle, $chunksize); 
     print $buffer; 
     } 
     return fclose($handle); 
     } 
    ?>
    
    Code (markup):
    If you're using a different server-side language you'll need to google for that.

    If you have access to your server config, e.g. apache, you can do something like:

    
    <FilesMatch "\.(?i:docx)$">
      ForceType application/octet-stream
      Header set Content-Disposition attachment
    </FilesMatch>
    
    Code (markup):
     
    irving, Jun 10, 2010 IP
  6. Anveto

    Anveto Well-Known Member

    Messages:
    697
    Likes Received:
    40
    Best Answers:
    19
    Trophy Points:
    195
    #6
    nevermind, I was being stupid :)

    I forgot the docx is for 2007 only. So the errors were on earlier office versions
     
    Anveto, Jun 15, 2010 IP