How to save signature in Mysql

  • Profile Image
    johnwheeler
    Asked on November 05, 2013 at 07:00 PM

    Hi,

    I am following the guide on saving my form to Mysql but am unsure as to how to save the signature which shows as

    data:image/png;base64 , is this just a blob, as it does not appear to save.

    I googled and established it as a method for being read by html.

     

  • Profile Image
    EltonCris
    Answered on November 05, 2013 at 11:57 PM

    Hi there,

    You can use the following code to convert the base64 image string into an image file.

    http://stackoverflow.com/questions/15153776/convert-base64-string-to-an-image-file

    Example:

    function base64_to_jpeg( $base64_string, $output_file ) {

        $ifp = fopen( $output_file, "wb" ); 

        fwrite( $ifp, base64_decode( $base64_string) ); 

        fclose( $ifp ); 

        return( $output_file ); 

    }

    //assign variable for your esignature post data, .e.g

    $my_base64_string = $_POST['signature4'];

    //call

    $esignature = base64_to_jpeg($my_base64_string, 'tmp.jpg' );

    There are few more scripts you can find at Google. If you require further assistance, do let us know here. Regards!

  • Profile Image
    EltonCris
    Answered on November 06, 2013 at 12:01 AM

    Here is also a good one: http://stackoverflow.com/questions/4110907/how-to-decode-a-base64-string-gif-into-image-in-php-html

    Just let us know if you help with this. Thanks!