Codeigniter将index.php添加到下载URL

时间:2015-07-22 13:02:45

标签: javascript php codeigniter iframe

我正在尝试创建一个按钮,按下时调用下载文件的javascript函数。

下载代码:

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;   
}

按钮代码:

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

输出是:

GET http://localhost/dfi/index.php/uploads/img/Mux.png 404 (Not Found)

因为index.php被添加到url中,当我删除index.php并直接在浏览器中访问该文件时,我可以正常访问它。

1 个答案:

答案 0 :(得分:0)

试试这个:

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

或者将完整的url添加到src:

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