Home › Forums › General Issues › how to get filetype (extension)? › Reply To: how to get filetype (extension)?
This worked for me and I am able to get the file type extension but now I would like to use an if statement with that extension so I can assign icons to my files based on the file type. So for example, if the filetype equals pdf then I would output a pdf icon. How can I do an if else type of statement using this?
I tried the following but no luck:
<?php $attachment_id = get_field('document_upload');
$url = wp_get_attachment_url( $attachment_id );
$title = get_the_title( $attachment_id );
// part where to get the filesize
$filesize = filesize( get_attached_file( $attachment_id ) );
$filesize = size_format($filesize, 2);
$path_info = pathinfo( get_attached_file( $attachment_id ) );
// show custom field
if (get_field('document_upload')): ?>
<?php echo $filesize; ?>
<?php echo $path_info['extension']; ?>
<?php
if ($path_info = "pdf") {
echo "<i class='fa fa-file-pdf-o' aria-hidden='true'></i>";
} ?>
<?php endif; ?>
Not really sure where to go from here. Thanks
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.