I just want to ask if there is a way to upload an image from src
of <img>
tag . The src
of the img
tag was not from the server and look like this one:
<img src="data:image/png;base64,iVBOR...52Eysdsadsa===" />
This was the product of the approach I learned from this site.
Thank you in advance.
Let me know if you want me to explaine this dipper. Thank you
You can upload base64 encoded string(src part) to the server and save it as it is or convert it into an image and save it as a file.
Uploading base64 encoded image:
Get the src attribute of the image and post it to the server.
var base64image = $('#blah').attr('src');
Converting base64 encoded string to image
$img = $_POST['base64image'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = 'image.png';
$success = file_put_contents($file, $data);
Or simply save the uploaded content into your database and later use the below code to render the image on your page:
echo '<img src="'. $img .'" />';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With