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).
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