2017-02-21 58 views
0

这是我的代码:阅读PDF到浏览器与托管网站

$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

对不起,让你失去了浪费你的时间。解决办法是我没有放正确的道路。