尝试下载文件时出现混乱的字符串

时间:2019-11-28 08:24:39

标签: php string oracle http-headers

我目前正在为Oracle数据库构建一种CRUD系统。在PHP中。

我设法从中下载了LOBS,但现在遇到了问题:

$requete2 = oci_parse($connexion, $sql2);
$result2 = oci_execute($requete2);

$row = oci_fetch_array($requete2, OCI_ASSOC+OCI_RETURN_LOBS); //the rows returned are "LIBELLE" and "CONTENU"

$filename = preg_quote($row['LIBELLE'], " ");

header('Content-Type: application');
header("Content-Disposition: attachment; filename='". $filename ."'");

ob_clean();
flush();
echo $row["CONTENU"];

oci_close($connexion);
exit;

代码可以正常工作,就像在正确的文件中下载了所有文件一样,但是对于此给定的字符串:

TR_ Contrat 493 140 - Reclamation degradation suite intervention.pdf

即使使用preg_quote进行了更改:

TR_\ Contrat\ 493\ 140\ \-\ Reclamation\ degradation\ suite\ intervention\.pdf

我得到“您已选择打开'TR_”。显然有一些字符串转义的问题,但我不太清楚。有什么想法吗?

Capture of the download dialog. The filename is wrong.

谢谢。

编辑:问题已在“ How to encode the filename parameter of Content-Disposition header in HTTP?”处解决 解决方案是使用双引号,如

header('Content-Disposition: attachment; filename="'. $filename .'"');

代替

header("Content-Disposition: attachment; filename='". $filename ."'");

我猜正常的PHP生活。感谢您的回答

0 个答案:

没有答案