自动创建用于保存上载文件的目录 [英] Auto-create directories for saving uploaded files
问题描述
我有一个网页表单,用户可以在其中上传一个或多个文件。我已经处理了用于上传文件的客户端和服务器端代码。
但在我的情况下,所有文件都上传到一个目录。但我想将上传的文件保存在多个目录中。
我已经在某个地方读过如果文件数量太多,将所有上传的文件存储在一个目录中的效率会不高。 />
现在,我想检查上次使用(最新)目录中的文件数是否超过N,PHP创建一个新目录,然后将上传的文件保存到新目录,每次上传文件时都会重复此验证和目录创建...
如果您能为我提供解决方案,我将不胜感激。
此外,请注意一个角落案例,例如在我的目录A中,我有(N-1)个文件,在单个表单提交中,用户上传例如3个文件。在这种情况下我应该如何处理文件保存过程?
提前谢谢。
I have a web form in which users can upload one or more files. I've already handled the client-side and server-side code for uploading the files.
But in my case, all files are uploaded to a single directory. But I want to save uploaded files in multiple directories.
I've read somewhere it won't be so efficient to store all uploaded files in a single directory if number of files get too many.
Now, I want to check if the number of files in the last used(newest) directory exceeds "N",PHP creates a new directory and then save uploaded files to the new directory and this validation and directory creation repeats on each file upload...
I appreciate if you could provide me with a solution.
Besides,please notice a corner case, in which for example In my directory 'A',I have (N-1) files and in a single form submission,user uploads for example 3 files. How should I handle the file saving process in this case?
Thanks in advance.
推荐答案
你好,
如果您使用的是PHP5,那么有一个名为 scandir [ ^ ]此功能可用于首先找到最新的文件夹如下所示的路径。
Hello,
If you are using PHP5 then there is a function named scandir[^] This function can be used to first locate the newest folder in a path something like shown below.
dirs = scandir(' data',SCANDIR_SORT_DESCENDING);
dirs = scandir('data', SCANDIR_SORT_DESCENDING);
newest_dir =
newest_dir =
这篇关于自动创建用于保存上载文件的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!