weixin_33725239 2015-08-22 04:01 采纳率: 0%
浏览 19

使用Codeigniter保存画布

I created HTML5 Canvas Drawing App using this video tutorial series.Now I want to save it as an image in database using codeigniter.Also I want to allow user to enter name for that image before saving it in database.I'm new to codeigniter.Can anyone help me with this.Here what I have done so far

html code .......................

<div class="col-lg-3">
      <div id="toolbar">    
          <div id="rad">
              Radius <span id="radval">10</span>
                  <div id="decrad" class="radcontrol">-</div>
                  <div id="incrad" class="radcontrol">+</div>
                  <div id="colors"></div>
                  <div id="save">Save</div>
          </div>
      </div>
          <canvas id="canvas"></canvas>
</div>

javascript code for saving .....................................

var saveButton=document.getElementById('save');
    saveButton.addEventListener('click',saveImage);
    function saveImage(){
        var data=canvas.toDataURL();
        var request=new XMLHttpRequest();

        request.onreadystatechange=function(){
            if(request.readyState==4&& request.status==200){
               var response= request.responseText;
                console.log(response);
            }
        }

        request.open('POST','http://localhost/cafdc/MainController/save',true);
        request.setRequestHeader('Content-type','application/x-www-form-urlencoded');
        request.send('img='+data);
    }
  • 写回答

1条回答 默认 最新

  • weixin_33696106 2015-08-22 04:16
    关注

    CodeIgniter has some built in library for image manupilation like cropping,resizing etc.You have save image in name or it's path in database not image has to be saved in database it's not prefered and is bad pratice.

    In order to work in CI you have to create controller like this

    <?php
    if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    ini_set("display_errors",1);
    
    
    
        class Image_upload extends CI_Controller {
    
    function __construct()
         {
              // Call the Model constructor
              parent::__construct();
              $this->load->helper(array('form', 'url'));
              $this->load->model('your_model');
    
    
    
         }
    
    
    public  function index() {
    
            $this->load->view('header');
            $this->load->view('your_view');
    
        }// index function ends
    
    function doupload() {
    
    //set preferences
            $config['remove_spaces']=TRUE;
            $config['encrypt_name'] = TRUE; // for encrypting the name
            $config['upload_path'] = LARGEPATH;
            $config['allowed_types'] = 'jpg|png|gif';
            $config['max_size']    = '78000';
    
    //load upload class library
            $this->load->library('upload', $config);
    
            //$this->upload->do_upload('filename') will upload selected file to destiny folder
            if (!$this->upload->do_upload('filename'))
            {
                // case - failure
                $upload_error = array('error' => $this->upload->display_errors());
                $this->load->view('some_view', $upload_error);
            }
            else
            {
                // case - success
            }
    

    //model

        class Your_Model extends CI_Model {
    
            //table name
            private $file = 'files';   // files    
    
            function save_files_info($files) {
                //start db traction
    }
    

    And above your code will be view which is loaded in controller Further can give you reference

    http://www.tutsmore.com/tutorials/codeigniter-image-upload-with-mysql/ start from here

    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?