[英]PHP script to display images from folder
Hi I have security cam that uploads via ftp to my server and I want to show last images as slideshow but I can't manage it to work.嗨,我有通过 ftp 上传到我的服务器的安全摄像头,我想将最后的图像显示为幻灯片,但我无法让它工作。 I have this code我有这个代码
$base_path = 'wp-content/uploads/camer/10.121.0.202';
$latest_date_folder = scandir($base_path, SCANDIR_SORT_DESCENDING);
$latest_folder = scandir($base_path . "/" . $latest_date_folder[0], SCANDIR_SORT_DESCENDING);
$directory = '../" . $base_path . "/" . $latest_date_folder[0] . "/" . $latest_folder[0] . ';
try {
echo '<div id="myslides">';
foreach ( new DirectoryIterator($directory) as $item ) {
if ($item->isFile()) {
$path = $directory . '/' . $item;
echo '<img src="' . $path . '"/>';
}
}
echo '</div>';
}
catch(Exception $e) {
echo 'No images found for this slideshow.<br />';
}
?>
I am still getting 'No images found for this slideshow.'我仍然收到“找不到此幻灯片的图像”。 But when I try this code但是当我尝试这段代码时
$latest1_date_folder = scandir($base1_path, SCANDIR_SORT_DESCENDING);
$latest1_folder = scandir($base1_path . "/" . $latest1_date_folder[0], SCANDIR_SORT_DESCENDING);
$latest1_file = scandir($base1_path . "/" . $latest1_date_folder[0] . "/" . $latest1_folder[0] , SCANDIR_SORT_DESCENDING);
echo "<img src='../" . $base1_path . "/" . $latest1_date_folder[0] . "/" . $latest1_folder[0] . "/" . $latest1_file[0] . "' />";
It displays last image normally.它正常显示最后一个图像。 What am I doing wrong?我究竟做错了什么? Thanks a lot.非常感谢。
I am using wordpress plugin phpcode snippets我正在使用 wordpress 插件 phpcode 片段
your directory variable is wrong!你的目录变量是错误的! you should write like this你应该这样写
$directory = '../'. $base_path . "/" . $latest_date_folder[0] . "/" . $latest_folder[0];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.