链接到目录的下载\删除

0

我有上传和下载脚本。他们来了:

上载

<html>
<head>
  <title> Result </title>
</head>
<body>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
<link rel="stylesheet" href="stylesheet.css">
<div class="container">
    <?php
    $uploaddir = '/var/www/uploads/';
    $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
    echo '<pre>';


    if (!empty($_FILES) && move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
        echo "File was succesfully uploaded to ".$uploaddir;
    } else {
        echo "Something went wrong. Attach you file, please. \n";
    }


    //
    //if ($_FILES["userfile"]["size"] > 500000) {
    //    echo "Sorry, your file is too large.\n";
    //}

    $filelist = scandir($uploaddir, 1);

?>
    <p> Download your files: </p>

    <table>
        <?php foreach($filelist as $file): ?>
            <tr>
                <td> <?php echo $file; ?></td>
            </tr>
        <?php endforeach; ?>
    </table>

<?php
//debug
//   print_r ($filelist);
//   print_r($_FILES);
?>
</div>
</body>
</html>

下载

<?php 

// block any attempt to the filesystem
if (isset($_GET['file']) && basename($_GET['file']) == $_GET['file']) {
    $filename = $_GET['file'];
} else {
    $filename = NULL;
}


$error = 'Sorry, the file you are requesting is unavailable for ya.';

if (!$filename) {
// if  $filename is NULL or false display the message
    echo $error;
} else {
    $path = '/var/www/uploads/'.$filename;
    if (file_exists($path) && is_readable($path)) {
        $size = filesize($path);
        header('Content-Type: application/octet-stream');
        header('Content-Length: '.$size);
        header('Content-Disposition: attachment; filename='.$filename);
        header('Content-Transfer-Encoding: binary');
// display the error messages if the file can´t be opened
        $file = @ fopen($path, 'rb');
        if ($file) {
// stream the file and exit the script when complete
            fpassthru($file);
            exit;
        } else {
            echo $error;
        }
    } else {
        echo $error;
    }
}

现在,我只能看到我上传的文件列表。

像那样

我想为其链接,以便我可以从目录中下载和删除(使用GET和取消链接)每个文件。我认为我必须使用foreach,但仍然无法弄清楚。提前致谢。

将要

只需使其链接:

<?php foreach($filelist as $file): ?>
    <tr>
        <td>
          <a href="download.php?file=<?php echo $file; ?>"><?php echo $file; ?></a>
        </td>
    </tr>
<?php endforeach; ?>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Linux符号链接到目录

来自分类Dev

链接到bash中的目录

来自分类Dev

回声删除链接到PHP

来自分类Dev

配额不链接到用户,但链接到目录

来自分类Dev

链接到SVG生成的下载文件

来自分类Dev

直接下载链接到OneDrive文件?

来自分类Dev

如何删除目录的符号链接?

来自分类Dev

如何删除目录的软链接?

来自分类Dev

是否可以从Web目录的链接文件下载?

来自分类Dev

取消链接(删除)目录符号链接

来自分类Dev

使用“目录名”链接到脚本

来自分类Dev

符号链接到现有目录

来自分类Dev

使用“目录名”链接到脚本

来自分类Dev

PHP符号链接到子目录

来自分类Dev

Linux:如何硬链接到目录?

来自分类Dev

子域链接到子目录?

来自分类Dev

Django ImageField链接到错误的目录

来自分类Dev

如何链接到根目录中的文件

来自分类Dev

删除下载目录中的文件

来自分类Dev

.htaccess链接到不在文档根目录下的目录

来自分类Dev

将不存在的卷目录挂载/链接到目录

来自分类Dev

如何通过链接到原始目录来链接到该目录?

来自分类Dev

重定向子目录并链接到适当的链接

来自分类Dev

替换链接到目录目标的符号链接

来自分类Dev

需要隐藏符号链接而不隐藏链接到的目录

来自分类Dev

链接到错误:在删除会话中(PHOENIX)

来自分类Dev

如何下载所有链接到文本的文件?

来自分类Dev

通过引用符号链接删除目录

来自分类Dev

通过引用符号链接删除目录