Reply to base64_decode

base64_decode  new!
by Steve, 5 years, 9 months ago
I have image data stored in a MySQL table encoded as base64.

How can I use this class to use that data, resize and store on my server?

So far I've gotten this far:

$data = $myBase64DataFromDb;

if (preg_match('/^data:image\/(\w+);base64,/', $data, $type)) {
  $data = substr($data, strpos($data, ',') + 1);
  $type = strtolower($type[1]); // jpg, png, gif
  $data = base64_decode($data);
  $path = '/img/put/here/';

  $filename = $data.'.'.$type;

  $handle = new upload($filename);
  $handle->file_max_size = '5000000';

  $handle->image_resize = true;
  $handle->image_x = 600;
  $handle->image_ratio_y = true; 
  $handle->process($path);
  if ($handle->processed) {
      echo $filename;
      $handle->clean();
  } else {
      echo 'error : ' . $handle->error;
  }
}
Reply

Your reply

Name *
Email 
Title *
Text *
CAPTCHA image
Enter the code displayed on the image:
Click on the image to generate another one if it is hard to read it. The case is important