Jump to content
Larry Ullman's Book Forums

bia.morton

Members
  • Posts

    1
  • Joined

  • Last visited

Posts posted by bia.morton

  1. I must be missing something. Everything works as expected but the pdf never show. It just says "loading" on the bottom acrobat style. I even tried adding an extension to the file name as you see bellow.

    <?php
    	require('includes/config.inc.php');
    	require(MYSQL);
    	$valid = false;
    	if(isset($_GET['id']) && strlen($_GET['id']) === 63 AND substr($_GET['id'], 0, 1) !== '.') {
    		$file = PDF_DIR . $_GET['id'] . '.pdf';
    		if(file_exists($file) && is_file($file)) {
    			$query = "SELECT id, title, description, file_name FROM pdfs WHERE tmp_name = '" . escapeData($_GET['id'], $dbc) . "'";
    			$result = mysqli_query($dbc, $query);
    			if(mysqli_num_rows($result) === 1) {
    				$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
    				$valid = true;
    				if(isset($_SESSION['user_not_expired'])) {
    					header('Content-type:application/pdf');
    					header('Content-disposition:inline;filename="' . $row['file_name'] . '.pdf"');
    					$size = filesize($file);
    					header('Content-length:$size\n');
    					readfile($file);
    					exit();
    				} else {
    					$pageTitle = $row['title'];
    					include('includes/header.html');
    					echo '<h1>' . $pageTitle . '</h1>';
    
    					viewingWarning();
    
    					echo '<div>' . htmlspecialchars($row['description']) . '</div>';
    					include('includes/footer.html');
    				}
    			}
    		}
    	}
    
    	if(!$valid){
    		trigger_error('There was an error accessing the page you requested. Please try again later.');
    	}
    

    viewingWarning is just a function i created to display the please sign in to view content or please renew to view content. It works just fine in other pages so I dont think thats the problem. I even tried copying and pasting view_pdf.php straight from the downloaded folder and it does the same thing. Im coding on my personal laptop. Any special settings I need to use to display pdfs?

×
×
  • Create New...