从另一个服务器下载pdf文件时,正斜杠被替换为下划线


While downloading pdf file from another server forward slash is get replaced with underscore

我正在尝试从我的服务器下载pdf文件。 下载文件时,它会用下划线替换正斜杠(/),文件路径变成这样(127.0.0.1_file_upload_demoform1.pdf),因为无法下载文件。

这是代码。

header('Content-Type: application/pdf');
$download_path = "127.0.0.1/file_upload/demoform1.pdf";
header('Content-Disposition: attachment; filename='.$download_path);
readfile('downloads/'.$download_path);

任何人都可以建议其中的问题。

我得到了答案。我正在尝试从另一台服务器下载pdf文件。这不允许我直接从该位置下载。

这是我的解决方案。

$content = file_get_contents('http://127.0.0.1/file_upload/demoform1.pdf');
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename=demoform1.pdf');
echo $content;