SitePoint Sponsor

User Tag List

Results 1 to 25 of 25
  1. #1
    SitePoint Guru Angry Coder's Avatar
    Join Date
    May 2002
    Location
    Canada
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question How can I store and pull out Zip files from MySQL table using PHP?

    Hello,

    I have some zip files, varies in sizes (between ~10 KB and ~10 MB), which I want to store into MySQL table... I am wondering how can I do that?

    I mean how can I insert a zip file and how can I pull it out in PHP?

    ... and what MySQL field type I have to use?

    You help is greatly appreciated.
    Why It Doesn't Work?!

  2. #2
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You shouldn't store 10mb of binary data into a MySQL field. You should just store it on disk, and then put the filename into the database.

    Is there a reason why you need it in SQL?

  3. #3
    SitePoint Guru Angry Coder's Avatar
    Join Date
    May 2002
    Location
    Canada
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your reply.

    But... Why I shouldn't store 10mb of binary data into a MySQL field? Is it a performance issue? What about <= 2MB?

    Actually the reason behind storing data on MySQL is to prevent stealing bandwidth by linking to my songs from out side (I can't use HOTLINKING feature at the mean time).
    Why It Doesn't Work?!

  4. #4
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can feed the image through a PHP script regardless of whether it's on the disk or in MySQL. There's absolutely NO difference externally. The only internal difference is that databases are made for content. You shouldn't store images, files, anything in it -- except for text/content. That's why there's a file system.

  5. #5
    SitePoint Guru Angry Coder's Avatar
    Join Date
    May 2002
    Location
    Canada
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBulletin stores the attachments in the database. I want to do the same, it's my idol

    Is there any tutorial?
    Why It Doesn't Work?!

  6. #6
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does it really?

    Finding a tutorial could be difficult. Few people will go publishing a tutorial on how to make a less efficient file management system that misuses the intentions of a database.

  7. #7
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by someonewhois
    Does it really?

    Finding a tutorial could be difficult. Few people will go publishing a tutorial on how to make a less efficient file management system that misuses the intentions of a database.
    Really?

    http://www.google.com/search?hl=en&l...ary+data+mysql

  8. #8
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You know I've never actually looked.

  9. #9
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Haha

  10. #10
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What's the big deal about storing binary datra in a database?

    Is it really that bad?

    Off Topic:


    300th post!

  11. #11
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It'd be like using GMail for storing files instead of e-mail.

    Oh, wait, people do...

    To put it into a better analogy, it'd be like storing fish in a water bottle. Sure, it'll work, it's just not what the water bottle was designed for.

  12. #12
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That GMail client is mighty handy.

  13. #13
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And it doesn't make for a happy fish

  14. #14
    SitePoint Guru dbevfat's Avatar
    Join Date
    Dec 2004
    Location
    ljubljana, slovenia
    Posts
    684
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For very small fish - a bottle would be just fine

    Just like for small files - I guess it'd be ok to store in a database, until you put an index on the blob field (is that possible at all?). But the filesystem is a database already, so take advantage of that.

    Regards

  15. #15
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A small fish woul still do better in a large tank than it would in a small bottle.

  16. #16
    SitePoint Guru Angry Coder's Avatar
    Join Date
    May 2002
    Location
    Canada
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Thanks to all... specially Dylannn. The google results of your query is GREAT. I got 8 articles.

    Please admin; move this topic to the aquarium's section.
    Why It Doesn't Work?!

  17. #17
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Remember to rep for helpful post

    </rep-plugging>

  18. #18
    SitePoint Guru Angry Coder's Avatar
    Join Date
    May 2002
    Location
    Canada
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    rep = Report Bad Post?



    I don't see the reputation button!!! where it is?
    Why It Doesn't Work?!

  19. #19
    SitePoint Guru MikeBigg's Avatar
    Join Date
    Jun 2004
    Location
    Reading, UK
    Posts
    970
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As someonewhois suggests, storing large files in a database is not the best thing to do. Although possible, most database professionals would advise against it for large files. There have been a number of threads on this topic, but where the advice given is "don't do it", there seems to be little in the way of a technical argument for why.

    This is my thinking on the subject and it relates primarily to scaleability:

    1) In a web application context, if you serve the binary file from the db through a script you will need more processing power to serve a page than if you stored the URL to the file in the db. As processing power on a server is finite, if traffic level to your website increase, you will need a faster server sooner if you have your binary files stored in the db.

    2) Database files are stored on disk. If you are adding many large files stored in the database the disk space will run out or the max size of db file will be reached. You will need to split the database between disks and or servers. If the files are in the filing system, the files can easily be spread around disks and servers in different places around the world if need be, with ease.

    3) Backups. Do you really want to create backups of your database including all the binary data? As the database gets larger the problems associated with backups increase.

    To conclude: if you run a small site with only tens of files totalling a couple of gigs of space with relatively small number of visitors you can probably get away with having your picture, video or music files in a database. If your site is likely to exceed those parameters you would be better starting off with a scaleable structure, which, in this context, means don't put the binary files in the database.

    Mike

  20. #20
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Very well said, Mike.

  21. #21
    SitePoint Guru MikeBigg's Avatar
    Join Date
    Jun 2004
    Location
    Reading, UK
    Posts
    970
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dylannn
    Very well said, Mike.
    Thanks Dylannn.

    Mike

  22. #22
    SitePoint Guru Angry Coder's Avatar
    Join Date
    May 2002
    Location
    Canada
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's now very clear, thanks Mike!

    I'll do it by the way... I'll store the fish in a water bottle
    Why It Doesn't Work?!

  23. #23
    SitePoint Guru MikeBigg's Avatar
    Join Date
    Jun 2004
    Location
    Reading, UK
    Posts
    970
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Angry Coder
    It's now very clear, thanks Mike!
    Don't mention it.

    I'll do it by the way... I'll store the fish in a water bottle
    I thought you might ...

    Mike

  24. #24
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Angry Coder
    rep = Report Bad Post?



    I don't see the reputation button!!! where it is?

    The little scale icon under the post count of a user.

  25. #25
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dylannn
    The little scale icon under the post count of a user.
    He has reputation disabled (see the black dot under his name), so he can't give rep until he enables it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •