douping4436 2013-03-07 02:28
浏览 35

php下载链接返回内部服务器错误

i'm try to create download link in my form so people can download the files in the upload folder.I'm used code below

<?php

$path = $_SERVER['DOCUMENT_ROOT']."/content/uploads/"; // change the path to fit your     websites document structure
$fullPath = $path.basename($_REQUEST['download_file']);

if (is_readable ($fullPath)) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
    case "pdf"||"docx"||"doc"||"jpg"||"jpeg":
    header(("Content-type: lappication/pdf")||("Content-type: application/msword")||("Content-type: image/jpeg")); // add here more headers for diff.     extensions
    header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");     // use 'attachment' to force a download
    break;
    default;
    header("Content-type: application/octet-stream");
    header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
}
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
readfile($fullPath);
exit;
} else {
        die("Invalid request");
}

and then i test by put download link in my form

<h2>Forms Available</h2>

<a href="content/grants/download.php?download_file=some.pdf">Download here</a>
<a href="content/grants/download.php?download_file=">Download here</a>
<a href="content/grants/download.php?download_file=IntroLetter.docx">Download here</a>
<a href="content/grants/download.php?download_file=Conference Grant Application Form.doc">Download here</a>

from that 4 download link. the first 1 return "invalid request" which i know because that file doesn't exist. second link pop up download box to download empty file. which i bet because it really empty. for third and fourth link that file really exist in the folder but it return

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@miitresearch-postgraduates.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request

what could be the problem? TQ :)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探