PHP: How can I grab a single file from a directory without scanning entire directory?

前端 未结 4 501
别跟我提以往
别跟我提以往 2020-12-29 08:59

I have a directory with 1.3 Million files that I need to move into a database. I just need to grab a single filename from the directory WITHOUT scanning the whole directory.

4条回答
  •  不知归路
    2020-12-29 09:29

    readdir will do the trick. Check the exampl on that page but instead of doing the readdir call in the loop, just do it once. You'll get the first file in the directory.

    Note: you might get ".", "..", and other similar responses depending on the server, so you might want to at least loop until you get a valid file.

提交回复
热议问题