フォームにダウンロードリンクを作成して、アップロードフォルダーにファイルをダウンロードできるようにしようとしています。以下のコードを使用しています
<?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");
}
そして、フォームにダウンロードリンクを入れてテストします
<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>
その4つのダウンロードリンクから。最初の 1 つは、そのファイルが存在しないためにわかっている「無効な要求」を返します。2 番目のリンクは、空のファイルをダウンロードするためのダウンロード ボックスをポップアップ表示します。それは本当に空だからです。3 番目と 4 番目のリンクでは、そのファイルは実際にはフォルダーに存在しますが、返されます
内部サーバーエラー
サーバーで内部エラーまたは構成ミスが発生したため、リクエストを完了できませんでした。
サーバー管理者 webmaster@miitresearch-post Graduates.com に連絡して、エラーが発生した時刻と、エラーの原因となった可能性のある操作を知らせてください。
このエラーの詳細については、サーバー エラー ログを参照してください。
さらに、ErrorDocument を使用して要求を処理しようとしたときに、404 Not Found エラーが発生しました。
何が問題なのですか?TQ :)