简体   繁体   中英

Check the file name in the upload folder before uploading the file

I am use the following code:

if(file_exists("upload/" . '1.txt')
....

This code checks only the file with the name of "1" and ".txt" in the upload folder There is or not. I want to check it for any file named "1" with any extension (for example 1.jpg, 1.png, ...). What is the simplest code that comes to your mind?

$result = glob ("upload/1.*");

并查看$ result是否包含任何内容。

if(preg_match("/^1\.(jpg|jpeg|png|gif)$/",$filename)){}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM