In controller:
public function Attachments(){
$this->layout = null;
$folder = new Folder(WWW_ROOT.'/files/attachments');
$files = $folder->find('.*\.*');
$this->set('files', $files);}
In View (Attachments.ctp):
<?php foreach($files as $file): ?>
<i><?php echo $file; ?></i>
<?php endforeach; ?>
How i can get size OR ext !?
Below is action in my 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);
}
and below is code of attachments.ctp file
<?php
foreach ($info as $k=>$v)
{
echo $v['extension'].'<br/>';
echo $v['filesize'].'<br/>';
}
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.