Log in

View Full Version : Forced Download and Web Win Media Player



Jas
01-20-2008, 08:13 PM
Okay, so I have a script which pulls up windows media player in the web page. It's suppose to load a video from a force download script in PHP and play it, but for some reason this only works in IE. What might I do to make it work in other browsers?
(Sorry for not sharing the script, but I'd rather not at this point for security reasons; if you need it I can water it down for you).

djr33
01-20-2008, 09:53 PM
You can't force anything upon a user, really. You can only do that within certain programs, like IE.

But there's one method I can think of-- require a certain player then apply it to that player.

So, here's what you do-- use mms:// instead of http://... that's one method that only allows streaming in a player as far as I know.

Jas
01-21-2008, 12:35 AM
You can't force anything upon a user, really. You can only do that within certain programs, like IE.

But there's one method I can think of-- require a certain player then apply it to that player.

So, here's what you do-- use mms:// instead of http://... that's one method that only allows streaming in a player as far as I know.

DJR33: Thanks for the reply. I'm not sure you understand, though. This one is my fault-- I typed the post in a rush. Sorry.:(

"Force Download" does not mean that you litterally make the user download the file; it means that it forces the browser to display a save dialogue box. (i.e. if you did this with an image, instead of the image being displayed in the browser, it would ask you save the image to your computer-- it's what happens when you DL something from sourceforge, for another example).

In this case, I want to use the script like an actual video file, because as far as web browsers are concerned, there is not difference between "myvideo.wmv" and "myscript.php?video=67". That is, instead of src="myvideo.wmv", it would be src="myscript.php?video=67". Again, it works with IE, but nothing else. The error that windows media player shows is that it could not retrieve file the contents.

So, to your answer: I'm not using the full path, for one, so I don't think the mms will work. If you think it will, I could use more info on it.

BLiZZaRD
01-21-2008, 04:24 AM
And what do you do for the visitors that don't have Windows Media Player installed?

The best bet would be to create the video in a more universal format and let the visitor play it in what ever player they want (or have set as default).

djr33
01-21-2008, 04:55 AM
You can send a force-download header to the browser using PHP. Just set the type of file being output with the header. But that isn't reliable, especially in IE (guess that's ironic).

You can use a PHP file to output that without much trouble.

readfile($_GET['file']);
...something like that.

Jas
01-24-2008, 04:45 AM
BLiZZaRD: The fact is that most users do have it installed. And if they don't, they can DL the file and view it in another player. I do hope to get different online players eventually, but right now one is all I can handle.

djr33: Thanks! The headers have only been working in IE.
I was trying to get to sleep last night, and I thought "Why don't I just try a readfile with no headers?" But I didn't know if that was worth trying. And then I come here, and you suggested it, so now I think it is worth I try! I'll let you know how it turns out.

djr33
01-24-2008, 05:02 AM
That should probably work. Using headers can be tough because there is a lot of info out there, and not all of it is right. There is no actual force-download header, in fact. That's just a null header because it doesn't exist, so it defaults to downloading as it doesn't know what to do with it. So, you can use that and hope it errors to downloading, or you can set another type. I'm not quite sure what the best procedure is.

Jas
01-24-2008, 07:54 PM
It did not work. It went well in IE again, but not in FF or Opera (didn't bother to try netscape or safari). There has to be a way to make it work. Perhaps the player has a problem with the .php?file=1 extension-- maybe it won't work unless it's .wmv or .avi or .mpeg. But then why does it work in IE? I am starting to think I should just give up and make the user DL the file.
Any other ideas djr33?

djr33
01-24-2008, 08:17 PM
I think I misread something you said before, and I've been giving backwards advice.
You WANT to embed this, and NOT force download it?
You should just then give the proper header, which will be a windows media file, either wmv or avi.
Take a look at this post, specifically the response for avi:
http://www.php.net/manual/en/function.header.php#48538

Jas
01-25-2008, 12:57 AM
I have a script very much like the one you linked to, and it didn't work for embedding. The files download great-- which is the intention of the script-- but for some reason they don't want to embed in WMP.

jackbenimble4
01-27-2008, 07:59 PM
First, I'd recommend using flash for your videos if you can. It's so widely supported that all the major video sharing sites like youtube and google videos use it.

Anyways, I don't know why other browsers wouldn't like the dynamic php urls. If they truly are the root of the problem, you could try mod_rewrite to rewrite their urls into more browser friendly urls. For example, /my-video-4.wmv could redirect to /myvideo.php?id=4.

If you're interested, here are a few links:
mod_rewrite: A Beginner's Guide to URL Rewriting (http://www.sitepoint.com/article/guide-url-rewriting)
modrewrite.com (http://modrewrite.com/)
URL Rewriting | redirecting URLs with Apache's mod_rewrite (http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html)

Here is a basic .htaccess file that should suit your needs (This is untested):

.htaccess


RewriteEngine On
RewriteBase /

RewriteRule ^video-([0-9]+)\.wmv$ myscript.php?video=$1 [L,NC]

Jas
01-29-2008, 11:01 PM
Thanks, I'll try that. It seems time consuming (lots of rewriting), but it might be the only option.