最終目標:1ページのリンクをクリックして、ファイルをダウンロードし、ページ1を更新します。PHPを使用して、パブリックhtmlにないダウンロードを提供します。
アプローチ:
ページ1。 リンクはページ2に移動し、使用しているファイルの変数参照を取得します。
ページ2。 ページ1を更新する前に更新する必要がある情報で関連するSQLデータベースを更新します。「firstpass」セッション変数を設定します。get変数からセッション変数「getvariablereference」を設定します。1ページにリダイレクトします。
ページ1。 初回通過セッション変数が設定されている場合。セカンドパスセッション変数を設定します。初回通過変数の設定を解除します。ページの更新。リロード時に、更新されたSQLデータベース情報(2ページで変更)を使用してページが再構築されます。
ページ1を更新 しました。2回目のパスセッション変数が設定されている場合。ダウンロードサービングヘッダーシーケンスを実行します。
これはページ1です。最初のリンクがあるページ1の部分は表示していません。関係ないので。
// REFERSH IF FIRSTPASS IS LIVE
if ($_SESSION["PASS1"] == "YES"){
$_SESSION["PASS1"] = "no";
$_SESSION["PASS2"] = "YES";
echo "<script>document.location.reload();</script>";
}
if ($_SESSION["PASS2"] == "YES"){
// Grab reference data from session:
$id = $_SESSION['passreference'];
// Serve the file download
//First find the file location
$query = "SELECT * from rightplace
WHERE id = '$id'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$filename = $row['file'];
$uploader = $row['uploader'];
// Setting up download variables
$string1 = "/home/domain/aboveroot/";
$string2 = $uploader;
$string3 = '/';
$string4 = $filename;
$file= $string1.$string2.$string3.$string4;
$ext = strtolower (end(explode('.', $filename)));
//Finding MIME type
if($ext == "pdf" && file_exists($file)) {
header("Content-disposition: attachment; filename= '$filename'");
header('Content-type: application/pdf');
readfile($file);
}
if($ext == "doc" && file_exists($file)) {
header("Content-disposition: attachment; filename= '$filename'");
header('Content-type: application/msword');
readfile($file);
}
if($ext == "txt" && file_exists($file)) {
header("Content-disposition: attachment; filename= '$filename'");
header('Content-type: text/plain');
readfile($file);
}
if($ext == "rtf" && file_exists($file)) {
header("Content-disposition: attachment; filename= '$filename'");
header('Content-type: application/rtf');
readfile($file);
}
if($ext == "docx" && file_exists($file)) {
header("Content-disposition: attachment; filename= '$filename'");
header('Content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
readfile($file);
}
if($ext == "pptx" && file_exists($file)) {
header("Content-disposition: attachment; filename= '$filename'");
header('Content-type: application/vnd.openxmlformats-officedocument.presentationml.presentation');
readfile($file);
}
if($ext == "ppt" && file_exists($file)) {
header("Content-disposition: attachment; filename= '$filename'");
header('Content-type: application/vnd.ms-powerpoint');
readfile($file);
}
}
2ページのスクリプトは正しく機能しています。SQLデータベースを更新し、メインページに適切にリダイレクトします。また、「$ _SESSION['passreference'];」が設定されていることも確認しました。正しく、1ページの何もそれを設定解除しません。
だから、それは状況の全体の長い説明です。私は困惑しています。何が起こるかというと、私が言ったように、2ページはうまく機能します。次に、ページ1に移動し、更新してからダウンロードをプッシュしません。ダウンロードスクリプトが機能し、ファイルがダウンロードされることを知っています(更新シーケンス全体なしでチェックされます)。
基本的に2つの質問があります。
誰かが何がうまくいかないのかを見つけることができますか?
誰かがより良いアプローチを概念化できますか?