我如何从cakephp中的文件获取大小或ext

时间:2014-01-22 13:24:39

标签: php ajax cakephp

在控制器中:

    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; ?>

我如何获得尺寸或分机!?

1 个答案:

答案 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/>';
}
?>