Loading image in Codeigniter shows an error. The boot path is not displayed.

$config['upload_path'] = site_path().'photos/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '2048';
$this->load->library('upload', $config);    
if ( ! $this->upload->do_upload())
{ 
    $this->data['alert'] = $this->upload->display_errors();                     
    $this->load->view('profile/photo', $this->data);
}   
else
{
    $upload_data = $this->upload->data();

    $filename = $upload_data['file_name'];
    $width = $upload_data['image_width'];
    $height = $upload_data['image_height'];
    $config1 = array();
    $this->load->library('image_lib');
    $config1['source_image'] = site_path().'photos/'.$filename;


    $this->remove_existing_file($this->session->userdata('user_id'));
    $this->Profile_model->savephoto('Edit', $filename );
    redirect('/profile/photo');
}

I get this error:

The boot path is not displayed.

+3
source share
10 answers

There are several reasons for this error:

  • The directory site_path().'photos/'does not exist, try to run is_dir()to make sure it is available.
  • The directory exists but is not writable. Make sure you set the appropriate permissions in the directory. Try is_writable()to make sure.
  • , , , . , .

, , . CI, ( Upload):

public function validate_upload_path()
{
    if ($this->upload_path == '')
    {
        $this->set_error('upload_no_filepath');
        return FALSE;
    }

    if (function_exists('realpath') AND @realpath($this->upload_path) !== FALSE)
    {
        $this->upload_path = str_replace("\\", "/", realpath($this->upload_path));
    }

    // This is most likely the trigger for your error
    if ( ! @is_dir($this->upload_path))
    {
        $this->set_error('upload_no_filepath');
        return FALSE;
    }

    if ( ! is_really_writable($this->upload_path))
    {
        $this->set_error('upload_not_writable');
        return FALSE;
    }

    $this->upload_path = preg_replace("/(.+?)\/*$/", "\\1/",  $this->upload_path);
    return TRUE;
}

:

, , , :

$config['upload_path'] = './community/photos/';
+6
$config['upload_path'] = './photos/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '1000';
$config['max_width'] = '1920';
$config['max_height'] = '1280';                     

$this->upload->initialize($config);

, , __construct(), , , , .

+3

, : ./assets/2016-07-27/ , , , .

:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * File Uploading Class Extension
 *
 * @package     CodeIgniter
 * @subpackage  Libraries
 * @category    Uploads
 * @author      Harrison Emmanuel (Eharry.me)
 * @link        https://www.eharry.me/blog/post/my-codeigniter-upload-extension/
 */
class MY_Upload extends CI_Upload {

    /**
     * Validate Upload Path
     *
     * Verifies that it is a valid upload path with proper permissions.
     *
     * @return  bool
     */
    public function validate_upload_path()
    {
        if ($this->upload_path === '')
        {
            $this->set_error('upload_no_filepath', 'error');
            return FALSE;
        }

        if (realpath($this->upload_path) !== FALSE)
        {
            $this->upload_path = str_replace('\\', '/', realpath($this->upload_path));
        }

        if ( ! is_dir($this->upload_path))
        {
            // EDIT: make directory and try again
            if ( ! mkdir ($this->upload_path, 0777, TRUE))
            {
                $this->set_error('upload_no_filepath', 'error');
                return FALSE;
            }
        }

        if ( ! is_really_writable($this->upload_path))
        {
            // EDIT: change directory mode
            if ( ! chmod($this->upload_path, 0777))
            {
                $this->set_error('upload_not_writable', 'error');
                return FALSE;
            }
        }

        $this->upload_path = preg_replace('/(.+?)\/*$/', '\\1/',  $this->upload_path);
        return TRUE;
    }
}


:

application/libraries/MY_Upload.php . !


:


:

CodeIgniter 3.x 2.x.

+1

Windows, "c: \" , .

_path(), , echo site_path();

xammp , c:\xammp\htdocs\myproject\photos\ , '\ photos \';

0

,

0

.htaccess, - CHMOD 777 var_dump (is_dir ('/photos/')); , ! :

    $config['upload_path'] = 'photos/';
    $config['allowed_types'] = 'gif|jpg|jpeg|png';
    $config['max_size'] = '1000';
    $config['max_width'] = '1920';
    $config['max_height'] = '1280';                     

    $this->upload->initialize($config);
0

, ,

$config['upload_path'] ='./photos/';

$config['upload_path'] = site_path().'photos/';
0

, . . , CodeIgniter /var/www www ( ).

The uploads folder should be in the / var / www folder containing the index.php file. This is what I had to do. The next is to grant 777 permissions to the uploads folder.

0
source

I am using wamp on windows

$config['upload_path'] = base_url().'./resources/uploads/';

not working at all.

var_dump(is_dir($config['upload_path'])); //return false
var_dump(is_writable($config['upload_path']));  //return false

but when I change it to

$config['upload_path'] = './resources/uploads/';   //works fine

It works great. Therefore, I think that in windows this is not a resolution problem. This is called by the base_url () method. How strange this is.

0
source

Try this code in the controller

$config['upload_path'] = 'images'; //name of the uploading folder
$config['allowed_types'] = 'jpeg|png|jpg'; 
$config['file_name'] = 'name_for_file'; 

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

if (!$this->upload->do_upload())
 {
  echo $this->upload->display_errors();
  exit;
 }
else
 {
  $upload_data = $this->upload->data();
 } 
0
source

All Articles