2

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!

Anvar Pk
  • 122
  • 1
  • 3
  • 18

1 Answers1

4

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 :)

Ravi Hirani
  • 6,511
  • 1
  • 27
  • 42