Skip to content Skip to sidebar Skip to footer

How To Crop And Upload Photo Using Cropit Jquery Plugin With Php

So I currently found this photo cropping plugin called cropit . Demos are here . So what I want to do is grab the cropped photo and upload the name of the photo to the mysql databa

Solution 1:

1. Saving the base64 encoded image

<?php//save your data into a variable - last part is the base64 encoded image$encoded = "data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhE";

    //decode the url, because we want to use decoded characters to use explode$decoded = urldecode($encoded);

    //explode at ',' - the last part should be the encoded image now$exp = explode(',', $decoded);

    //we just get the last element with array_pop$base64 = array_pop($exp);

    //decode the image and finally save it$data = base64_decode($base64);
    $file = 'data.png';

    //make sure you are the owner and have the rights to write content
    file_put_contents($file, $data);

2. Getting the filename of base64 encoded image

    $encoded = "data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhE";
    $decoded = urldecode($encoded);
    $exp = explode(';', $decoded);
    $exp = explode(':', $exp[0]);
    $image = array_pop($exp);
    echo ($image);

Solution 2:

I got Hosch Nok's answer to work by not decoding the encoded data. Not calling:

$decoded = urldecode($encoded);

But working directly with the $encoded variable.

Post a Comment for "How To Crop And Upload Photo Using Cropit Jquery Plugin With Php"