Monday, 7 March 2016

How to Upload base64 Encoded Image in Codeigniter





$image = base64_decode($this->input->post("image_base64_string"));
// decoding base64 string value
$image_name = md5(uniqid(rand(), true));// image name generating with random number with 32 characters
$filename = $image_name . '.' . 'png';
//rename file name with random number
$path = set_realpath('product/image/');
//image uploading folder path
file_put_contents($path . $filename, $image);
// image is bind and upload to respective folder

7 comments:

  1. THNAKS A LOT ! U Just saved my project

    ReplyDelete
  2. $path = set_realpath('product/image/'); not working
    then i tried $path = 'product/image/'; now its working

    ReplyDelete
  3. Message: file_put_contents(http://localhost/ssw/upload/profile/1/577dd0c83561dcff5f23d48121786629.png): failed to open stream: HTTP wrapper does not support writeable connections

    ReplyDelete
    Replies
    1. it contains http OR https so it's not gonna work

      Delete
  4. file_put_contents(http://demo.switch2webpro.com/programming/my_circo/upload/profile/e2c6264f9b1e0a7adbb09542b3747f3e.png): failed to open stream: HTTP wrapper does not support writeable connections

    ReplyDelete
  5. $image = base64_decode(explode( ',', $your_full_base64_code )[1]);

    ReplyDelete