php: image to base64

Trabla: php: image to base64

Solving:

<?php

//Path to image file
$path = "/path/to/image.jpg";

//Read image file data
$imgedata = file_get_contents(  $path );

//Convert image file data to base64
$base64 = base64_encode( $imagedata );

//Write base64 data to text file
file_put_contents(   "/path/to/text/file.txt" , $base64  );

?>



No comments:

Post a Comment