How to display pdf in php

后端 未结 6 1740
情深已故
情深已故 2020-12-03 05:42

I\'m trying to display a pdf file in php, I used:



         


        
6条回答
  •  北荒
    北荒 (楼主)
    2020-12-03 06:31

    if(isset($_GET['content'])){
      $content = $_GET['content'];
      $dir = $_GET['dir'];
      header("Content-type:".$content);
      @readfile($dir);
    }
    
    $directory = (file_exists("mydir/"))?"mydir/":die("file/directory doesn't exists");// checks directory if existing.
     //the line above is just a one-line if statement (syntax: (conditon)?code here if true : code if false; )
     if($handle = opendir($directory)){ //opens directory if existing.
       while ($file = readdir($handle)) { //assign each file with link  tag with GET params
         echo ''.$file.'';
    }
    

    }

    if you click the link a new window will appear with the pdf file

提交回复
热议问题