PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Create a Highly Available Database Solution. Advantage Database Server can provide the availability to keep your data safe and ready for your application and users.
  #1  
Old March 23rd, 2008, 07:48 PM
o2pb o2pb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 50 o2pb User rank is Corporal (100 - 500 Reputation Level)o2pb User rank is Corporal (100 - 500 Reputation Level)o2pb User rank is Corporal (100 - 500 Reputation Level)o2pb User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 5 h 55 m 29 sec
Reputation Power: 5
PHP5 - Force client to download video file instead of streaming

I have a slight problem. I allow people to upload video files ( avi, mpg and wmv) to the server. But when they click the link to be taken to the file (filename.php?dowload=ID) which just uses header("Location:") to direct the client to download the file. avi files bring up the download box, but wmv and mpg just stream in the browser. How can I force downloading on these files?

Reply With Quote
  #2  
Old March 23rd, 2008, 07:59 PM
requinix's Avatar
requinix requinix is offline
Vpmytoniyomh Idrt
Click here for more information.
 
Join Date: Mar 2007
Location: Here
Posts: 2,034 requinix User rank is Captain (20000 - 30000 Reputation Level)requinix User rank is Captain (20000 - 30000 Reputation Level)requinix User rank is Captain (20000 - 30000 Reputation Level)requinix User rank is Captain (20000 - 30000 Reputation Level)requinix User rank is Captain (20000 - 30000 Reputation Level)requinix User rank is Captain (20000 - 30000 Reputation Level)requinix User rank is Captain (20000 - 30000 Reputation Level)requinix User rank is Captain (20000 - 30000 Reputation Level)requinix User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 22 h 14 m 11 sec
Reputation Power: 296
Send a message via MSN to requinix
We've got a great search engine for this site. It's perfect for commonly-asked questions like yours.
Comments on this post
sephers181 agrees!
__________________
I question my belief in the existence of buttons.
--
PHP Manual (cURL - PCRE regex - references) error_reporting() SQL injection: and mysql_real_escape_string() PHP and cron

Negative0 - always looking for more members

Reply With Quote
  #3  
Old March 24th, 2008, 12:31 AM
tobbilla78 tobbilla78 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 1 tobbilla78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 31 sec
Reputation Power: 0
Quote:
Originally Posted by o2pb
I have a slight problem. I allow people to upload video files ( avi, mpg and wmv) to the server. But when they click the link to be taken to the file (filename.php?dowload=ID) which just uses header("Location:") to direct the client to download the file. avi files bring up the download box, but wmv and mpg just stream in the browser. How can I force downloading on these files?


I really want to help you but sorry man i am not a good webdeveloper[] So i have forwarded your request to my good web developer friend.When he will give me the code i will forward it to you on the very same day.
----------------------------
Comments on this post
requinix disagrees: first post, eh? did you really just sign up to post that?
JavaNinja disagrees: can someone remove this post! I hear a scam.

Reply With Quote
  #4  
Old March 24th, 2008, 09:37 AM
Hammer65's Avatar
Hammer65 Hammer65 is online now
Web Developer/Musician
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2004
Location: Lincoln Nebraska
Posts: 1,921 Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 16 h 47 m 2 sec
Reputation Power: 500
Send a message via AIM to Hammer65
If you are simply re-directing to the actual file, then this isn't really a PHP issue. A web browser will play content of the types that are mapped to a specific plug-in. If there is no plug-in for that type of content, then it will display the download dialog. I'm surprised that AVI isn't mapped to anything since both Quicktime and WMP plug-ins support it, but there might be a conflict there.
__________________
"Strange women lying in ponds distributing swords is no basis for a system of government. Supreme executive power derives from a mandate from the masses, not from some farcical aquatic ceremony! Well, but you can't expect to wield supreme executive power just 'cause some watery tart threw a sword at you! I mean, if I went 'round saying I was an emperor just because some moistened bint had lobbed a scimitar at me, they'd put me away!"

Reply With Quote
  #5  
Old March 24th, 2008, 10:14 PM
o2pb o2pb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 50 o2pb User rank is Corporal (100 - 500 Reputation Level)o2pb User rank is Corporal (100 - 500 Reputation Level)o2pb User rank is Corporal (100 - 500 Reputation Level)o2pb User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 5 h 55 m 29 sec
Reputation Power: 5
Well, there is a way to force downloading, since I know some sites force download a .jpg file, which will otherwise load in any browser.

Reply With Quote
  #6  
Old March 25th, 2008, 09:11 AM
Hammer65's Avatar
Hammer65 Hammer65 is online now
Web Developer/Musician
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2004
Location: Lincoln Nebraska
Posts: 1,921 Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 16 h 47 m 2 sec
Reputation Power: 500
Send a message via AIM to Hammer65
Try the following

PHP Code:
Original - PHP Code
  1.  
  2.  
  3.     function getMimeType($file)
  4.     {
  5.         $nameArr = explode('.',$file);
  6.         $ext = $nameArr[(count($nameArr) - 1)];
  7.         switch(strtolower($ext))
  8.         {
  9.             case 'pdf':
  10.                 $type = 'application/pdf';
  11.                 break;
  12.             case 'jpg':
  13.                 $type = 'image/jpeg';
  14.                 break;
  15.             case 'jpeg':
  16.                 $type = 'image/jpeg';
  17.                 break;
  18.             case 'gif':
  19.                 $type = 'image/gif';
  20.                 break;
  21.             case 'mp4':
  22.                 $type = 'application/mpeg4-generic';
  23.                 break;
  24.             case 'mp3':
  25.                 $type = 'audio/mpeg';
  26.                 break;
  27.             case 'tiff':
  28.                 $type = 'image/tiff';
  29.                 break;
  30.             case 'png':
  31.                 $type = 'image/png';
  32.                 break;
  33.             case 'csv':
  34.                 $type = 'text/csv';
  35.                 break;
  36.             case 'txt':
  37.                 $type = 'text/plain';
  38.                 break;
  39.             case 'xml':
  40.                 $type = 'text/xml';
  41.                 break;
  42.             case 'html':
  43.                 $type = 'text/html';
  44.                 break;
  45.             case 'doc':
  46.                 $type = 'application/msword';
  47.                 break;
  48.             case 'zip':
  49.                 $type = 'application/zip';
  50.                 break;
  51.             case 'jpeg2000':
  52.                 $type = 'image/jp2';
  53.                 break;
  54.             case 'rtf':
  55.                 $type = 'text/rtf';
  56.                 break;
  57.             case 'mov':
  58.                 $type = 'video/quicktime';
  59.                 break;
  60.             case 'xls':
  61.                 $type = 'application/excel';
  62.                 break;
  63.             case 'ppt':
  64.                 $type = 'application/powerpoint';
  65.                 break;
  66.             case 'wav':
  67.                 $type = 'audio/x-wav';
  68.                 break;
  69.             case 'aiff':
  70.                 $type = 'audio/aiff';
  71.                 break;
  72.             case 'mid':
  73.                 $type = 'audio/x-midi';
  74.                 break;
  75.             case 'bmp':
  76.                 $type = 'image/bmp';
  77.                 break;
  78.             case 'mpeg':
  79.                 $type = 'video/mpeg';
  80.                 break;
  81.             case 'mpg':
  82.                 $type = 'video/mpeg';
  83.                 break;
  84.             case 'avi':
  85.                 $type = 'x-msvideo';
  86.                 break;
  87.             case 'pub':
  88.                 $type = 'application/x-mspublisher';
  89.                 break;
  90.             case 'sit':
  91.                 $type = 'application/x-stuffit';
  92.                 break;
  93.             case 'tar':
  94.                 $type = 'application/x-tar';
  95.                 break;
  96.             case 'ra':
  97.                 $type = 'audio/x-pn-realaudio';
  98.                 break;
  99.             case 'ram':
  100.                 $type = 'audio/x-pn-realaudio';
  101.                 break;
  102.             case 'tsv':
  103.                 $type = 'text/tab-separated-values';
  104.                 break;
  105.             case 'asf':
  106.                 $type = 'video/x-ms-asf';
  107.                 break;
  108.             case 'wma':
  109.                 $type = 'audio/x-ms-wma';
  110.                 break;
  111.             case 'wmv':
  112.                 $type = 'video/x-ms-wmv';
  113.                 break;
  114.             case 'flv':
  115.                 $type = 'video/x-flv';
  116.                 break;
  117.             case 'swf':
  118.                 $type = 'application/x-shockwave-flash';
  119.                 break;
  120.             case 'fla':
  121.                 $type = 'application/octet-stream';
  122.                 break;
  123.             default:
  124.                 $type = 'application/octet-stream';
  125.                 break;
  126.         }
  127.         return $type;
  128.     }
  129.    
  130.     function downloadHeaders($file,$filelen,$mode='I')
  131.     {
  132.         // $mode: D = force download, I = attempt inline
  133.         $type = getMimeType($file);
  134.         $mode = strtoupper($mode);
  135.         if(isset($_SESSION))
  136.         {
  137.             session_cache_limiter('no-cache');
  138.         }
  139.         header('pragma: cache');
  140.         header('pragma: public');
  141.         header('Cache-Control: max-age=0');
  142.         header("Cache-Control: private",false); // required for certain browsers
  143.         header('Content-Type: '.$type);
  144.         header("Expires: 0");
  145.         if($mode == 'D')
  146.         {
  147.             header('Content-Disposition: attachment; filename='.$file);
  148.         }
  149.         else
  150.         {
  151.             header('Content-Disposition: inline; filename='.$file);
  152.         }