1

im sorry mr im try this code for upload with angular in codeigniter but file and data not insert to database and file not upload, :) please corectly im no find that tutorial in google please..

        $postdata = file_get_contents("php://input");
        $data = json_decode($postdata);

        $config['upload_path']      = 'assets/img/img_berita/';
        $config['allowed_types']    = 'gif|jpg|png';
        $config['max_size']         = '1000';
        $config['max_width']        = '1024';
        $config['max_height']       = '768';
        $config['encrypt_name']     = TRUE;

        $this->load->library('upload', $config);

        if( ! $this->upload->do_upload($data($_FILES['file'])) ) {
            $this->set_model->update_data('berita', array('gambar' => $data['file']['name']), array('id_berita' => $data['id_berita']) );
            echo '{"stat" : "Success!"}';
        } else {
            echo '{"stat" : "Try Again!"}';
        }
    app.controller('berita_uploadImage', function($scope,$http,$routeParams,$location,Upload) {
        $scope.ImageInfo = 
        $scope.dataInfo = [];

        $scope.onFileSelect = function(file) {
            //console.log($scope.picFile);
            if (!file) return;
            console.log(file);
            Upload.upload({
                method : 'POST',
                url : '<?php echo base_url();?>home/dashboard/admin/upload_image_berita',
                data : JSON.stringify({'id_berita':$scope.id_berita,file:file}),
            }).success(function(data) {
                console.log($scope.id_berita);
                console.log(file);
                console.log(data.stat);
            });
        }

        $scope.id_berita = $routeParams.id_berita;
        $http.get('<?php echo base_url(); ?>home/dashboard/admin/getImage_berita/' + $scope.id_berita ).success(function(result) {
            $scope.dataInfo = result;
        });
6

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.