YiiHaa Webdevelopment blog about Yii-framework and more

16Feb/124

Serving (large) files

Ever served large files with PHP? I bet you loved that! Do not worry, I have good news for you! There is a solution (or improvement, whatever you want to call it) to the old way of serving files, which used to look sort of like this:

<?php // Old method, which you shouldn't like anymore!
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename="myFile"');
readfile(dirname(__FILE__) . '/myFile');

This guy "Nils Maier" created a nice module for Apache called mod_xsendfile. This module allows you to send a specific header to Apache via PHP, and it's really easy to implement:

<?php // 'New' and improved method!
header('X-SendFile: ' . dirname(__FILE__) . '/myFile');
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename="myFile"');

Using this module has a couple of advantages when serving files:

  • you can control file-transfers with PHP, without actually serving using PHP
  • sets correct cache headers such as Etag and If-Modified-Since as if the file was statically served
  • processes cache headers such as If-None-Match or If-Modified-Since
  • and more..

There is just one downside to this, you need to install the module into Apache and enable it. Good thing installing it is a breeze!

wget https://tn123.org/mod_xsendfile/mod_xsendfile.c -O mod_xsendfile.c
apxs -cia mod_xsendfile.c
# Depending on your system, restart Apache
/etc/init.d/httpd restart

Now enable XSendFile in your .htaccess (or Apache config):

<IfModule mod_xsendfile.c>
  XSendFile on
</IfModule>

Now you are set up and ready to upload the hell out of your server, without leaning on PHP, enjoy!

Posted by Klaas

Comments (4) Trackbacks (1)
  1. “Which was the point, preciselyM Nor, for that matter, did Hoffman explain how this “consensus” developed miraculously in the single day that had passed since the election B The blond, leonine singer-guitarist came down from his room in standard gear black T-shirt, black jeans, black boots all psyched up to order his first beer of the evening, when the maitre d’ informed him with frosty politeness that club rules require gentlemen to wear tiesnot only for her Best Leading Actress win,Asics Gel-K

  2. “But,KD 9 Royal Blue, dig, I just can’t do that And it was great though if you think about it, here’s us doing a song, and it was really a girls’ song He said, ‘I want you back in the skirts and saddle shoes,Nike Kyrie 2 USA, and out of One-Eyed Jacks!’”Whose Twin Peaks Are They, Anyway? “On the set of the pilot,” Sherilyn says, trying to clear up one mystery, “the makeup artist always called me Miss Twin Peaks Or rather, I was and he came in to take over Her previous release,Wmns Dunk Sky High,

  3. @kimkardashian Shortly after officially launching at the end of June, the app game Kim Kardashian: Hollywood made a plea for world domination and won Sanders has a long history in the land of Ben & Jerry: He was mayor of the state’s biggest city, Burlington, before representing Vermonters in the U Orlane Absolute Skin Recovery Masque “I like to use this for tired, jet-lagged skin,” says celebrity makeup artist Matin Maulawizada, whose clients include Claire Danes, Idina Menzel, and Maggie Gyllen

  4. )The source blamed most often, though, is Curt Gentry, a San Francisco writer who authored The Last Days of the Late, Great State of California for G It sounds like something you’ve been able to provide for both your families your family onstage and your kidsfabulous!)A-ListersSign up with facebookBy signing up, I agree to theTerms& to receive emails from POPSUGAR “Retirement is appealing when you’re in full bloom,” he suggests”It’s all about the music Past studies on rats,Boys Kyrie 3, say scie


Leave a comment