php - PHP Downloader无法下载?

标签 php html error-handling

我正在使用php下载器,但工作了一会儿却没有。

我把我的代码放在多个错误检查器中,都没有结果。

我的代码:

    <html>
     <title>Downloading...</title>
     <!-- Latest compiled and minified CSS -->
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

     <!-- Optional theme -->
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">

     <div class="alert alert-success" role="alert">Cosmic Downloads By Cosmic Web Services</div>
     <div class="jumbotron">
      <h1>Your File Is Downloading...</h1>
      <br>
      <div class="progress">

       <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">

    <span class="sr-only">45% Complete</span>
   </div>
   </div>
    </div>

   </html>

    <?php
    $fullPath = $_GET['url'];
    if($fullPath) {
    $fsize = filesize($fullPath);
    $path_parts = pathinfo($fullPath);
       $ext = strtolower($path_parts["extension"]);
       switch ($ext) {
        case "pdf":
        header("Content-Disposition: attachment; "); // use 'attachment' to force a download
        header("Content-Type: text/plain");
        header("Content-type:application/octet-stream");
        header("Content-type:application/zip");
        header("Content-type:application/msword");
        header("Content-type:application/vnd.ms-excel");
        header("Content-type:application/vnd.ms-powerpoint");
        header("Content-type:image/gif");
        header("Content-type:image/png");
        header("Content-type:image/jpeg");
        header("Content-type:image/jpg");
        header("Content-type:image/ico");
        header("Content-type: application/pdf"); // add here more headers for diff. extensions
        break;
        default;
        header("Content-type: application/octet-stream");
        header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
    }
    if($fsize) {//checking if file size exist
      header("Content-length: $fsize");
    }
    readfile($fullPath);
    exit;
    }
    ?>

The page

我正在Chromebook上运行它。

如果要测试:click here

谢谢!

最佳答案

尝试这样的事情(警告:我没有测试过):

<?php
$fullPath = $_GET['url'];
if($fullPath) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
    case "pdf":
    header("Content-type: application/pdf"); // add here more headers for diff. extensions
    header('Content-Disposition: attachment; filename="'.basename($fullPath).'"');
    break;
    default:
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'.basename($fullPath).'"');
}
if($fsize) {//checking if file size exist
  header("Content-length: $fsize");
}
readfile($fullPath);
exit;
}
?>

关于php - PHP Downloader无法下载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34233986/

相关文章:

PHP mySQL 不允许我插入到表中

php - 数据库更新需要FROM子句,但是FROM子句导致错误

javascript - 识别没有id的div

c# - 是什么原因导致 “assertion failed: abort=quit, retry=debug, ignore=continue”弹出窗口?

error-handling - Python : If error occurs anywhere, do specific line of code

php - 使用PHP将值添加到MySQL数据库不起作用?

php - 如何使用 AJAX 从复选框获取值并传递到 PHP 页面

swift - “ fatal error :在展开可选值时意外发现nil”是什么意思?

javascript - Gulp:使用多个 PHP 文件

java - 如何使用 Java 获取 html 文本区域的值(给定其 id/名称)?