【问题标题】:How I can get a file's icon and show it on a web site application如何获取文件的图标并将其显示在网站应用程序上
【发布时间】:2014-03-29 11:36:09
【问题描述】:

我正在 Windows 8 上的 CodeIgniter 2.1.3 上编写一个下载站点。 我想获取并显示用户上传的每个文件的文件图标。 这些文件可以有任何扩展名(.exe、.mpg、.rar、.pdf)。 我该怎么做?

【问题讨论】:

  • 您必须自己定义它们。方法:查找/创建图标并按扩展将它们应用于项目。

标签: php html windows icons codeigniter-2


【解决方案1】:

这样做的唯一方法是将所有关联的文件图标作为图像,您可以在许多地方下载它们,例如这里 iconarchive .doc .jpg .pdf 等并将它们放在一个文件夹中,然后使用 PHP 根据文件扩展名显示相应的文件图标。

我创建了一个脚本来读取文件夹中的文件数据,然后您可以获取文件名并获取特定的文件扩展名,我这里只使用 pdf,所以不太关心不同的扩展名

function displayDocuments($path){   

 if ($handle = opendir($path))
 {

   $up = substr($path, 0, (strrpos(dirname($path."/."),"/")));
   $order = '"desc"';
   $csvarray = array(array('Type','Document','Last Modified','File Size'));
/*   echo "<table id='Docs'>";
     echo "<thead id='DocsHeaderRow'>";
   echo "<th colspan='2' align='center' data-sort='string'>File Name</th>";
   echo "<th align='center' data-sort='float'>Last Modified</th>";
   echo "<th align='center' data-sort='int' >File Size</th>";
  // echo "<a href='".$_SERVER['PHP_SELF']."?path=$up'>Up one level</a>";
   echo "</thead>";
echo "<tbody>";*/
   while (false !== ($file = readdir($handle)))
   {
     $files[] = $file;

       if ($file != "." && $file != ".." && $file != "documents.csv")
       {
           $fName  = preg_replace("/\\.[^.\\s]{3,4}$/", "", $file);
           $file   = $path.'/'.$file;
           $fileSize = filesize($file);
           //$sitename = bloginfo('template_directory');
          // $fileSizefinal = number_format($fileSize/1048576,1)."MB";

           if ($fileSize >= 1048576)
    {
        $fileSizefinal = number_format($fileSize / 1048576, 2) . ' MB';
    }
    elseif ($fileSize >= 1024)
    {
        $fileSizefinal = number_format($fileSize / 1024, 2) . ' KB';
    }

           if(is_file($file)) {
        arsort(filemtime($file));   

             /*  echo "<tr>";
               echo "<td><img src='";
               echo bloginfo('template_directory');
               echo "/images/Adobe_Acrobat_PDF.png' id='docIcon' border='0'/>";
               echo "</td>";
               echo "<td><a href='".$file."'>".$fName."</a></td>"
                        ."<td align='right'>&nbsp;".date ('Y-m-d H:i:s', filemtime($file))."</td>"
                        ."<td align='right'>&nbsp;".$fileSizefinal."</td></tr>";*/
           } elseif (is_dir($file)){
               print "<tr><td colspan='3'> -D- <a href='".$_SERVER['PHP_SELF']."?path=$file'>$fName</a></td></tr>";
           }
           $csvrowarray = array("<img src='http://10.200.200.42//wp-content/themes/socdev/images/Adobe_Acrobat_PDF.png' id='docIcon' border='0'/>","<a href='".$file."'>".$fName."</a>",date ('Y-m-d', filemtime($file)),$fileSizefinal);
           //H:i:s time on date

           array_push($csvarray,$csvrowarray);

       }
   }

【讨论】:

    猜你喜欢
    • 2017-01-17
    • 2018-01-08
    • 1970-01-01
    • 2019-02-05
    • 2018-05-29
    • 1970-01-01
    • 1970-01-01
    • 2015-01-01
    • 2017-01-29
    相关资源
    最近更新 更多