-2

Hello: I have a web form that submits data to my db. I am able to create a signature image and save it within my directory. I want to save/store that signature image in my mysql db along with the record so I can call it later.

Written in CodeIgniter 2.0

here are my model and controller.

public function sig_to_img()
        {
            if($_POST){
                require_once APPPATH.'signature-to-image.php';
                 $json = $_POST['output'];

                $img = sigJsonToImage($json);

            imagepng($img, 'signature.png');

            imagedestroy($img);

            $form = $this->input->post();
            var_dump($form);

               $this->coapp_mdl->insert_signature($form);
            }
        }

public function insert_signature($data)
        {
          $sig_hash = sha1($data['output']);
          $created = time();
          $ip = $_SERVER['REMOTE_ADDR'];

          $data = array(
            'first_name' => $data['fname'],
            'last_name' => $data['lname'],
              'signator' => $data['name'],
              'signature' => $data['output'],
              'sig_hash' => $sig_hash,
              'ip' => $ip,
              'created' => $created
          );

            return $this->db->insert('signatures', $data);
        }

I found the function below on php.net but apparently I am doing something wrong or various things wrong. Does anyone know how to accomplish this functionality?

$imagefile = "changethistogourimage.gif";

$image = imagecreatefromgif($imagefile);
ob_start();
imagepng($image);
$imagevariable = ob_get_contents();
ob_end_clean();
user1176783
  • 673
  • 4
  • 19
  • 39

1 Answers1

0

Got it - For those curious here are the changes to my controller:

public function sig_to_img()
        {
            if($_POST){
                require_once APPPATH.'signature-to-image.php';
                 $json = $_POST['output'];

                $img = sigJsonToImage($json);

// Save to file
            $file_name = trim(str_replace(" ","_",$_POST['name']));//name to used for filename
            imagepng($img, APPPATH."../images/signatures/".$file_name.'.png');
            $sig_name = $file_name.'.png'; //pass to model

// Destroy the image in memory when complete
            imagedestroy($img);

            $form = $this->input->post();
            var_dump($form);         
            $this->coapp_mdl->insert_signature($form, $sig_name);
            }

        }
user1176783
  • 673
  • 4
  • 19
  • 39