这是我的代码:
$filename = $data['cmr'];
$realpath = str_replace('../', '', $filename);
$path = str_replace('/', '\\', $realpath);
//On affiche le document PDF à l'écran
$content = file_get_contents($path);
header("Content-Disposition: inline; filename=$filename");
header("Content-type: application/pdf");
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
echo $content;
}
else
{
echo 'Vous ne possédez pas les droits pour accéder à cette page.';
}
我的问题是:"无法加载PDF文件"。我的网站托管在ovh。
我试着这样做:
$content = file_get_contents($path);
//header("Content-Disposition: inline; filename=$filename");
//header("Content-type: application/pdf");
//header('Cache-Control: private, max-age=0, must-revalidate');
//header('Pragma: public');
echo $path;
路径还可以。此外,如果我复制此路径并将其作为url(在域名之后)放入浏览器,我将获得我的PDF文件。但是,目标是使用名为view.php。
的php文件向用户隐藏此路径我必须指明这是在本地工作没有任何问题。
答案 0 :(得分:0)
很抱歉让你失去浪费时间。解决方案是我没有采用正确的路径。