【问题标题】:How i can get size OR ext from files in cakephp我如何从 cakephp 中的文件中获取大小或 ext
【发布时间】:2014-01-22 13:24:39
【问题描述】:

在控制器中:

    public function Attachments(){
    $this->layout = null;
    $folder = new Folder(WWW_ROOT.'/files/attachments');
    $files = $folder->find('.*\.*');
    $this->set('files', $files);}

在视图中(附件.ctp):

<?php foreach($files as $file): ?>          
   <i><?php echo $file; ?></i>
<?php endforeach; ?>

我怎样才能得到大小或分机!?

【问题讨论】:

    标签: php ajax cakephp


    【解决方案1】:

    下面是我的 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);
        }
    

    以下是附件.ctp文件的代码

    <?php 
    foreach ($info as $k=>$v)
    {
        echo $v['extension'].'<br/>';
        echo $v['filesize'].'<br/>';
    }
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-12
      • 1970-01-01
      • 2021-07-01
      • 1970-01-01
      • 2014-10-21
      • 2013-10-14
      • 1970-01-01
      相关资源
      最近更新 更多