Postingan lainnya
menampilkan gabar menggunakan codeigniter
public function render($name)
{
$q = $this->db->select('filename')->from('gambar_produk')->where('filename',$name)->get()->row();
$file = $q->filename;
$gambar= base_url('gambar_produk/'.$file);
if($q == ""){
return array('errorCode' => 401,'userMessage' => 'Filename Not found');
} else {
return array('errorCode' => 200,'userMessage' => $gambar);
}
}
bagaimana cara menampilkan gambar dari link yang ada pada variabel gambar, jadi jika errorcode 200 menampilkan gambar?????????????????????????
2 Jawaban:
agan @abdulrojakUG coba dicek aturan mainnya ya https://sekolahkoding.com/forum/aturan-main 1. kode agan bisa dirapikan dengan masukin di tag kode, agar terhighlight 2. kurang detail agan mau nampilin dimana? diatas cuma kode fungsinya yang ada. Kalo mau nampilin dari variable langsung bisa
<img href="<?=$gambar?>">
Controller
public function render()
{
$method = $_SERVER['REQUEST_METHOD'];
if($method != 'GET'){
$jsonAr = array(
"_meta" => array('status' => 'ERROR','count' => 1),
"result" => array('errorCode' => 400,'userMessage' => 'Bad request')
);
json_output(400,$jsonAr);
} else {
$this->load->model('m_gambar_produk');
$name = $this->input->get('filename');
$response = $this->m_gambar_produk->render($name);
if ($response['errorCode'] == 200) {
$stat = "SUCCESS";
} else {
$stat = "ERROR";
}
$count = array($response);
if ($response['errorCode'] == 200) {
$result = array($response);
} else {
$result = $response;
}
$jsonAr = array(
"_meta" => array('status' => $stat,'count' => count($count)),
"result" => $result
);
json_output($response['errorCode'],$jsonAr);
}
}
Model
public function render($name)
{
$q = $this->db->select('filename')->from('gambar_produk')->where('filename',$name)->get()->row();
$file = $q->filename;
$gambar= base_url('gambar_produk/'.$file);
if($q == ""){
return array('errorCode' => 401,'userMessage' => 'Filename Not found');
} else {
return array('errorCode' => 200,'userMessage' => $gambar);
}
}
pertanyaanya ketika saya mau akses variabel $gambar atau http://localhost/rest_server/gambar_produk/render?filename=e5ce7e-f4a36d-ccbe71-47d3e2-ad4664-d3.jpg muncul gambar sesuai filename yang di input bagaimana ya?????