Codeigniter-显示扩展名为的文件名


Codeigniter - show file name with extension

我使用的是Codeigniter框架。我有codeigniter查看记录页面。

其中im显示文件名。但现在我想分别显示文件名和文件扩展名。像这个

file name  |  file ext

请参阅下面的我的代码

查看页面

<div class="gallery gallery-2">
<ul class="row">
    <?php $images = $this->fileupload_model->get_all_files(); ?>
    <?php if ($images): ?>
    <?php foreach ($images as $image): ?>
    <li class="col-md-3 hidden-phone">
        <a class="thumb no-ajaxify" data-gallery="gallery-2" href="#">
        <img style="width:177px;height:130px;" src="/uploads/<?php if ('/uploads/$image->file_url') echo $image->file_url ?><?php else echo "pdf.png" ?>" alt="uploaded files" class="img-responsive" /></a>
        <p>Status: <strong>
        <?php if ($image->status == 2 && 1)
        echo "<a style='text-decoration:underline;' href='/admin/fileupload/status/$image->file_id'>Deactive</a>";
        else
        echo "<a style='text-decoration:underline;' href='/admin/fileupload/status/$image->file_id'>Active</a>";
        ?>
        </strong> &nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="/admin/fileupload/delete/<?php echo $image->file_id; ?>" class="btn btn-sm btn-danger"><i class="fa fa-times"></i></a></p>
        <p>File Url: <strong><a href="/uploads/<?php echo $image->file_url; ?>" target="_blank">click for url</a></strong></p>
        <div class="separator">&nbsp;</div>
    </li>
    <?php endforeach ?>
    <?php else: ?>
        <h2 style="color:red;font-weight:bold;text-transform:uppercase;font-size:17px;">oh Sorry, No Images Found !</h2>
    <?php endif ?>
</ul>
</div>

型号

public function files_insert($name_array) //add images from model
{
    foreach ($name_array as $photo)
    {       
        $data = array(
            'file_url' => $photo,
            'status' => '1',
        );
        $this->db->insert('file_upload', $data);
        $this->db->affected_rows();
    }
}

读取路径信息()

<?php
$path_parts = pathinfo('/www/htdocs/inc/inc.php');
echo $path_parts['dirname'], "'n";
echo $path_parts['basename'], "'n";
echo $path_parts['extension'], "'n";
echo $path_parts['filename'], "'n"; // since PHP 5.2.0
?>

上面的例子将输出:

/www/htdocs/inc 公司

包括php

php

包括

使用getimagesize()

$file // path of the file
$result = getimagesize($file);
$mime = $result["mime"];

pathinfo为您的带来了魔力

 <?php 
    $ext = pathinfo("file.png", PATHINFO_EXTENSION);
    echo $ext ;
    $filename = pathinfo("file.txt", PATHINFO_FILENAME);
    echo "<br/>";
    echo $filename;
    ?>

这是快速、高效、可靠和内置的。pathinfo()可以根据传递给它的常量为您提供其他信息,例如规范路径