我正在开发一个类似画廊的网络应用程序。用户可以请求将某个目录下的所有照片下载为 zip 文件。我将以这种方式实现此功能:创建每个请求的文件名都是唯一的 zip 文件,将文件保存在目录中,然后通过 x-sendfile 发送给用户。
那么保存这些临时文件的好位置是什么呢?一个好的位置意味着一个会自动清理的目录?是否存在这种目录?该应用程序在 Linux + Apache + PHP 上运行。
I am developing a gallery-like web app. Users can request to download all photos under a directory as a zip file. I'm going to implement this feature in this way: create the zip file whose filename is unique for each request, save the file in a directory, and send to the user via x-sendfile.
So what's a good location to save those temporary files? A good location means a directory which is cleaned up automatically? Does this kind of directories exist? The app is running on Linux + Apache + PHP.
发布评论
评论(2)
我能想到的一种方法是创建一个临时目录,其目录名称与每个请求的唯一文件名相同,并将文件放入其中。操作结束后(成功或异常),请确保删除此目录
One approach i could think of is create a temporary directory with directory name same as the unique filename for each request and put files in it. After the operation ends (successfully or with an exception), make sure you delete this directory
你可以在这里使用 Apache Ant 吗?因为这里有一个 Zip 类:
http://www.jajakarta.org/ant/ant-1.6.1/docs/en/manual/api/org/apache/tools/ant/taskdefs/Zip.html
和它有一个 cleanUp() 方法,可以满足您的要求。
Can you use Apache Ant here? Because there is a Zip class here :
http://www.jajakarta.org/ant/ant-1.6.1/docs/en/manual/api/org/apache/tools/ant/taskdefs/Zip.html
And it has a cleanUp() method which does what you are asking.