【问题标题】:While downloading pdf file from another server forward slash is get replaced with underscore从另一台服务器下载 pdf 文件时,正斜杠被下划线替换
【发布时间】:2016-01-27 07:04:05
【问题描述】:

我正在尝试从我的服务器下载 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);

谁能提出其中的问题。

【问题讨论】:

  • 您的意思是$download_path 变量内容发生了变化吗?还是您的意思是 Content-Disposition 文件名参数的值在传输到客户端时会发生变化?
  • @mkl $download_path 变量内容在下载时更改其值。

标签: php pdf download


【解决方案1】:

我得到了答案。 我试图从另一台服务器下载 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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-29
    • 1970-01-01
    相关资源
    最近更新 更多