在控制器中:
public function Attachments(){
$this->layout = null;
$folder = new Folder(WWW_ROOT.'/files/attachments');
$files = $folder->find('.*\.*');
$this->set('files', $files);}
在视图(Attachments.ctp)中:
<?php foreach($files as $file): ?>
<i><?php echo $file; ?></i>
<?php endforeach; ?>
我如何获得尺寸或分机!?
答案 0 :(得分:0)
以下是我的PostController中的操作
public function attachments(){
$dir = new Folder(WWW_ROOT.'files/attachments');
$files = $dir->read(true);
foreach ($files['1'] as $k=>$v)
{
$fileObj = new File(WWW_ROOT.'files/attachments/'.$v);
$info[]=$fileObj->info();
}
$this->set('info',$info);
}
及以下是attachments.ctp文件的代码
<?php
foreach ($info as $k=>$v)
{
echo $v['extension'].'<br/>';
echo $v['filesize'].'<br/>';
}
?>