Download image using Codeigniter - the download path is not displayed.

I'm having problems loading the image using the codeigniter download library, I keep getting the error,

The download path is not displayed.

The path to the file I'm trying to download is as follows:

$config['upload_path'] = './media/images/site';

and when I truncate the following,

 die(var_dump(is_dir($config['upload_path']))); 

I get the following:

BOOL (true)

The folder is also writable (777), so I'm not sure where I am wrong, below is my download code,

 $config['upload_path'] = './media/images/site'; //die(realpath($config['upload_path'])); //die(var_dump(is_dir($config['upload_path']))); $config['allowed_types'] = 'gif|jpg|png|jpeg'; $config['max_size'] = '1500'; $config['max_width'] = '390'; $config['max_height'] = '269'; $this->load->library('upload',$config); if ( ! $this->upload->do_upload() && $_FILES['userfile']['error'] != 4) { $data['error'] = $this->upload->display_errors(); $this->template->build('/admin/pages/about_us', $data); } else { $image = $this->upload->data(); if(empty($image['file_name'])) { $image['file_name'] = $this->formbuilder->defaults['page_image']; } $page = array( //'page_title' => $this->input->post('page_title'), //'page_slug' => $this->input->post('page_slug'), 'page_content' => $this->input->post('page_content'), 'page_image' => $image['file_name'], 'date_created' => date("Ymd h:i:s"), 'created_by' => 1 ); if($this->pages_model->insert($this->security->xss_clean($page))) { redirect('/admin/dashboard'); } } 

I don’t see anything obvious to stop the file loading, below is my folder structure of my project

 /application /system index.php .htaccess /media /images /site /admin /css /js 

If someone can shed light on my problem, that would be great.

EDIT FOR A PETIT VNIINER

What can cause this problem?

(The question arises as if it were not obvious enough)

+4
source share
3 answers

Try adding this line to the libary boot line:

  // Alternately you can set preferences by calling the initialize function. Useful if you auto-load the class: $this->upload->initialize($config); 

Remember to add this line to the template:

 <?php echo form_open_multipart('upload/do_upload');?> 
+8
source

Your problem occurs in the validate_upload_path method system/libraries/Upload.php

This method performs all kinds of tricks for parsing the download path to the full path, so I suggest sticking with the var dump before each line: $this->set_error('upload_no_filepath'); to determine where this happens, then step back from there.

0
source

Try this code in the controller

 $config['upload_path'] = 'images'; //name of the uploading folder $config['allowed_types'] = 'jpeg|png|jpg'; $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

Source: https://habr.com/ru/post/1381116/


All Articles