Welcome Guest, Not a member yet? Register   Sign In
Saving image from data:img
#1

(This post was last modified: 01-19-2022, 10:49 AM by AngelRodriguez.)

Hi,

I want to save an image in the public folder "img/signatures" created with canva / js from data:image string.

Code:
PHP Code:
        $noteId 16;
        $signName 'note-' $noteId '.png';
        $signature ='data:image/png;base64,iV...gg==';

        $data base64_decode(preg_replace('#^data:image/\w+;base64,#i'''$signature));
        file_put_contents(base_url('img/signatures/'$signName), $data); 

I get this error:

PHP Code:
ErrorException
file_put_contents
(http://web.local/img/signatures/note-16.png): failed to open stream: HTTP wrapper does not support writeable connections 

How to solve this? 

Thank you
Reply
#2

In your controller,
PHP Code:
$data $this->input->post('image'); //or  $_POST["image"];

 
$image_array_1 explode(";"$data);
 
$image_array_2 explode(","$image_array_1[1]);
 
$data base64_decode($image_array_2[1]); 

then you can use your $data and save it in such a scenario :

Code:
$imageName = $new_name.'-'.time().'.png';

$user_folder = 'upload/accounts/user-id-'. $user_id;
if(!is_dir($user_folder)){
mkdir($user_folder, 0777);
}

$result = file_put_contents($user_folder.'/'.$imageName, $data);


 


Reply




Theme © iAndrew 2016 - Forum software by © MyBB