LiteSpeed Technologies
Download Download     Blog Blog     Wiki Wiki     Forum Forum     Store     Contact Contact    

Go Back   LiteSpeed Support Forums > External Applications > PHP > [solved] Force Download or any better than readfile()

Reply
 
Thread Tools Display Modes
  #1  
Old 07-09-2012, 03:11 PM
redstrike redstrike is offline
Senior Member
 
Join Date: May 2011
Posts: 63
Post [solved] Force Download or any better than readfile()

I want to force download files instead of letting browsers handle files automaticaly. My files are stored on a remote server. Is there any way better than using readfile() to buffer download?

I see the Internal Redirect, but it's not working.

Last edited by NiteWave; 07-11-2012 at 10:07 AM..
Reply With Quote
  #2  
Old 07-09-2012, 03:45 PM
webizen webizen is offline
LiteSpeed Staff
 
Join Date: Oct 2010
Posts: 2,337
Can you be more specific about your implementation? The internal redirect is as follows for reference.

http://www.litespeedtech.com/support...ernal_redirect
Reply With Quote
  #3  
Old 07-09-2012, 08:31 PM
redstrike redstrike is offline
Senior Member
 
Join Date: May 2011
Posts: 63
I have 2 servers, 1 for running PHP apps and database, 1 for streaming and download medium static files.

I was using this line of PHP code to handle download.

PHP Code:
header('Location: ' $external_media_url); 
It's good in performance but lacking of convenience for my users, IE users must Save target as..., or browsers auto-handle this with their inline media player.

I've searched around the internet for a coupe of hours, but everyone is using these line of codes for their download feature.

PHP Code:
        $filename basename($url).PHP_EOL;
        
$filesize getRemoteFileSize($url);            
        
header('Content-Description: File Transfer');        
        
header('Expires: 0');
        
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        
header('Pragma: public');
        
header('Content-Disposition: attachment; filename =' $filename);
        
header('Content-Length: ' $filesize);
        
readfile($url); 
This works GREAT, but i see an impact to client's speed rate and long processing time to serve a download, because it must read entire filesize in the external server and re-buffer to serve client.
Reply With Quote
  #4  
Old 07-10-2012, 10:58 AM
webizen webizen is offline
LiteSpeed Staff
 
Join Date: Oct 2010
Posts: 2,337
if you want to use LSWS internal redirect, you need the download and PHP app on the same server or download being the local path to PHP app (or via nfs mount).
Reply With Quote
  #5  
Old 07-10-2012, 09:56 PM
redstrike redstrike is offline
Senior Member
 
Join Date: May 2011
Posts: 63
Quote:
Originally Posted by webizen View Post
if you want to use LSWS internal redirect, you need the download and PHP app on the same server or download being the local path to PHP app (or via nfs mount).
I follow this guide: http://drupal.org/node/417866

AND it works like a charm.
Reply With Quote
  #6  
Old 07-11-2012, 10:07 AM
NiteWave NiteWave is offline
LiteSpeed Staff
 
Join Date: Sep 2009
Posts: 2,217
paste the tip here:
Code:
in .htaccess:
<FilesMatch "\.(?i:doc|odf|pdf|rtf|txt)$">
  Header set Content-Disposition attachment
</FilesMatch>
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 07:22 PM.



- Archive - Top
© Copyright 2003-2011 LiteSpeed Technologies, Inc. All rights reserved. Privacy Policy.