Posted by schwoortz 4 years 45 weeks ago
Hi folks,
I'm afraid this is a very beginner-ish question:
I am trying to serve a 3gp video by linking to the following file named video.php:
<?php
header('Content-type: video/3gpp');
header('Content-Disposition: attachment; filename="video.3gp"');
readfile('http://server.mobi/video.3gp');
?>
My link in xhtml would be:
<a href="video.php">download video (3gp, 868k)</a>
This does not work. Can anybody point me to what's wrong here?
Thanks
Michael




Posted by schwoortz 4 years ago
Hmm, maybe I should simply add the necessary mime-type to my apache config. I was just trying to find a way for situations where I have PHP at hand but cannot change/add to the mime-types...
-- Michael Schwarz / BerlinWeb Frontent Development
http://www.htmlexperts.de/ http://www.mobilewebdesign.de/
Posted by atrasatti 4 years ago
Mobile Genius
I think that your issue might be linked to MIME types, as suggested in another reply or in the filename. My suggestion is actually that you nest the php in a URL and then use PATH_INFO to serve the content and get the parameters to the PHP script. A couple of examples:
http://mobile.example.com/download/check.php/image.gif
http://mobile.example.com/download/check.php/123456789abcdef/image.gif
The difference is that in the first case you are passing a parameter, image.gif, and the script check.php will identify the file and deliver it. In the second case you are also passing a session id, 123456789abcdef. This can be another step further to log and protect your contents. Store session information in a database and get file and user info from your database. Very useful when you want to generate statistics about how many time a user downloaded a content, which user-agent requested the contents and so on.
Another easy thing to do to protect your content is to store the user-agent string and block any other request with a different user-agent string.
When delivering a content file with a script you will have to manage the HTTP headers. It is required that you set the appropriate MIME type and it is also good practice to specify the file size.
Andrea Trasatti
Blog: Andrea Trasatti's tech notes and more
Posted by GumSlone 4 years ago
you can add the mime types to your .htaccess
here are the mime types for 3gp files:
addType audio/3gpp 3gp
addType video/3gpp 3gp
also i suggest you to use mod rewrite for your download script because some browsers would get an error like unsuported while downloading from download.php, here is an example of mine:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^file([0-9]+).(3gp) ./download.php?video=$1 [L]
and small example of download php:
header('Content-type: video/3gpp');
header('Content-Disposition: attachment; filename="'.$video.'.3gp"');
readfile('http://server.mobi/'.$video.'.3gp');
and link to video download would look like http://mysite.mobi/file123.3gp
and your mobile would download it as file123.3gp in best case header('Content-Disposition: attachment; filename="'.$video.'.3gp"'); works with your mobile you would download it as 123..3gp my script is a bit different but i hope i explained how it works :)
Posted by tbartolucci 4 years ago
I tried this method and I'm getting a malformed response when I hit the file. The redirect seems to be working fine. And the file is there.
My .htaccess file:
addType audio/3gpp 3gp
addType video/3gpp 3gp
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([a-z]+).(3gp) ./stream.php?v=$1 [L]
My stream.php file:
<?php
header('Content-type: video/3gpp');
header('Content-Disposition: attachment; filename="'.$_GET["v"].'.3gp"');
readfile('server.com/'.$_GET["v"].'.3gp');
?>
My HTML link:
video.3gp
Posted by jonarne 4 years ago
Her's a piece of code I wrote a while back that does excactly what you want:
<?php $reqfile = "path/to/file.3gp"; $contenttype="video/3gpp"; if($fn=fopen($reqfile, "rba")){ header("Content-Type: ".$contenttype); header("Content-Length: ".filesize($reqfile)); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Pragma: no-cache"); header("Expires: Mon, 26 Jul 1997 06:00:00 GMT"); header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0"); fpassthru($fn); fclose($fn); }else{ exit("error...."); } exit(); ?>Also be careful about spaces/linebreaks outside the <?php and ?> ....
Posted by thevoid 4 years ago
Hi! (hej! ;) )
I am testing and playing around with your code as a "proof of concept" exercise before a project.
What I really want to do is to stream the 3gp file!
So the browser in my Nokia N95 doesnt ask if I want to dowload the file, downloads and plays in realplayer, but instead, buffers a bit and starts to stream it to realplayer straight away!
Can I modify the above code with other headers etc do achive this?
Many thanks!!!
Henrik
Posted by jonarne 4 years ago
Hej.
In order to stream a 3gp file you need a streaming server that supports RTSP (real time streaming protocol). So I'm afraid you wont be able to do that with php and a webserver. You can try some of the opensource ones
-- Jon Arne S.
Posted by Morg 4 years ago
Hey GumSlone.
I have been trying to get my page to work forever now! Came across this code and it works a charm.
One thing though.
I am not using the MOD rewrite but rather serving it straight up. The thing is, my filename is showing up as download_handler instead of the file name... any idea why this is happening? And could you suggest a way to get it the name it should be?
Here's my code:
<?php
header('Content-type: video/3gpp');
header('Content-Disposition: attachment; filename="'.$video.'.3gp"');
readfile('http://www.myserver.com/mobile/video/'.$video.'.3gp');
exit();
?>
and I call it like this: a href="http://www.myserver.com/mobile/download_handler.php?video=shark"
Any help would be greatly appreciated! :)
MorgThanks,
Morg
Posted by digitalkev 3 years ago
Thanks for the code, i'm using it and its working fine