我正在编写一个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上运行它。
如果您想测试它:单击此处
谢谢!
发布于 2015-12-11 23:18:23
尝试这样的方法(警告:我还没有测试它):
<?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;
}
?>https://stackoverflow.com/questions/34233986
复制相似问题