HOW TO SAVE IMAGE FILE (.jpeg,.gif dll) TO SQL SERVER
slm,nak mintak sifu2 kat sini pesal menda nih.
Task terbaru, bos ali soh ali simpan plak imej(jpeg,gif dll) ke dlm server sql.
kita org guna php sebagai bahasa pengaturcaraan.
lepas dah simpan, kena panggil dalam template word plak (.doc)..
ada sesapa pernah buat tak?
thanks haku penah buat system save images into Oracle db( save as blob ) ..
tapi pastu db jadik slow coz banyak sangat space allocated utk the images..
so kitorang remove the image from db and save dlm directory dlm webserver instead ....
time ni kitorang pakai asp.net ... tuh lah sy pun rs db akan jd slow kalau nak access. Post Last Edit by FMKiller at 15-6-2010 17:39
try encode image tuh jadik base 64, then simpan dalam database.
<?php
// function to encode the image
// returns the image as base64 encoded string
function encode_img($img)
{
$fd = fopen ($img, 'rb');
$size=filesize ($img);
$cont = fread ($fd, $size);
fclose ($fd);
$encimg = base64_encode($cont);
return $encimg;
}
// use this to split the code into managable pieces
// if you want to save the string to a file
$imgcode = chunk_split($encimg,20,'\'.
\'');
// function to display the image
function display_img($imgcode,$type)
{
header('Content-type: image/'.$type);
header('Content-length: '.size($imgcode));
echo base64_decode($imgcode);
}
// use like
encode_img('path/to/image.gif'); // to encode the image
display_img($imgcode,'gif'); // to show the image
?>
aku amek kat sini: http://fundisom.com/phparadise/p ... base64_image_encode try encode image tuh jadik base 64, then simpan dalam database.
aku amek kat sini:
FMKiller Post at 15-6-2010 17:37 http://mforum.cari.com.my/images/common/back.gif
thanks 4 da tips. apasal tak simpan je filename kat db, bila nak download, link kan balik je, sebab kalau simpan dlm db, db jadi besar..... mungkin sebab memang matlamat nak membagakkn db kot.. :L
Pages:
[1]