Anvar Pk
Anvar Pk

Reputation: 122

convert base64 data to image and save in codeIgniter folder

i want to convert data url to image and save it in codeigniter folder

 private function _convertToImg($data){ //$data is the data url
        $encodedData = str_replace(' ','+',$data);

        $decodedData = base64_decode($encodedData);
   file_put_contents('/../../uploads/newImage.JPG',$decoded);
}

but it resulting an error

Message: file_put_contents(/../../uploads/newImage.JPG): failed to open stream: No such file or directory

i dont know why this happening, i am not much familiar with php and codeigniter

thank you in advance!

Upvotes: 2

Views: 10740

Answers (1)

Ravi Hirani
Ravi Hirani

Reputation: 6539

If application and upload folder in same directory then,

You should write below line as:-

// APPPATH will give you application folder path
file_put_contents(APPPATH . '../uploads/newImage.JPG',$decoded);

You can also set upload path,

$this->upload_config['upload_path'] = APPPATH . '../uploads/';

get full information write below lines

 $data = $this->upload->data();
 // $data will contain full inforation
 echo "Full path is:". $data['full_path'];

This link will be useful to you.

Hope it will help you :)

Upvotes: 4

Related Questions