treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Creating a .m4v Download Link

  • I'm attempting to create download links on several pages for .m4v video files. One of the pages is here: http://gkeagles.org/drew-austin-qb-2/. The setup is intended to be somewhat similar to the Screencast pages on CSS-Tricks, where visitors can watch online or download.

    The problem I'm having is in creating the download link. My understanding is that I would simply use an <a href> element: <a href="video-url">Click Here</a> to download. When I do so, however, clicking on the link doesn't initiate a download, it just tries to navigate to the specified url. As a stop-gap in the meantime I'm going to upload a .zip of each video and link to that, which should force a download. Is there a way to force a download when linking to a .m4v file?

    Thanks in advance for any help.
  • I'm not completely familiar with this, though I believe it is possible to force the download using a .htaccess file.

    Try this: create a .htaccess file in the server root (or add to it if that file already exists) and add these contents:

    AddType application/octet-stream .m4v


    (according to http://www.askapache.com/htaccess/ultim ... ample.html -- see the "## FORCE FILE TO DOWNLOAD INSTEAD OF APPEAR IN BROWSER ###" section).

    However, do check -- adding this line may mean that if you try to play a .m4v video (though a video player, rather than linking it) the file will attempt to download. If that is the case (I'm not sure off the top of my head), using a .zip file may be the best way to go. Perhaps other members will have some additional ideas as well.
  • @falkencreative --

    Thanks for the info -- I had looked at this technique as well but wasn't sure. Added the line to my .htaccess file, but it didn't work.

    One important piece of information i forgot to add in my initial request: the site is built in Wordpress, so I'm attempting to add the download links in posts. I don't know if that makes a difference, but thought I should mention it.

    Update 4/13/10: I really, really hope someone out there will take pity on me and offer some help on this one. I suspect it has something to do with the fact that I'm attempting to do this inside a WordPress post: no matter what I do (including one attempt to use php to force a download) clicking on the file link just tries to open a new page. I'm due to hand the project over to the client tomorrow and would really like to have this issue solved before then.
  • Did you ever get an answer for how to write html so that an m4v video link is downloaded instead of played? I too want to do that on my site. Thanks, Wayne