我正在开发一个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;
}
?>
我在chromebook上运行它。
如果您想测试一下:click here
谢谢!
答案 0 :(得分:2)
尝试这样的事情(警告:我还没有测试过它):
<?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;
}
?>