dszm02606009 2012-03-24 00:05
浏览 50
已采纳

用PHP编写Zip文件

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

  • 写回答

1条回答 默认 最新

  • doupo1908 2012-03-24 00:13
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答