PHP-仅知道文件名的一部分时打开或复制文件? [英] PHP - Open or copy a file when knowing only part of its name?
问题描述
我有一个巨大的文件存储库,这些文件按编号的文件夹排序.每个文件夹中都有一个文件,该文件以唯一的编号开头,然后是未知的字符串.有了唯一的编号,我如何打开或复制此文件?
I have a huge repository of files that are ordered by numbered folders. In each folder is a file which starts with a unique number then an unknown string of characters. Given the unique number how can i open or copy this file?
例如:我得到的号码是"7656875",仅此而已.我需要与一个名为"\ server \ 7656800 \ 7656875 foobar 2x4"的文件进行交互.
for example: I have been given the number '7656875' and nothing more. I need to interact with a file called '\server\7656800\7656875 foobar 2x4'.
如何使用PHP实现此目标?
how can i achieve this using PHP?
推荐答案
如果您知道目录名称,请考虑使用 glob()
If you know the directory name, consider using glob()
$matches = glob('./server/dir/'.$num.'*');
然后,如果只有一个文件应以数字开头,则进行第一个(也是唯一一个)匹配.
Then if there is only one file that should start with the number, take the first (and only) match.
这篇关于PHP-仅知道文件名的一部分时打开或复制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!