Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top