Welcome Guest, Not a member yet? Register   Sign In
upload image error , please help ?...
#1

[eluser]deepydee[/eluser]
I’ve edited this post as i solved the last problem, i can’t pass the image path into folder and database. whats wrong and what can i do ???

Here my controler
Code:
if ($this->input->post('from') == 'edituser') {
            $this->datamodel->saveUser($this->input->post('id'));
            $this->user();
            return false;
        }
        
---
function user()
    {
        if (!$this->Loginkah() || !$this->Adminkah()) {
            $this->mainmenu();
            return false;
        }

        if (isset($_GET['add'])) {
        
            $this->data['add'] = $_GET['add'];

                
            if ($this->data['add'] == 0) {
                $this->data['id'] = $_GET['id'];
                // Try Upload Image
                        $config['upload_path'] = './system/application/uploads';
                        $config['allowed_types'] = 'gif|jpg|png';
                        $config['max_size']    = '100';
                        $config['max_width']  = '1024';
                        $config['max_height']  = '768';                        
                        $data['userfile'] = array('name' => 'userfile');
                        $this->load->library('upload', $config);
                        $this->upload->initialize($config);
                        
            if( $this->upload->do_upload('userfile')){
             $data = array('upload_data' => $this->upload->data());
            // $uploadData = $this->upload->data();
               // $fileName = $uploadData['file_name'];
              
             $this->load->model('datamodel');
            }
            // finis upload image
                
                $this->data['editkode'] = $this->usermodel->getUser($_GET['id']);
                            }
            else {
    ……

            }
………
        }

                $this->data['jenisteks'] = 'User ';
        $this->data['title'] = $this->data['jenisteks'];
        
            $this->load->view('user', $this->data);
    }
----------

This my view, with abxHtml class
Code:
<?
Include “header.php”; //  like this <form name=\"form1\" method=\"post\" action=\"$indexx\" enctype=\"multipart/form-data\">

?>
<?
if(isset($add) ) {
    echo "<fieldset>";

    echo abxHtml::hidden('from', 'edituser');
    if($add == 1) {
        $leg = "add user : ";
        $pesan = "(username dan password harus diisi)";
        $onblur = " onBlur=cek_user() ";
        echo abxHtml::hidden('id', '');
        

    } else {
        $leg = " Edit user: ";
        $pesan = "(Isi password baru jika ingin merubah password atau biarkan kosong jika tidak ingin merubah password)";
        $onblur = "";
        echo abxHtml::hidden('id', $id);
    }

    
    echo "<legend>$leg</legend>";
    echo "<br><table align=left >";
    $ek = isset($editkode) ? strtolower($editkode[0]['username']) : '';
    echo "<tr><td>Username</td><td>:</td><td>" . abxHtml::input('username', $ek, $onblur) . abxHtml::hidden('usernameawal', $ek) . " <span class=msg id=msgkode></span></td></tr>";
    $ek = isset($editkode) ? '' : '';
    echo "<tr><td>Password</td><td>:</td><td>" . abxHtml::password('password', $ek, $onblur) . "<br>$pesan</td></tr>";
    //
    $ek = isset($editkode) ? $editkode[0]['userfile'] : '';
    echo "<tr><td>Image Ttd User</td><td>:</td><td>" . abxHtml::file('userfile', $ek, '')  . "</td></tr>";
    
    //



    $dis2 = isset($editkode) ? '' : ' disabled ';
    echo "<tr><td></td><td></td><td><br>" . abxHtml::button2('simpan', $simpan, 'submitt()', $dis2) . "&nbsp;" . abxHtml::button2('batal', $batal, 'location.href=\'' . $indexx . '&m=user\'', '') . "</td></tr>";
    echo "</table>";
    echo "</fieldset><br>";
}
---------

And this my datamodel
Code:
function &saveUser;($id='') {
        
    $data1 = array(
          'username' => strtolower($this->input->post('username')),
            
            'statususer' => $this->input->post('statususer'),
            //'userfile' => $this->input->post('userfile')
            'userfile' => $this->upload->data('file_name')
            //'userfile' => $data['upload_data']['file_name']
            
    );
    if ($id == '') {
        $data2 = array(
            'password' => MD5($this->input->post('password')),
            
        );
        

        $dataa = array_merge($data1, $data2);
        $this->db->insert('user', $dataa);
    } else {
        if($this->input->post('password') != '') {
            $data2 = array(
                'password' => MD5($this->input->post('password'))
            );
            $dataa = array_merge($data1, $data2);
        } else {
            $dataa = $data1;
        }
        $this->db->where('id', $id);
        $this->db->update('user', $dataa);
    }
    return $id;
}
------------

i get error

A PHP Error was encountered

Severity: Notice

Message: Undefined property: DataModel::$upload

Filename: models/datamodel.php

Line Number: 92

Fatal error: Call to a member function data() on a non-object
----------------------

sorry if my english bad ... , please help ??




Theme © iAndrew 2016 - Forum software by © MyBB