我正在使用Codeigniter
框架。
我有codeigniter
查看记录页。
其中我显示文件名。 但现在我想单独显示文件名和文件扩展名。 像这样
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> | <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"> </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();
}
}
答案 0 :(得分:1)
$file // path of the file
$result = getimagesize($file);
$mime = $result["mime"];
答案 1 :(得分:1)
<?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
?>
以上示例将输出:
/网络/ htdocs中/ INC
inc.php
PHP
INC
答案 2 :(得分:0)
pathinfo
为你做这个魔术
<?php
$ext = pathinfo("file.png", PATHINFO_EXTENSION);
echo $ext ;
$filename = pathinfo("file.txt", PATHINFO_FILENAME);
echo "<br/>";
echo $filename;
?>
这是快速,高效,可靠和内置的。 pathinfo()可以为您提供其他信息,例如规范路径,具体取决于您传递给它的常量。