Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created April 21, 2021 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeforfun-jp/681c3f8f0f145b6c6a0e869002efdf1b to your computer and use it in GitHub Desktop.
Save codeforfun-jp/681c3f8f0f145b6c6a0e869002efdf1b to your computer and use it in GitHub Desktop.
Save Image File with PHP & MySQL - #4
<?php
require_once 'functions.php';
$pdo = connectDB();
$sql = 'SELECT * FROM images WHERE image_id = :image_id LIMIT 1';
$stmt = $pdo->prepare($sql);
$stmt->bindValue(':image_id', (int)$_GET['id'], PDO::PARAM_INT);
$stmt->execute();
$image = $stmt->fetch();
header('Content-type: ' . $image['image_type']);
echo $image['image_content'];
exit();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment