无法在脚本输出中显示图像名称

时间:2016-04-01 18:52:46

标签: php

您好我是非常新的PHP,但我一直在尝试修改一些代码并且已经走到了死胡同。

我正在尝试显示上传到文件夹的最后20张图片以及文件名。我已经到了显示图像但我无法从名称中删除路径的地方,任何帮助都会得到应用。

脚本如下所示

<?php

$files = (glob('../YoungsMotors/clientimages/*.*', GLOB_BRACE)); /* change php to the file you require either html php jpg png. */
$selection = $files;

$files = array();

foreach ($selection as $file) {

    $files[$file] = 0-filemtime($file);   
}


$string = '$file';

$name = preg_replace('/../YoungsMotors/clientimages/ (.*) /','',$string);

asort($files);

foreach ($files as $file => $time) {
    $i++;
    if ($i <= 20) { /* change this to display the amount of results 1 for most recent or 10 for the 10 most recent. */
            print $image ."<br />";
echo '<img src="'.$file .'"width="200""  />'."<br />$name<br />";

    }
}
?>

1 个答案:

答案 0 :(得分:1)

我会用这样的东西。

$name = pathinfo('/var/www/html/image.jpg', PATHINFO_FILENAME)

以下是文档的链接:http://php.net/manual/en/function.pathinfo.php

此致