Home > Backend Development > PHP Tutorial > PHP code to convert images into base64 strings

PHP code to convert images into base64 strings

WBOY
Release: 2016-07-25 08:45:41
Original
1275 people have browsed it
This code will help you learn how to convert an image into a base64 string.
  1. Image to Base64 String
  2. Image to Base64 String
  3. /**
  4. * @author vir0e5 a.k.a banditc0de
  5. * @copyright 2010 by vir0e5
  6. * @authorurl http://facebook.com/vir0e5.vbs
  7. * @Blog http://banditc0de.blogspot.com
  8. This code will help you to learn how we can convert an image into a base64 string!!
  9. */
  10. echo"

    Image

    ";
  11. //$file = File Image yang ingin di encode
  12. //Filetype: JPEG, PNG, GIF
  13. $file = "encode.jpg";
  14. if($fp = fopen($file,"rb", 0))
  15. {
  16. $gambar = fread($fp,filesize( $file));
  17. fclose($fp);
  18. $base64 = chunk_split(base64_encode($gambar));
  19. //Result
  20. $encode = '';
  21. echo $encode;
  22. }
  23. ?>

Copy code

Convert to, PHP


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template