0

I have an uploading the image using the camera to the server. Till now, I have succeeded in capturing the image, encoding it to base64 and then saving the String to Database.

I am aware of the fact that saving base64 encoded String into the database is not a good idea at all. It eats up space unnecessarily.

Can anyone help me in achieving the following?

  1. I want to store physical image to "http://my_website.com/images/saved_images/image_name.jpg"
  2. Please note that "image_name" will be dynamic based on the record id, which is AUTOINCREMENT.

I am able to decode the image successfully using the below code.

$imageString = "/9j/4AAQSkZJRgAB..."; // My image encoded base64 String.

$data = base64_decode($imageString);

$im = imagecreatefromstring($data);
if ($im !== false) {
    header('Content-Type: image/jpg');
    imagepng($im);
    imagedestroy($im);
}
else {
    echo 'An error occurred.';
}

How to define the target location and create the image?

0 Answers0