コードを使用して添付ファイル データをシリアル化することにより、データベースに複数の添付ファイルを 1 つの列に保存しました。
$files = array(
'file1' => base64_encode(file_get_contents('back.jpg')),
'file2' => base64_encode(file_get_contents('email.jpg')),
'file3' => base64_encode(file_get_contents('web.jpg')),
);
// serialize
$filesData = serialize($files);
今、別のphpページで、ダウンロードするファイルを取得しています。その中で、上記のファイルデータをシリアル化解除し、データベース列「データ」から取得しています
次のコードを使用してデータを非シリアル化しますが、データは非シリアル化されていないようです.3つの写真を保存しました.それらを取得すると.txtファイルがダウンロードされ、そこに「配列」と書かれています.
if($result->num_rows == 1) {
$row = mysqli_fetch_assoc($result);
// Print headers
header("Content-Type: ". $row['mime']);
header("Content-Length: ". $row['size']);
header("Content-Disposition: attachment; filename=". $row['name']);
$files = unserialize($row['data']);
echo $files;
}