Pergunta

I want to download files uploaded to the server.I have the filenames as links and I need to download the file directly when the user click it.I have succeeded in that.The issue now I face is I cant open the files containing amp symbols in their filename,eventhough it is downloaded. eg: &,test.doc(filename containing other special symbols can be downloaded and opened properly.)

My php script is like this:

<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);  
 ?>  
Foi útil?

Solução

Here's what I did

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 file:

<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>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top