CARI Infonet

 Forgot password?
 Register

ADVERTISEMENT

View: 3044|Reply: 6

HOW TO SAVE IMAGE FILE (.jpeg,.gif dll) TO SQL SERVER

[Copy link]
Post time 15-6-2010 12:10 PM | Show all posts |Read mode
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
Reply

Use magic Report


ADVERTISEMENT


Post time 15-6-2010 02:06 PM | Show all posts
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 ...
Reply

Use magic Report

 Author| Post time 15-6-2010 03:22 PM | Show all posts
tuh lah sy pun rs db akan jd slow kalau nak access.
Reply

Use magic Report

Post time 15-6-2010 05:37 PM | Show all posts
Post Last Edit by FMKiller at 15-6-2010 17:39

try encode image tuh jadik base 64, then simpan dalam database.

  1. <?php
  2. // function to encode the image
  3. // returns the image as base64 encoded string
  4. function encode_img($img)
  5. {
  6.     $fd = fopen ($img, 'rb');
  7.     $size=filesize ($img);
  8.     $cont = fread ($fd, $size);
  9.     fclose ($fd);
  10.     $encimg = base64_encode($cont);
  11.     return $encimg;
  12. }

  13. // use this to split the code into managable pieces
  14. // if you want to save the string to a file
  15. $imgcode = chunk_split($encimg,20,'\'.
  16. \'');
  17.   
  18. // function to display the image
  19. function display_img($imgcode,$type)
  20. {
  21.     header('Content-type: image/'.$type);
  22.     header('Content-length: '.size($imgcode));
  23.     echo base64_decode($imgcode);
  24. }

  25. // use like
  26. encode_img('path/to/image.gif'); // to encode the image
  27. display_img($imgcode,'gif'); // to show the image
  28.   
  29. ?>
Copy the Code



aku amek kat sini: http://fundisom.com/phparadise/p ... base64_image_encode
Reply

Use magic Report

Post time 17-6-2010 07:16 AM | Show all posts
try encode image tuh jadik base 64, then simpan dalam database.




aku amek kat sini:
FMKiller Post at 15-6-2010 17:37



    thanks 4 da tips.
Reply

Use magic Report

Post time 20-6-2010 10:38 PM | Show all posts
apasal tak simpan je filename kat db, bila nak download, link kan balik je, sebab kalau simpan dlm db, db jadi besar.....
Reply

Use magic Report

Follow Us
Post time 21-6-2010 11:51 AM | Show all posts
mungkin sebab memang matlamat nak membagakkn db kot..
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT


Forum Hot Topic

 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CARI Infonet

5-5-2024 10:54 AM GMT+8 , Processed in 0.057744 second(s), 33 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list