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
  • 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
  • 6,311
  • 1
  • 23
  • 41
  • 1
    but now seems an error ,Message: file_put_contents(/var/www/html/portfolioApis/application/../uploads/newImage.JPG): failed to open stream: Permission denied – Anvar Pk Feb 03 '16 at 07:07
  • 2
    Give permission to your upload folder. – Ravi Feb 03 '16 at 08:39
  • 1
    http://stackoverflow.com/questions/30570987/codeigniter-failed-to-open-stream-permission-when-upload-images – Anvar Pk Feb 03 '16 at 08:49