Glob 没有 return 结果

Glob doesn't return results

我可能做错了什么,但我找不到什么。

这是有效的代码:

foreach (glob('uploads/'.$userid.'[*') as $file)
{
  echo $file."<br>";
}

这里是我试图让它起作用但它不起作用的方法:

foreach (glob('uploads/'.$userid.'[?]('.$id.')*') as $file)
{
  echo $file."<br>";
}

一些文件示例:

uploads/24[3](30) Random name.pdf
uploads/24[1](114) Random name.pdf
uploads/24[2](55) Random name.doc
etc etc

基本上:UserID[1-3](ID) name of the file

全局函数:

The glob() function searches for all the pathnames matching pattern according to the rules used by the libc glob() function, which is similar to the rules used by common shells.

您需要按如下方式转义方括号和圆括号:

foreach (glob('uploads/'.$userid.'\[?\]\(' . $id . '\)*') as $file) {
    echo $file."<br />";
}