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']; ?>
    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