首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP下载器没有下载吗?

PHP下载器没有下载吗?
EN

Stack Overflow用户
提问于 2015-12-11 23:03:27
回答 1查看 84关注 0票数 1

我正在编写一个php下载程序,它工作了一会儿,但它没有工作。

我把我的代码放在多个错误检查程序中,所有这些都没有结果。

我的守则:

代码语言:javascript
复制
    <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;
    }
    ?>

我在chromebook上运行它。

如果您想测试它:单击此处

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-11 23:18:23

尝试这样的方法(警告:我还没有测试它):

代码语言:javascript
复制
<?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;
}
?>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34233986

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档