【发布时间】:2017-08-02 10:41:14
【问题描述】:
在下面的 php 函数中,我在第 31 行出现错误“严格标准:只能通过引用传递变量”
当我阅读论坛上的答案时,我必须更改explode(..)。但我不知道如何..
function scanDirectoryImages($directory, array $exts = array('jpeg', 'jpg', 'png'))
{
if (substr($directory, -1) == 'uploads/') {
$directory = substr($directory, 0, -1);
}
$html = '';
if (
is_readable($directory)
&& (file_exists($directory) || is_dir($directory))
) {
$directoryList = opendir($directory);
while($file = readdir($directoryList)) {
if ($file != '.' && $file != '..') {
$path = $directory . '/' . $file;
if (is_readable($path)) {
if (is_dir($path)) {
return scanDirectoryImages($path, $exts);
}
if (
is_file($path) && in_array(end(explode('.', end(explode('/', $path)))), $exts) // Line 31
) {
$html .= '<a href="' . $path . '"><img src="' . $path
. '" style="max-height:100px;max-width:100px" /></a>';
}
}
}
}
closedir($directoryList);
}
return $html;
}
【问题讨论】:
-
将
end(explode('/', $path))设置为 if 语句上方的自己的变量,然后改用它。
标签: php