PHP5 Universal File Download Class

Written by Chris on August 12, 2008 – 12:16 pm -

After finding different hosting companies having wildly different policies when it comes to what's enabled and what isn't in PHP, I've built a generic file download class which should work in almost all situations.

This is the first version so there are some improvements to be made and if you download it, you'll see where some improvements may be made. I will be releasing another version when I've had time to do some further work on it. For now you can find the source code plus any community improvements here: http://www.refactormycode.com/codes/440-universal-file-download-class

I should also mention that this class has been cleaned of some application specific code, so if there's any disjointed bits I apologise - I have tried to deal with any discontinuities before posting but there may be something i've missed (this is also the reason for the bunch of if's in get_file() if you are to use this as is you may want to replace them with your own custom code).



Popularity: 82% [?]

Sphere: Related Content

Related posts on coderchris.com:

  1. Simple Function To Force Download Of A File
    The following function will allow you to run a file download through PHP, you...
  2. Why @ is NOT your friend
    Ah, the error suppression operator (@) It seems like such a fantastic idea, just...
  3. File-system mp3 Organisation - Is It Really That Hard?
    Like most people I know I have a lot of mp3's and every person...
  4. Convert Multiple Spaces To a Single Space
    Sometimes you want to sanitise a block of text or input by removing consecutive...
  5. Refactor My Code - I Wish I’d Thought of It!
    refactormycode.com is a fledgling website setup as a project by French Canadian  Ruby Developer...


Tags: , , , , , ,
Posted in PHP, Web Development | Trackback |

3 Comments to “PHP5 Universal File Download Class”

  1. James on RefactorMyCode.com Says:

    Universal File Download Class…

    I wish I had this last night… gah!…

  2. Ishkur on RefactorMyCode.com Says:

    Universal File Download Class…

    In your function ‘public function cc_wget_file($url)’, you’re passing the string through exec(). Thats fine, but PHP allows you to pass cli strings via backticks (http://www.php.net/language.operators.execution). Might help, might not, ymmv….

  3. Chris Dean on RefactorMyCode.com Says:

    Universal File Download Class…

    @Ishkur

    I try to avoid back-ticks as (for me at least) they obfuscate the code a little bit.

    That said, it may give a small performance boost - I don’t know as I’ve not done any such tests, but maybe I will if I get 5 mins :)…

Leave a Comment

RSS

  • Translator

    English flagChinese (Simplified) flagChinese (Traditional) flagDutch flagFrench flagGerman flag
    Greek flagItalian flagJapanese flagKorean flagPortuguese flagRussian flag
    Spanish flag     
    By N2H
  • Also Find Me On

    Delicious  Digg  Facebook  Flickr  FriendFeed  Last.fm  LinkedIn  LiveJournal  Ma.gnolia  MyBlogLog  MySpace  StumbleUpon  Technorati  Twitter  YouTube  



  • Find job
  • Credit Cards
  • Online Advertising
  • Guitar Lessons
  • Mortgage