0

I am creating a game currently and I want users to be able to upload their save games to my site for them to retrieve later, like if they log into another computer or accidentally delete their save from their computer. I want the file to be linked to the specific user that uploaded it, which is easy to do. I have a MySQL database set up that stores the usernames and passwords. The way I think I am going to link the file to the user is to upload the file with its name the same as the username. My problem is I don't want the files to be able to be accessed without being the owner of the file and I don't want them all sitting on my web server taking up more room than is needed. I think a good solution is to zip them up together. What would the easiest way to do that is and be able to retrieve it without unzipping every single file in it to get the one save file. Is it possible to take just one file out of it? I am reading up on the zip functions, http://php.net/manual/en/ref.zip.php. Also, is there a better/easier way of setting each file to a specific "owner"? Thanks!

Edit: I want to both zip and unzip the file(s).

8
  • 1
    You want to zip them, but you don't want to unzip them? Commented Mar 24, 2012 at 0:08
  • Sorry, I want to do both zip and unzip. I must not have said that sorry. I will add to first post! Commented Mar 24, 2012 at 0:09
  • 1
    I think you need to rethink your strategy here. Commented Mar 24, 2012 at 0:11
  • What would you suggest doing instead? Commented Mar 24, 2012 at 0:12
  • What type of files should be uploaded?
    – Dion
    Commented Mar 24, 2012 at 0:13

1 Answer 1

2

If I understand you well, you want to save all users files into the same big one? I don't think it's a good idea... Your server will spend a lot of time to find the only small file that needs to be unzipped, and it's the same for insertion.

Instead, simply zip each files individually. YOu'll still save some space, but without eating 100% of the resources of your server.

To link users & files, you just needs 2 tables, users and savegames. It's better to do the link between those tables using user_id, MySQL is faster on integers than varchar.

Here are some examples from php.net http://php.net/manual/en/zip.examples.php

7
  • Oh OK. I can't seem to figure out the Zip functions though. Could you give me a simple example of zipping and unzipping? Sometimes php.net doesn't give me enough info. Commented Mar 24, 2012 at 0:15
  • That zipping is not easy, and it's really not a good idea for what you want to. If you need it for something else you could just search the web for that there has to be a tutorial.
    – Dion
    Commented Mar 24, 2012 at 0:19
  • What would you suggest over my original idea? The files I would be uploading would be very small. Just a few kilobytes, maybe up to a megabyte or two so the zipping is not really necessary now that I think about it. What I am more worried about is if there gets to be a lot of files on the server. Commented Mar 24, 2012 at 0:20
  • 1
    Just let the user upload their file onto the server. I don't know how large these savegames are, but you could also just save these files as 'username.*savegameextension*'. Then you wouldn't need the second table in your database, if the script only lets the user download his file. Or should the users be able to upload more than one file? Than it would be besser with a table.
    – Dion
    Commented Mar 24, 2012 at 0:24
  • 2
    You should make a file size and number of files limit. E.g. Every user can upload 5 files with max. 1 mb...
    – Dion
    Commented Mar 24, 2012 at 0:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.