CodeIgniter Forums
Force download of image - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Force download of image (/showthread.php?tid=80285)



Force download of image - pippuccio76 - 10-12-2021

Hi , sorry for english , i want create a link to download image and pdf from server folder .

This is the code :
Code:
<?= $v->nome_file_originale ?><a download="<?= $v->nome_file_originale ?>" href="<?=base_url() ?>/uploaded/xyz_xrh/documenti/<?=$record->id_users?>/<?= $v->nome_file ?>" >Download</a>

it work only with pdf ...


RE: Force download of image - ARAmiss - 10-14-2021

Add "download" attribute to the link.


RE: Force download of image - pippuccio76 - 10-14-2021

(10-14-2021, 04:41 AM)ARAmiss Wrote: Add "download" attribute to the link.

there is download...


RE: Force download of image - ARAmiss - 10-14-2021

What's your link look like in html page source (in browser)?


RE: Force download of image - InsiteFX - 10-15-2021

Please read the CodeIgniter 4 User Guide.

CodeIgniter 4 User Guide - Force File Download


RE: Force download of image - ARAmiss - 10-15-2021

pippuccio76 use base_url, so it seems files stored in public folder, it is enough for him to give away a picture using a web server. Not build response from img.


RE: Force download of image - pippuccio76 - 10-15-2021

(10-15-2021, 12:46 AM)InsiteFX Wrote: Please read the CodeIgniter 4 User Guide.

CodeIgniter 4 User Guide - Force File Download

But i must use it on an html page not redirect to another page .... is there a way to use an anchor ?

(10-15-2021, 01:11 AM)ARAmiss Wrote: pippuccio76 use base_url, so it seems files stored in public folder, it is enough for him to give away a picture using a web server. Not build response from img.

base_url work only to show image not to download....


RE: Force download of image - InsiteFX - 10-16-2021

According to this you just need to add the download attribute.

How to force a file to download instead of open in the browser using only HTML

Chrome will not allow cross orgin downloads.


RE: Force download of image - pippuccio76 - 10-18-2021

But which is the correct path ? the file is in /uploaded , at the same level i have the codeigniter folder (inside there are app,system,vendor and writable) . i try FCPATH ,base_url() but dont work...