繁体   English   中英

如何列出驱动器 D 中的所有文件和文件夹目录并使用 php 下载

[英]how to list all file and folder directory from drive D and download it using php

这里我的代码如何访问本地文件夹,例如 driveD-->folder->.pdf 文件并在单击除文件夹时下载文件

<?php




$path    = './';
$files = scandir($path);
$files = array_diff(scandir($path), array('.', '..'));
foreach($files as $file){
  echo "<a href='$file'>$file</a>"."<br>";
}




 ?>

这不太安全,无法直接从驱动器 D 下载。

正确的方法是将id分配给数据库表files中的每个文件,以便知道每个文件的path 然后下载一些download.php?id=123文件来进行实际下载。

有关解决方案的草图,请在此处查看我最近的另一个答案。

简而言之:创建一个像这样的“download.php”文件:

$id = $_REQUEST["id"];

// according to id get from database:
$file = '../image.jpg';   

// then download
header('Content-Type: ' . mime_content_type($file));
readfile($file);

并通过

<img src="download.php?id=123">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM