2012-03-09 31 views
0

我在php中创建了一个下载函数,其中文件中包含特殊字符。 但在下载文件时,文件名称会从某些特殊字符中断开。 主要在获取文件名的空间时。 我的下载功能是这样的。不想在文件名中创建具有特殊字符的下载功能

function download(){ 
      $filename = "google _(){}[][email protected]#$%^&*()_+`1=-.flv"; 
      $filepath = "uploads/" . $filename; 
      header("Pragma: public"); 
      header("Expires: 0"); 
      header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
      //setting content type of page 
      header("Content-Type: application/force-download"); 
      header("Content-Disposition: attachment; filename=" . $filename); 
      header("Content-Description: File Transfer"); 
      //Read File it will start downloading 
      readfile($filepath); 
} 

请大家帮忙。

回答

2

你应该设法逃脱空间,其中包括 “\”。

像这样:

$filename = str_replace(' ', '\ ', $filename); 
+0

谢谢。 我昨天自己做了。 这样。 'header(“Content-Disposition:attachment; filename = \”“。$ filename。”\“”);' 感谢您的回复。 – 2012-03-10 06:53:12

相关问题