-1

Help to modify this script to hide the file extension in the listing. Clicking on links in the listing must function as before - i.e. open

function display_block( $file )
{
    global $ignore_file_list, $ignore_ext_list, $force_download;

    $file_ext = getFileExt($file);
    if( !$file_ext AND is_dir($file)) $file_ext = "dir";
    if(in_array($file, $ignore_file_list)) return;
    if(in_array($file_ext, $ignore_ext_list)) return;

    $download_att = ($force_download AND $file_ext != "dir" ) ? " download='" . basename($file) . "'" : "";

    $rtn = "<div class=\"block\">";
    $rtn .= "<a href=\"$file\" class=\"$file_ext\"{$download_att}>";
    //$rtn .= " <div class=\"img $file_ext\">&nbsp;</div>";
    $rtn .= "   <div class=\"name\">\n";
    $rtn .= "       <div class=\"file\">" . basename($file) . "</div>\n";
    //$rtn .= "     <div class=\"date\">Size: " . format_size($file) . "<br />Last modified: " .  date("D. F jS, Y - h:ia", filemtime($file)) . "</div>\n";
    $rtn .= "   </div>\n";
    $rtn .= "   </a>\n";
    $rtn .= "</div>";
    return $rtn;
}
Caconde
  • 4,177
  • 7
  • 35
  • 32
Gideon
  • 43
  • 5
  • 2
    What have you already tried that isn't working as expected? Please [edit] your question and share what you have tried. – Dave Aug 20 '19 at 18:15

1 Answers1

1

You can use pathinfo function to get filename without extension as below:

function display_block($file) {
    global $ignore_file_list, $ignore_ext_list, $force_download;
    $file_ext = getFileExt($file);
    if (!$file_ext AND is_dir($file))
        $file_ext = "dir";
    if (in_array($file, $ignore_file_list))
        return;
    if (in_array($file_ext, $ignore_ext_list))
        return;

    $filePathInfo = pathinfo($file); 
    $download_att = ($force_download AND $file_ext != "dir" ) ? " download='" . basename($file) . "'" : "";

    $rtn = "<div class=\"block\">";
    $rtn .= "<a href=\"$file\" class=\"$file_ext\"{$download_att}>";
//$rtn .= " <div class=\"img $file_ext\">&nbsp;</div>";
    $rtn .= "   <div class=\"name\">\n";
    $rtn .= "       <div class=\"file\">" . $filePathInfo['filename'] . "</div>\n";
//$rtn .= "     <div class=\"date\">Size: " . format_size($file) . "<br />Last modified: " .  date("D. F jS, Y - h:ia", filemtime($file)) . "</div>\n";
    $rtn .= "   </div>\n";
    $rtn .= "   </a>\n";
    $rtn .= "</div>";
    return $rtn;
}

basename function is used when we are sure about the file extension. if you are sure that file extension will be same then you can also use it as below:

$fileName = basename($file, ".php"); 

Hope it helps you!!

Rohit Mittal
  • 2,064
  • 2
  • 8
  • 18