javascript - Codeigniter adds index.php to a download url -


i trying make button when pressed calls javascript function downloads file.

download code:

function downloadfile(url) {    console.log('clicked');    var iframe;    iframe = document.getelementbyid("download-container");    if (iframe === null)    {        iframe = document.createelement('iframe');          iframe.id = "download-container";        iframe.style.visibility = 'hidden';        document.body.appendchild(iframe);    }    iframe.src = "uploads/img/"+url;    } 

button code:

<?php echo '<button type="button" onclick="downloadfile(\''.$value.'\')">'.$value.'</button>' ?> 

the output is:

get http://localhost/dfi/index.php/uploads/img/mux.png 404 (not found) 

because index.php added url, when remove index.php , access file directly in browser can access normally.

try :

iframe.src = "/uploads/img/"+url; 

or add full url src :

iframe.src = "http://localhost/dfi/uploads/img/"+url;   

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -