php - How to show images from my database (BLOB type data)? -
this table upload
create table `upload` ( `id` int(10) unsigned not null auto_increment, `deskripsi` text, `filetype` varchar(200) default null, `filedata` longblob, `filename` varchar(200) default null, `filesize` bigint(20) default null, primary key (`id`) ) engine=myisam default charset=latin1 auto_increment=49 ;
this table article
create table `info` ( `id_info` int(10) not null auto_increment, `judul_info` varchar(50) collate latin1_general_ci not null, `konten` varchar(50000) collate latin1_general_ci not null, `diubah_oleh` varchar(20) collate latin1_general_ci not null, `id_kategori` int(10) not null, `tgl_buat` timestamp not null default '0000-00-00 00:00:00', `tgl_ubah` timestamp not null default current_timestamp on update current_timestamp, `dibuat_oleh` varchar(20) collate latin1_general_ci not null, `id` int(10) not null, primary key (`id_info`), key `id_kategori` (`id_kategori`), key `id` (`id`) ) engine=myisam default charset=latin1 collate=latin1_general_ci auto_increment=5 ;
this source code index.php
<?php include "config.php"; $query= "select upload.filetype, upload.filename, upload.filedata, info.judul_info, info.konten, info.diubah_oleh, info.id_info, info.tgl_buat, info.tgl_ubah, info.dibuat_oleh, info.id info join upload on info.id = upload.id id_info='4'"; $runquery = mysql_query($query); while($result = mysql_fetch_array($runquery)) { $id = $result['id']; echo "<img src=get_image.php?id=$id>"; ?> <div class="caption"> <?php $id_info = $result['id_info']; $judul = $result['judul_info']; $konten = $result['konten']; echo "<h3>$judul</h3>"; echo "<p>".substr($result['konten'], 0, 100)."...</p>"; echo "<a href=detail_info.php?page_detil=$id_info>selengkapnya</a><br><br>"; } ?>
and, source code get_image.php
<?php include "config.php": $id = addslashes($_request['id']); $image = mysql_query("select * upload id=$id"); $image = mysql_fetch_assoc($image); $image = $image['filedata']; header("content-type: image/jpeg"); echo $image; ?>
i want images shown article, can show title , content of article images won't showed up. can me?
first: please avoid pass user input query directly! should switch mysqli or pdo: http://code.tutsplus.com/tutorials/pdo-vs-mysqli-which-should-you-use--net-24059
to solve problem, should quote image href:
echo "<img src='get_image.php?id=$id'>";
if not help, open get_image.php in browser. image show up? if not, check query's result (just comment header line see output).
Comments
Post a Comment