下载文件名中包含 & 的文件问题。
例如,名为 bla 的文件可以正常下载,但 bla & Blaaaaa 找不到该文件。
有没有办法让我逃脱&?
我无法重命名服务器上的文件,这会更容易但不可能。
文件存储在数据库中,然后检索并修剪其独特的附件。:)
$fileName = $eachFile['filename'];
$fileNamePretty = explode('__', $fileName); // ONLY FILENAME
然后在下载链接中我有:
<a href="../download.php?filename=<?php echo $fileName?>">
和download.php
<?php
require 'core/init.php';
$filename = $_GET['filename'];
$dir = "training/trainingDocuments/";
$downloadFilename = $dir.$filename;
//8 - SUBSEA QUESTIONS__51f034ab37a8e.xls
//if the filename exists
if(is_file($downloadFilename)){
//send the headers
header('Pragma: public'); //FIX IE6 Content-Disposition
header('Content-Description: File Transfer');
header('Content-Transder-Encoding: binary');
header(sprintf('Content-Length: %u', filesize($downloadFilename)));
header('Content-type: application/octet-stream');
header("Content-Disposition: attachment; filename=".$downloadFilename."");
readfile($downloadFilename);
$training->addToDownload($filename);//updates download count
}else{
//file doesn't exist
echo "File no exist\n\n";
echo $downloadFilename;
谢谢你的帮助