簡體   English   中英

無法打開文件名中帶有“&”符號的下載文件

[英]cannot open downloaded file having '&' symbol in filename

我想下載上傳到服務器的文件。我將文件名作為鏈接,當用戶單擊它時我需要直接下載文件。我成功了。現在我面臨的問題是我無法打開包含amp符號的文件即使已下載文件名,也可以使用它們的文件名。 例如:&,test.doc(包含其他特殊符號的文件名可以下載並正確打開。)

我的PHP腳本是這樣的:

<script>
function downloadme(file){          
    var link = "download.php?file=" + file; 
    location.replace(link);
} 
</script>

<a title="Click to download" href="javascript:downloadme()">filename</a>

download.php

<?php
$path = $_GET['file'];
header("Content-Description: File Transfer");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=\"" . basename($path . $uri[1]) . "\"" ); 
@readfile($path);  
 ?>  

這就是我所做的

download.php:

<?php
$path = $_GET['file'];
header("Content-Description: File Transfer");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=\"" . basename($path . $uri[1]) . "\"" ); 
@readfile($_GET['file']);
?>

html文件:

<script>
function downloadme(file){          
    var link = "download.php?file=" + escape(file);
    location.replace(link);
} 
</script>

<a title="Click to download" href="javascript:downloadme('test&12.doc')">filename</a>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM