【问题标题】:opendir not reading full file nameopendir 没有读取完整的文件名
【发布时间】:2014-05-27 14:08:22
【问题描述】:

我想在 php 中打开一个目录,然后显示下载该文件的链接。

这就是我正在尝试的。

if(is_dir($dir))
{
  $op=opendir($dir);
  echo"Files in the directiry are<br>";

   while(($file=readdir($op))!==false)
   {
    if(strpos($file,$ext,1))
   {
      echo "<a href=apps/".$file .">".$file."</a><br>";
    }  
  }
}

这显示下载链接,但仅显示空间。

【问题讨论】:

    标签: php opendir


    【解决方案1】:

    PHP 函数rawurlencode 显然为您提供了更好的系统覆盖率。 urlencode 实际上在我的本地主机上不起作用。

    <?php
    
    $dir = 'apps';
    $ext = 'pdf';
    
    if(is_dir($dir))
    {
      $op=opendir($dir);
      echo"Files in the directory are<br>";
    
       while(($file=readdir($op))!==false)
       {
        if(strpos($file,$ext,1))
       {
          echo '<a href="apps/' . rawurlencode($file) . '">' . $file . '</a><br>';
        }  
      }
    }
    
    ?>
    

    这里有更多关于这个主题的信息:urlencode vs rawurlencode?

    【讨论】:

      猜你喜欢
      • 2019-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-15
      • 2011-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多