3

I'm trying to play files in the web browser rather than downloading. The files are embedded using WordPress

    [video width="250" height="140" m4v="http://www.justtalking.co.uk/wp-content/uploads/2014/02/Will-Aid-2013-Case-Study.m4v"][/video]

I would like to use the link Link to Video for email marketing purposes. When the link is opened, the web browser downloads the file rather than playing. However, i would prefer if the video was played in the web browser!

Is this possible?

Graham Warrender
  • 365
  • 1
  • 8
  • 20

2 Answers2

2

You need to add MIME/TYPE for video/mp4 and video/x-m4v on your server where the m4v file is hosted. You can read here section "MIME Types Rear Their Ugly Head" on how to do this.

Your URL indicates Content-Type: text/plain in the response header hence the prompt to download.

Arnaud Leyder
  • 6,674
  • 5
  • 31
  • 43
1

Probably purest solution is to add header "Content-Disposition: attachment" to that file.

It cannot be done on HTML link level, but you can do it via .htaccess or virtual host configuration.

If you have apache2 with mod_header you can do something like this:

<FilesMatch "\.jpg$">
    Header add "Content-Disposition" "attachment"
</FilesMatch>

Other ways you have to make simple PHP script which uses header() function to do the job and then simple pass target file to output.

<?php
$allowed_path = __DIR__."/downloads/";
$file = $allowed_path.basename($_GET["file"]);

if(file_exists($file)) {
    header("Content-disposition: attachment");
    readfile($file);
}
else {
    header('HTTP/1.1 404 Not Found', TRUE, 404);
}

Another way I noticed is that your link to video says wrong content type (it's minor issue):

Content-type: text/plain

You can solve that by adding one more header like this:

header("Content-type: ".mime_content_type($file));

But be careful about security, because if you have any PHP file in $allowed_path it can be downloaded via this script.

Dragonn
  • 11
  • 3
  • Thanks for your answer! It turns out the MIME type was the main issue. The configuration panel on the server has a feature to add MIME types relating to the file extension. `MIME Type File Extension` `video/x-m4v .m4v` So now, anything with a file of m4v is assigned a MIME type of video/x-m4v – Graham Warrender Apr 09 '14 at 14:42
  • I see i have misread your question, i was explaining how to force browser to download file, not play it in browser. Sorry ... – Dragonn Apr 09 '14 at 15:58