Results 1 to 8 of 8

Thread: Make Video Download Link

  1. #1
    Join Date
    Apr 2009
    Location
    Sydney, Australia
    Posts
    118
    Thanks
    16
    Thanked 1 Time in 1 Post

    Default Make Video Download Link

    Hi back to a newbie question here. I just uploaded a .wmv Windows Media Player video to a server. I had hoped to go to the website, type in the URL and a pop-up window would show up which asked whether I wanted to download the video. Instead, Windows Media Player kicked into action and played the video. I was unable to save the video.

    The question is whether there is a HTML/JavaScript method available to make the video downloadable rather than automatically play.

    I use Google Chrome.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    1. The direct URL for the video is a link to the file, not to an HTML page. There's nothing you can do using HTML, Javascript or anything else that will affect it. (In theory, you could potentially do something to the video itself, but I'm not aware of any setting in a video-- that's just a technical theoretical point, that it could be possible.)

    2. You could serve the video file in such a way that tries to make the browser download it. One good option is to put it in a zip archive (or other compressed format). It will save you bandwidth and always force users to download it. But that's not so convenient. Another option is to serve the file using PHP or another serverside language and attempt a "force-download" header, essentially confusing the browser into saving it rather than opening it. This is messy and can work, and there's plenty of info about the methods and reasons it is complicated available with a quick search for "force download".

    3. You shouldn't try this. The browser decides what to do with various file types. HTML? It plays it. JPG? It displays it. ZIP? It saves it. WMV? It plays it. (Or it downloads it.)

    The simple answer is to uninstall the Windows Media Player plugin from your browser. Or find a setting to disable it (I'm not sure what that is, if there is one).
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. The Following User Says Thank You to djr33 For This Useful Post:

    sniperman (09-02-2011)

  4. #3
    Join Date
    Apr 2009
    Location
    Sydney, Australia
    Posts
    118
    Thanks
    16
    Thanked 1 Time in 1 Post

    Default

    Ordinarily this would be no problem but the reason this approach was required is because the movie is over 100MB and my server is acting as a conduit for another person to access mainly because hotmail/gmail have 10MB attachment limits.

    The user is also elderly so while a ZIP file is the best alternative, the user might not know how to decompress a file etc.

    I might attempt the force download option in PHP. I'm hoping the code to attach in the header is fairly easily implementable because all the web page should do is allow the possibility to download.

    Thanks

  5. #4
    Join Date
    Apr 2009
    Location
    Sydney, Australia
    Posts
    118
    Thanks
    16
    Thanked 1 Time in 1 Post

    Default

    Just an update. I've resolved the issue.

    When searching for "force download" I came across another post in Dynamic Drive forums. Basically I added an .htaccess file with the code below to the server folder in question.

    Code:
    <Files *.wmv>
      ForceType application/octet-stream
      Header set Content-Disposition attachment
    </Files>
    Luckily for me it worked. The video started to download.

    Thanks for pointing me in the right direction.

  6. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Not pretty but this seemed to work OK in testing:

    PHP Code:
    <?php 
      
    // place this code inside a php file and call it f.e. "download.php" 

    $path $_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . '/';
    $fullPath $path.$_GET['download_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 'attachment' 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($fd2048); 
            echo 
    $buffer
        } 

    fclose ($fd); 
    die(); 
    // example: place this kind of link into the document where the file download is offered: 
    // <a href="download.php?download_file=some_file.pdf">Download here</a> 
    ?>
    Put it - name it download.php, in a folder with the file to download (whatever.wmv in this example), and with a separate page with a link on it:

    HTML Code:
    <a href="download.php?download_file=whatever.wmv">Whatever WMV</a>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Your .htaccess will "work", depending on what you mean by work. If you're sure that's what you want, go ahead and use it-- you won't be the only one, certainly. But there are several downsides you should know about: 1. It is invalid and only works by confusing the browser; 2. It won't work in all browsers (I believe IE is especially troublesome).
    And as I said, you may not want to mess with this configuration because some users will want to view it in the browser rather than be forced to download it.
    Just for your information, and you can do what you'd like.

    Note that this will apply to any "force download" method, not just using .htaccess. (They all work through HTTP headers and those are then seen the same way in a browser, so the origin is not important.)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The method in my previous post works. But it gives the user the choice. I think the .htaccess method probably is the same. Unless the browser is configured to "Always perform this action with this type of file", all the server can do is force the "Open or Save?" dialog.

    However, Daniels's right in a way. If you choose download too quickly without opting out of "Always perform this action with this type of file", it may lock your browser into "Always perform this action with this type of file". At that point you would have to "get under the hood" to change that behavior.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The "Open or Save" dialog is something else. Either way, it will save it to your computer (not just in the cache). "Open" will often save to a 'temporary' location, and "Save" will save to a more accessible 'storage' location, though they can be the same location. On Windows, I believe "Open" tends to put the file in some obscure location and "Save" goes to My Downloads (or wherever you've told your browser to save files), but on a Mac they do the same thing. This may all be customizable.
    Regardless, and ignoring the location where the file is saved, those two options do perform the same action: they save the file to your computer. The difference is that "Open" then additionally automatically opens the file when it is done and "Save" does not. Note that some browsers don't have this option. For example, Safari just saves the file (and may or may not open it, I think this is configurable in the options).
    This is not the choice I was talking about.


    Viewing a video with a browser plugin is something different. That will load the video as if it were a webpage (well, something like a webpage-- more like an image), and will not save it or give you control over where this temporarily cached file is stored.
    But disabling or uninstalling the plugin is the way to modify this behavior (as a user), rather than as a web designer deciding what should happen for your clients. Unless they just don't know what's going on, then they probably have that plugin there for a reason.


    Note that plugins don't necessarily stop saving a file. There are two easy ways to save it:
    1. In most browsers, File>Save will work when a plugin loads a file.
    2. You can also right click and choose "Save As" in the menu rather than loading the file as a link.

    Some plugins also provide a download option or button, and there are more complicated ways to get around this like looking in the source code or digging through your cache.



    Note that, as a web designer using HTML etc., there is no way whatsoever to control whether the "Open" or "Save" option is chosen beyond forcing that menu to pop up. That IS "force downloading".
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

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