简体   繁体   中英

Codeigniter adds index.php to a download url

I am trying to make a button that when pressed calls a javascript function that downloads a 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 is added to the url, when i remove index.php and access the file directly in the browser i can access it normally.

Try this :

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

Or add the full url to the src :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM