0

This is continued from my original question (http://stackoverflow.com/questions/10133976/getelementsbytagname-specific-links-only) which I got resolved but now facing different issue.

I'm implementing Anarchy player on my site and problem is that script stores files outside the domain root so links to them are in format like ( http: // mysite.com/mod/file/download.php?file_guid=fileID) which is fine for the player, it still plays the file but I need to separate files by type.

Look at the javascript code below, "if(o.href.match(/.mov$|.mp4$|.m4v$|.m4b$|.3gp$/i)" part, if I understand it correctly it says if file extension is .mov, .mp4, etc. than include that player. But since link is not in standard format with file name and extension it does not recognize it. How to change that "if(o.href.match" to something that would distinguish what type of file it is? I can pull file full name with extension in text format via PHP code and maybe wrap it in or div and that use if...div.match(...? Link to video file is already inside div block id "video"

<div id="video">
        <a href="<?php echo $file_url;?>"></a>
        </div>

Here is javascript:

var all = document.getElementById ( "video" ).getElementsByTagName ( "a" );
        for (var i = 0, o; o = all[i]; i++) {
            if(o.href.match(/\.mov$|\.mp4$|\.m4v$|\.m4b$|\.3gp$/i) && o.className!="amplink") {

Thank you so much for any suggestions.

4

1 回答 1

0

仅通过查看文件名并不总是可以确定文件的文件类型。更好的方法是查看Content-Type标头(在 HTTP 资源的情况下)或MIME-type(本质上是相同的)。

仍然有可能发送一个错误Content-Type,所以也许有一种方法可以通过查看前几个字节来识别文件类型?我知道 PNG 从一个非常明显的指标开始。

于 2012-04-13T18:14:31.813 回答