为什么Glob在scandir时不起作用?

为什么Glob在scandir时不起作用?

问题描述:

Can someone explain why, in this situation, scandir is getting my directory, but the glob is getting...well, it seems like it's getting the path:

$directory = "../../../XXXXXXXXXXXXXX/media/csv";

With scandir:

$files  = scandir($directory);
print_r($files);

Result:

Array ( [0] => . [1] => .. [2] => myCsv.csv [3] => index.html )

With Glob:

$files  = glob($directory . "*"); # i wanted to select only CSV, but it returned empty. so i placed a *.

Result:

Array ( [0] => ../../../XXXXXXXXXXXXXX/media/csv ) 

有人可以解释为什么,在这种情况下,scandir正在获取我的目录,但是glob正在...... ,它似乎正在获得路径: p>

  $ directory =“../../../ XXXXXXXXXXXXXX / media / csv”; 
  code>  
 
 

使用scandir: p>

  $ files = scandir($ directory); 
print_r($ files); 
  code>  
 
 

结果: p>

 数组([0] =>。[1] => .. [2] => myCsv  .csv [3] => index.html)
  code>  pre> 
 
 

使用Glob: p>

  $ files = glob  ($ directory。“*”);  #我想只选择CSV,但它返回空。 所以我放了*。
  code>  pre> 
 
 

结果: p>

  Array([0] => ../  ../../XXXXXXXXXXXXXX/media/csv)
  code>  pre> 
  div>

Since your $directory is something like ../XXX/media/csv, you need to append it with /*.csv so it would become ../XXX/media/csv/*.csv (currently it is ../XXX/media/csv*).

$files = glob($directory . "/*.csv");