PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, January 21, 2022

[FIXED] The upload path does not appear to be valid in codeigniter when upload image

 January 21, 2022     codeigniter, php, uploading     No comments   

Issue

I'm trying to make crud with upload image. When I try to upload it keeps returning failed. I put var_dump it shows false when I put code to show error it returns:

"The upload path does not appear to be valid"

I've been searching for the solution and I found nothing. Can some one help me to find the error:

This is my controller :

 public function saveReimburse()
{
    validate_submitted_data(array(
        'nama' => 'required',
        'category_reimburse_id' => 'required',
        'amount' => 'required|numeric',
        'date_reimburse' => 'required',
        // 'photo' => 'required'
    ));
    // data
    $data = [
        'nama' => $this->input->post('nama'),
        'category_reimburse_id' => $this->input->post('category_reimburse_id'),
        'amount' => $this->input->post('amount'),
        'date_reimburse' => $this->input->post('date_reimburse'),
        'photo' => $_FILES['photo'],
        // 'status'=> $this->input->post("PENDING"),
        // 'nama' => $this->input->post('nama'),
    ];


    // condition
    $date = date('Y-m-d');
    $date = strtotime($date);
    $date = strtotime('-7 day', $date);

    if ($data['date_reimburse'] < date('Y-m-d', $date)) {
        echo json_encode(array('succes' => FALSE, 'message' => 'Max Reimburse was 1 week ago'));
    } else {
        // var_dump($data);
        // exit;
        if ($data['photo'] = "") {
        } else {
            $config = [
                'upload_path' => is_dir('assets/reimburse/') . 'assets/reimburse/',
                'allowed_types' => 'jpg|png|gif',
                'overwrite' => TRUE
            ];
            $this->load->library('upload', $config);
            $upload = $this->upload->do_upload('photo');

            var_dump($config);
            print_r($this->upload->display_errors());exit;

            var_dump($upload);exit;
            if (!$upload) {
                json_encode(array('success' => FALSE, 'message' => 'Failed Upload'));
                redirect('Reimburse/index', 'refresh');
            } else {
                $this->upload->data('file_name');
                $save = $this->reimburseModel->saveReimburse('reimburse', $data);
                var_dump($data);exit;
                if (!$save) {
                    echo json_encode(array('success' => FALSE, 'message' => 'Failed to reccord'));
                } else {
                    redirect('Reimburse/index', 'refresh');
                    echo json_encode(array('success' => TRUE, 'message' => 'Reimburse Success'));
                }
            }
        }
    }
}

Solution

You have to use base_path for physical path in codeigniter.

$base_path = $this->config->item('base_path');

Then Use $base_path as your project folder root directory and you can access any folder from your project folder to upload images.

Like. $base_path.'/'.'upload/';



Answered By - thesachinparmar
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing