简体   繁体   English

如何在Content-Disposition标头中使用带有特殊字符的文件名?

[英]How can I use a filename with special characters in a Content-Disposition header?

I have a problem with some php code: 我有一些php代码问题:

$link = $_GET['url'];
$name = $_GET['name'];
$str = '[wanted-web.ro]';

header("Content-Disposition: attachment; filename=$str $name");
header("Content-type: audio/mpeg;\r\n");
readfile(str_replace(' ', '_', $link));

That is the code I use to save files. 那就是我用来保存文件的代码。 When I want to download some direct files to my computer, that dot what I use in wanted-web.ro stop writing the rest of information after dot " . ", such like this: 当我想将一些直接文件下载到我的计算机上时,该点在我想要的web.ro中使用时停止在点“ ”之后写入其余信息,例如:

[wanted-web [想要的Web

Problem SOLVED! 问题解决了!

Thank you verry much to all. 非常感谢大家。 You are awesome. 你真棒。 I combined your comments, and the result is: 我结合了您的评论,结果是:

header("Content-Disposition: attachment; filename=\"[wanted-web.ro] $name.mp3\""); 

That work perfect! 完美的工作! Thanks very much to all. 非常感谢大家。 Respect! 尊重!

Quote the filename in the header: 在标题中引用文件名:

header("Content-Disposition: attachment; filename=\"$str $name\"");

http://www.ietf.org/rfc/rfc6266.txt http://www.ietf.org/rfc/rfc6266.txt

Try this: 尝试这个:

<?php
$link = $_GET['url'];
$name = $_GET['name'];
$str = "[wanted-web.ro]";

header("Content-Disposition: attachment; filename=".$str." ".$name);
header("Content-type: audio/mpeg;\r\n");
readfile(str_replace(' ', '_', $link));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更正Content-Disposition标头中的文件名值? - How to correct filename value in Content-Disposition header? PHP Content-Disposition header:文件名中的特殊字符 - PHP Content-Disposition header: Specialcharacters in the filename 如何使用 content-disposition 标头设置下载的 UTF-8 文件名? - How to use the content-disposition header to set a downloaded UTF-8 filename? php标头内容处置 - php header Content-disposition 标头(“ Content-Type:应用程序/ zip”)和标头(“ Content-Disposition:附件;文件名= $ fileName”)在wordpress中不起作用? - header(“Content-Type: application/zip”) and header(“Content-Disposition: attachment; filename=$fileName”) not working in wordpress? 如何在Android设备上设置“Content-Disposition:inline;”文件的文件名? - How to set a filename for “Content-Disposition: inline;” file on android device? Firefox将下载retrieve.php,而不是每个Content-Disposition标头指定的文件名 - Firefox downloads retrieve.php instead of filename given per Content-Disposition header 客户端缺少内容处理标头 - Content-Disposition header missing at client PHP:RFC-2231如何将UTF-8字符串编码为Content-Disposition文件名 - PHP: RFC-2231 How to encode UTF-8 String as Content-Disposition filename 如何在 php 中更改 Content-Disposition 的目录 - How to change directory of Content-Disposition in php
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM