Last active
April 16, 2016 15:02
-
-
Save divinity76/06f3e97ae926fbe1d2136af0a218a8d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//untested code, and i dont really use ?>. | |
CreateDatabase.php: | |
<?php | |
$db=new PDO('sqlite:imagedb.sqlite3','','',array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION)); | |
$db->exec(' | |
-- DROP TABLE IF EXISTS image; | |
CREATE TABLE images( id INTEGER AUTO_INCREMENT PRIMARY KEY,filename VARCHAR(255),rawdata BLOB); | |
'); | |
//change this with your mysql or whatever | |
?> | |
uploadImage.php: | |
<?php | |
$db=new PDO('sqlite:imagedb.sqlite3','','',array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION)); | |
$filename="test.jpg"; | |
$rawdata=file_get_contents($filename); | |
$stm=$db->prepare("INSERT INTO `images` (filename,rawdata) VALUES(:filename,:rawdata);"); | |
$stm->bindValue(":filename",$filename); | |
$stm->bindValue(":rawdata",$rawdata); | |
$stm->execute(); | |
?> | |
displayImage.php: | |
<?php | |
$db=new PDO('sqlite:imagedb.sqlite3','','',array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION)); | |
header("content-type: image/jpg"); | |
$res=$db->query("SELECT `rawdata` FROM `images` LIMIT 1")->fetch(PDO::FETCH_ASSOC); | |
echo $res['rawdata']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment