Php 从特定文件夹中的所有文件制作下载链接
目前,我正在开发的网站上有一个上传系统,用户可以将一些文档上传到特定的文件中。稍后,我将需要使这些文件可下载。有没有一种简单的方法可以遍历特定目录中的所有文件并为这些文件创建下载链接 比如:Php 从特定文件夹中的所有文件制作下载链接,php,javascript,jquery,Php,Javascript,Jquery,目前,我正在开发的网站上有一个上传系统,用户可以将一些文档上传到特定的文件中。稍后,我将需要使这些文件可下载。有没有一种简单的方法可以遍历特定目录中的所有文件并为这些文件创建下载链接 比如: foreach($file){ echo '<a href=""'somepath/'.$file.'">somefilename</a>'; } foreach($file){ 回声'; } 非常感谢。if($dh=opendir('path/to/directory')
foreach($file){
echo '<a href=""'somepath/'.$file.'">somefilename</a>';
}
foreach($file){
回声';
}
非常感谢。if($dh=opendir('path/to/directory')){
if($dh = opendir('path/to/directory')) {
while(($file = readdir($dh)) !== false) {
if($file == "." || $file == "..") { continue; }
echo '<a href="path/to/directory/' . $file . '">' . $file . '</a>';
}
closedir($dh);
}
while(($file=readdir($dh))!==false){
如果($file==“| |$file==”。”{continue;}
回声';
}
closedir($dh);
}
您应该看到
该页中的示例适用于以下问题:
$dir = "/etc/php5/";
$path = "/webpath";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo "<a href=\"$webpath/$file\">$file</a>";
}
closedir($dh);
}
}
$dir=“/etc/php5/”;
$path=“/webpath”;
//打开已知目录,然后继续读取其内容
if(is_dir($dir)){
如果($dh=opendir($dir)){
while(($file=readdir($dh))!==false){
回声“;
}
closedir($dh);
}
}
+1,正是我想要的,非常感谢您,清晰而有用的示例!