如何使用 cakephp 显示或打印目录内的所有图像
How to display or print all images inside a directory using cakephp
我是 cakephp 的新手,感谢您的帮助
<?php
$dir = new Folder(WWW_ROOT . '/img/profile/'.$profile);
$files = $dir->find('.*', true);
pr($files);exit;
?>
下面输出
Array
(
[0] => 1.png
[1] => 20643696_1656261664406406_1426837475_n.jpg
[2] => IMG_2911.JPG
[3] => h.png
[4] => 5.jpg
)
我不知道如何循环打印图像。
我可以在目录中回显 1 个图像
echo $this->Html->image('profile/' .$br.$profile.$br.stream_get_contents($users->profile_pic),array('width'=>'250px','height'=>'250px'));
profile_pic是数据库中的图像字段
如果你想显示实际图像,你可以做这样的事情:
foreach($files as $file){
echo "<img src='./img/profile/$profile/$file'>";
}
请注意,您应该检查文件是否真的是图片(png、jpg、gif 等)
如果你只想打印名字,你可以这样做:
foreach($files as $file){
echo $file . "<br>"; // The br is optional
}
更新:只需删除 stream_get_contents:
echo $this->Html->image('profile/' .$br.$profile.$br.$file);
我是 cakephp 的新手,感谢您的帮助
<?php
$dir = new Folder(WWW_ROOT . '/img/profile/'.$profile);
$files = $dir->find('.*', true);
pr($files);exit;
?>
下面输出
Array
(
[0] => 1.png
[1] => 20643696_1656261664406406_1426837475_n.jpg
[2] => IMG_2911.JPG
[3] => h.png
[4] => 5.jpg
)
我不知道如何循环打印图像。
我可以在目录中回显 1 个图像
echo $this->Html->image('profile/' .$br.$profile.$br.stream_get_contents($users->profile_pic),array('width'=>'250px','height'=>'250px'));
profile_pic是数据库中的图像字段
如果你想显示实际图像,你可以做这样的事情:
foreach($files as $file){
echo "<img src='./img/profile/$profile/$file'>";
}
请注意,您应该检查文件是否真的是图片(png、jpg、gif 等)
如果你只想打印名字,你可以这样做:
foreach($files as $file){
echo $file . "<br>"; // The br is optional
}
更新:只需删除 stream_get_contents:
echo $this->Html->image('profile/' .$br.$profile.$br.$file);