Php 如何从下载文件中删除url
我已经找到了这个脚本,它的工作原理就像一个符咒,但是我下载的文件现在在名称中有了url。我怎样才能去掉它Php 如何从下载文件中删除url,php,jquery,url,Php,Jquery,Url,我已经找到了这个脚本,它的工作原理就像一个符咒,但是我下载的文件现在在名称中有了url。我怎样才能去掉它 The html: <a class="download_link" href="catalogue/CP-Greengo-Filtertips-30027.jpg"><img src="CP-Greengo-Filtertips-30027.jpg" width=100 alt=image></a> The jQuery: $('a.download_
The html:
<a class="download_link" href="catalogue/CP-Greengo-Filtertips-30027.jpg"><img src="CP-Greengo-Filtertips-30027.jpg" width=100 alt=image></a>
The jQuery:
$('a.download_link').on('click', function (event) {
event.preventDefault(); //prevent the normal click action from occuring
window.location = 'php/filedownload.php?file=' + encodeURIComponent(this.href);});
The php:
$file = $_GET['file'];
header('Content-Description: File Transfer');
header("Content-type: application/octet-stream");//notice this content-type, it will force a download since browsers think that's what they should do with .exe files
header("Content-disposition: attachment; filename= ".$file."");
readfile($file);
html:
jQuery:
$('a.download_link')。在('click',函数(事件){
event.preventDefault();//防止正常的单击操作发生
window.location='php/filedownload.php?file='+encodeURIComponent(this.href);});
php:
$file=$\u获取['file'];
标题(“内容描述:文件传输”);
标题(“内容类型:应用程序/八位字节流”)//请注意这种内容类型,它将强制下载,因为浏览器认为这是他们应该对.exe文件执行的操作
标题(“内容处置:附件;文件名=“.$file.”);
readfile($file);
感谢php中的所有内容,请执行以下操作:
$pathParts = explode('/',$file);
$fileName = $pathParts[count($pathParts)-1];
header("Content-disposition: attachment; filename=".$fileName);
这将从文件路径中删除剩余的URI,并留下文件名。在php中,执行以下操作:
$pathParts = explode('/',$file);
$fileName = $pathParts[count($pathParts)-1];
header("Content-disposition: attachment; filename=".$fileName);
这将从文件路径中删除剩余的URI,并留下文件名。Wauw,太快了!太棒了。非常感谢格雷格:)没问题。如果答案解决了你的问题,一定要接受。是的,效果很好。你会注意到,当你接受一个问题时,当人们投票给你的问题或答案时,你会得到声誉分数。哇,那太快了!太棒了。非常感谢格雷格:)没问题。如果答案解决了你的问题,一定要接受。是的,效果很好。你会注意到,当你接受一个问题时,当人们投票给你的问题或答案时,你会得到声誉分数。