I am using Codeigniter
framework. i have codeigniter
view record page.
where im showing file name. but now i want to show file name and file extension seperately. like this
file name | file ext
see my codes below
view page
<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>
model
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();
}
}
Use getimagesize()
$file // path of the file
$result = getimagesize($file);
$mime = $result["mime"];
Read pathinfo()
<?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
?>
The above example will output:
/www/htdocs/inc
inc.php
php
inc
pathinfo
does this magic for you
<?php
$ext = pathinfo("file.png", PATHINFO_EXTENSION);
echo $ext ;
$filename = pathinfo("file.txt", PATHINFO_FILENAME);
echo "<br/>";
echo $filename;
?>
This is fast, efficient, reliable and built-in. pathinfo() can give you other information, such as canonical path, depending on the constant you pass to it.
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.