0
votes

i have this code :

$this->load->library('form_validation'); $this->form_validation->set_rules($this->credit_rules);

    $this->load->model('profile_m');
    $this->load->model('order_m');


        $config['upload_path'] = './uploads/user/';
        $config['allowed_types'] = 'gif|jpg|png|jpeg';
        $config['max_size'] = '2048';
        $config['max_width']  = '2650';
        $config['max_height']  = '2270';
        $config['overwrite'] = FALSE;
        $config['encrypt_name'] = FALSE;

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

        if ( ! $this->upload->do_upload('ktp')  )
        {
            $this->data->error = $this->upload->display_errors();

//          $this->load->view('upload_form', $error);
        }
        else
        {
            $data = array('upload_ktp' => $this->upload->data());
//          $this->load->view('upload_success', $data);
        }

no warning / error appear, submit success but the image which i upload not show up on the folder './uploads/user/' i wonder why, i don't know how to check my upload_path is right or not. i wish for some direction. but i do upload from the different function with a same code it's working and the image show up.

i currently use localhost.

this is the form :

<?php if($this->session->flashdata('pesan')): ?>
<?php echo $this->session->flashdata('pesan'); ?>
<?php else:?>
<?php if(@$error){echo @$error;} ?>
<?php echo validation_errors(); ?>
<?php 
echo form_open_multipart(site_url(uri_string()));
echo form_label('KTP');
echo form_upload('ktp');
echo form_submit('submit','Pesan Sekarang');
?>
2

2 Answers

2
votes

Well if your code work and you're not sure about your path you could always check it like this :

$upload_path = "./uploads/user/";

if(!file_exists($upload_path)) {
    mkdir($upload_path);
}

Because i tried your code and it worked for me too with a valid path, and when i tested with an invalid path you should get an error with : The upload path does not appear to be valid. as the error message

Edit 1

Here how i tested it :

The view :

 <?php echo form_open_multipart(site_url().'/upload_test/uploadImg');?>
        <input type="file" name="ktp" title="Upload ktp" class="btn btn-lg btn-info m-b-sm col-sm-12">
        <input type="submit" value="Go Upload son !">


        <?php echo isset($the_file) ? 'Uploaded file : '.$the_file['file_name'] : ''; ?>
        <?php echo isset($error) ? $error : ''; ?>  
  <?php echo form_close(); ?>

The controller :

public function uploadImg() {

    $config['upload_path']   = './uploads/user';
    $config['allowed_types'] = 'gif|jpg|png|jpeg';
    $config['max_size']      = '2048';
    $config['max_width']     = '2650';
    $config['max_height']    = '2270';
    $config['overwrite']     = FALSE;
    $config['encrypt_name']  = FALSE;

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

    if( ! file_exists($config['upload_path']) ) {
         mkdir($config['upload_path']);
    }


    if ( ! $this->upload->do_upload('ktp')  ) {
        $data['error'] = $this->upload->display_errors();
        $this->load->view('welcome_message', $data);
    }
    else {
        $data['the_file'] = $this->upload->data();

        $this->load->view('welcome_message', $data);
    }
}   

Edit 2

My last idea is to do it without codeIgniter helper. Check this here. W3school guide for PHP File Upload.

0
votes

You defined some constraints such as max_size, max_width, max_height. Did you check the upload images satisfy all your defined constraints?