error when trying to download file in codeigniter 3

1

I made a function to upload files and this works correctly, now in my view I've added a link to download the file.

link in view:

<td><?php echo anchor("propostas/download/{$id}/{$record->nomepessoal}", "<i class='glyphicon glyphicon-arrow-down'></i>", ['class' => 'btn btn-primary btn-block', 'name' => 'baixar']); ?></td>

and this is function of controller

// baixar anexo
public function download($id, $nomepessoal) {

    $this->load->helper('download');

    $nomearquivo = $nomepessoal."_".$id.".zip";
    $path = file_get_contents(base_url()."anexos/".$nomearquivo);

    force_download($path, null); // start download'
}

Error in file_get_contents function:

  

Message: file_get_contents ( link ): failed to open stream: HTTP request failed! HTTP / 1.0 404 Not Found

Note: the file exists and the name is correct.

    
asked by anonymous 24.10.2017 / 18:11

1 answer

2

Validate if your .htaccess is configured and working. It should direct calls to index.php , but if it is to access an existing file it should not direct to index . Ensure that the following lines exist in your .htaccess :

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
    
27.10.2017 / 20:17