Zubaz Posted May 11, 2006 Share Posted May 11, 2006 So to stop third-party traffic on certain media files my site does, I did a download.php type script that just took in the media id, and found the filename and did a readfile on it for the user. The problem is that when you start doing massive amounts of traffic with it, I think the readfile stream is taking up a lot of cpu. Is there any alternative to readfile that creates a direct link between the user and the file, instead of it having to go through the php?I'm afraid that this is something I need to do on the server end, and not in PHP, but I figured I'd ask. Quote Link to comment https://forums.phpfreaks.com/topic/9532-alternative-to-readfile/ Share on other sites More sharing options...
.josh Posted May 11, 2006 Share Posted May 11, 2006 from php.net/readfile comments section:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]A mime-type-independent forced download can also be conducted by using:<?(...)header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // some day in the pastheader("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");header("Content-type: application/x-download");header("Content-Disposition: attachment; filename={$new_name}");header("Content-Transfer-Encoding: binary");?>[/quote]i don't know if this will help you in any way. if you go to php.net/readfile and scroll down to the submitted comments it gives various alternate methods for forced downloads. Quote Link to comment https://forums.phpfreaks.com/topic/9532-alternative-to-readfile/#findComment-35193 Share on other sites More sharing options...
Zubaz Posted May 13, 2006 Author Share Posted May 13, 2006 You missunderstand. I know how to do the code with readfile - I'm looking for a way to make the connection between media server and client directly, without piping it through php.MEDIA SERVER --> readfile() --> user-bad for high traffic - effectively doubles your bandwith usageMEDIA SERVER --> user-happiness! Quote Link to comment https://forums.phpfreaks.com/topic/9532-alternative-to-readfile/#findComment-35342 Share on other sites More sharing options...
fuji0050 Posted May 28, 2009 Share Posted May 28, 2009 A media server is a computer appliance, ranging from an enterprise class machine providing video on demand, to, more commonly,________________[url=http://www.inin.com/ProductSolutions/Pages/Enterprise-Interaction-Center.aspx]IP PBX[/url] Quote Link to comment https://forums.phpfreaks.com/topic/9532-alternative-to-readfile/#findComment-843989 Share on other sites More sharing options...
MadTechie Posted May 28, 2009 Share Posted May 28, 2009 You can use CV's code[quote author=Crayon Violent link=topic=93268.msg373213#msg373213 date=1147333559][code]<?phpheader("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // some day in the pastheader("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");header("Content-type: application/x-download");header("Content-Disposition: attachment; filename=\"{$new_name}\"");header("Content-Transfer-Encoding: binary");?>[/code][/quote]Just set $new_name to the name and Location to the urlie[code=php:0]header("Location: http://mydomain.com/myfile.txt");$new_name = "myfile.txt";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/9532-alternative-to-readfile/#findComment-843991 Share on other sites More sharing options...
redarrow Posted May 28, 2009 Share Posted May 28, 2009 does not matter what way you do this your need good bandwidth and a dedicated server for the media files if there thousands like torents.also all users should be logged in to download the files more secure.go the ftp way better and more secure. Quote Link to comment https://forums.phpfreaks.com/topic/9532-alternative-to-readfile/#findComment-843993 Share on other sites More sharing options...
.josh Posted May 28, 2009 Share Posted May 28, 2009 seriously? this thread is 2 years old... Quote Link to comment https://forums.phpfreaks.com/topic/9532-alternative-to-readfile/#findComment-844109 Share on other sites More sharing options...
MadTechie Posted May 28, 2009 Share Posted May 28, 2009 LOL didn't notice, fuji0050 reply revived It Quote Link to comment https://forums.phpfreaks.com/topic/9532-alternative-to-readfile/#findComment-844121 Share on other sites More sharing options...
demonicoder Posted December 21, 2011 Share Posted December 21, 2011 I'm writing because I see that this thread, even though old, it still is pretty up-to-date with the situation. The readfile method works perfectly, however, I need a way to force the download on the user and make them download the file straight from the external server. Whenever I am trying to use:header('Content-Disposition:attachment;bla bla bla without readfileI download the file, however it is 0 bytes. I then thought that maybe the browser did not understand how many bytes to download, so I calculated the file size of the remote file and sent another header along the way like:header("Content-length: $video_size");Has anyone managed to successfully got this to work without the use of readfile and not get an empty zero file? Quote Link to comment https://forums.phpfreaks.com/topic/9532-alternative-to-readfile/#findComment-1300040 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.