[英]php glob() not finding any files
$directory = $_SESSION['base_url'] . "assets/images/*.jpg";
$images = glob($directory);
This code is not working. 该代码不起作用。 If I print out $directory, it matches the directory where I have put some .jpg files.
如果我打印出$ directory,它与我放置了一些.jpg文件的目录匹配。 $images just remains empty...
$ images仍然是空的...
As bsdnoobz answered, this was my solution: 正如bsdnoobz回答的那样,这是我的解决方案:
$directory = dirname(dirname(dirname(__FILE__))) . "\assets\images\\"; //escape
$images = glob($directory . "*.jpg");
It looks like $_SESSION['base_url']
points to your app's URL (like http://example.com
). 看起来
$_SESSION['base_url']
指向您应用的URL(例如http://example.com
)。 You should use filesystem path instead of URL. 您应该使用文件系统路径而不是URL。 Try something like this:
尝试这样的事情:
$directory = dirname(__FILE__) . '/assets/images/*.jpg';
$directory = $_SESSION['base_url'] . "assets/images/*.jpg";
$images = glob($directory);
There was an additional '
. 还有一个额外的
'
。
您在/
和.jpg
之间有一个额外的'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.