$ _SESSIONに投稿し、その後$_SESSIONデータからpdfを生成する非常に単純なphpフォームを作成しました。私はPDFを生成するためにfpdfを使用しています。fpdfを介して何かを出力する前に、アップロードされたファイル$ _SESSIONがnullかどうかを確認したい(出力を変更したいため)
すべてが想定どおりに機能しますが、セッションがnullの場合に$_SESSIONデータが上書きされる理由は本当に混乱しています。
if(isset($_SESSION['attachments']) && !empty($_SESSION['attachments'])) {
$attachments = $_SESSION['attachments'];
}
else {
$attachments = "No attachments";
}
現在、$ _ SESSION ['attachments']には添付ファイルのシリアル化されたパスが含まれていますが、添付ファイルがアップロードされていない場合はnullになります。このif句がSESSIONを初期化して上書きする理由は、次のとおりです。
var_dump($_SESSION['attachments']);
出力:
string 'No attachments' (length=14)
私がしていることを示すためにfpdfスクリプトを削除しました:
<?php
require('fpdf.php');
if(!isset($_SESSION)){
session_start();
}
//Lot of other checking
if(isset($_SESSION['attachments']) && !empty($_SESSION['attachments'])) {
$attachments = $_SESSION['attachments'];
}
else {
$attachments = "No attachments";
}
//a lot of fpdf functions. AddMultiRow is my own function
$pdf = new PDF();
$pdf->AddPage();
$pdf->AddMultiRow(utf8_decode("Required attachments:"), $attachments, 1);
$pdf->Output(//output comes here);
?>