dongziya9863 2016-01-07 13:00
浏览 39

如何列出目录中可通过点击下载的文件?

I need the PHP code to list files in a directory. I have seen the code here and it works well. But what I need is the code should not only list the file also they should be able to be downloadable when user clicks on the file. The files are all text files.

Here is the code I found and works well for listing the files:

<?php

$username = Am_Lite::getInstance()->getUsername();

$directory = $username."/";

//get all text files with a .txt extension.
$texts = glob($directory . "*.txt");

//print each file name
foreach($texts as $text)
{
    echo $text;
}

?>
  • 写回答

1条回答 默认 最新

  • doujiong2533 2016-01-07 17:27
    关注

    Ok got it thanks.Actually it was much more simple than i thought.But still instead of downloading the file it opens the txt file on Chrome.Anyone got any idea why this happens? Thanks

    echo "<a href='$text'>$text</a><br />";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思