title: How to save captured image inside folder using codeigniter (image captured by javascript code)?
body: <p>Hi everyone I had written code to capture image of div tag when click on button and javascript code will capture that image ,but i want to save that captured image using codeigniter but we can't using default codeigniter upload method because upload only work for input type file which create one object but here getting captured image by javascript so i want to upload that image in folder so please tell me how to do that using codeigniter.below  i mentioned my code.</p>
  
  <pre><code>Html code....
  &lt;div id="target" style="border: 1px solid #CCC;padding: 5px;margin: 5px;"&gt;
      &lt;div&gt;
          &lt;p&gt;PHP is a server-side scripting language designed primarily for web development.&lt;/p&gt;
      &lt;/div&gt;
  &lt;/div&gt;
   &lt;form method="POST" enctype="multipart/form-data" id="form1"&gt;
          &lt;input type="hidden" name="img_value" id="img_value" value="" /&gt;
      &lt;/form&gt;
  &lt;input type="submit" value="Screenshot" onclick="capture();" /&gt;
  </code></pre>
  
  <p>javascript code to captured image and call ajax to save image</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          function capture() {
              $('#target').html2canvas({
                  onrendered: function (canvas) {
                      //Set hidden field's value to image data
                      $('#img_value').val(canvas.toDataURL("image/png"));
                      //Submit the form1
                      var hid_img=$("#img_value").val();
                      $.ajax({
                          url: "&lt;?= base_url('controller/save_img') ?&gt;",
                          type: "POST",
                          data: {
                              hid_img: hid_img,
                          },
                          success: function (response) {
  
                              $(".show_img").html(response);
  
                          }
                      });
                  }
              });
          }
      &lt;/script&gt;
  </code></pre>
  
  <p>code in controller method of codeigniter to save image in folder...</p>
  
  <pre><code>public function save_img() {
  
  $data = $this-&gt;input-&gt;post($hid_img);
      $file = md5(uniqid()) . '.png';
  
      // remove "data:image/png;base64,"
      $uri =  substr($data,strpos($data,",")+1);
  
      // save to file in uploads folder of codeigniter
      file_put_contents('./uploads'.$file, base64_decode($uri));
  
  }
  to store image in table
  $res=$this-&gt;db-&gt;insert('demo',array('img'=&gt;base_url('uploads/').$file));
      $detail = $this-&gt;db-&gt;select('*')-&gt;from('demo')-&gt;where('id', $this-&gt;db-&gt;insert_id())-&gt;get()-&gt;row();
      echo '&lt;img src="'.base_url('uploads/').$detail-&gt;message.'" style="width:500px;"/&gt;';
  </code></pre>