Calliphoridae (pkbarbiedoll) wrote in php,
Calliphoridae
pkbarbiedoll
php

Open PDF in browser, not "Save As"

My users want an option to open stored PDFs in the browser window instead of being prompted to download the file.

Current code:

if(file_exists($file))
		{
			header('Content-Description: File Transfer');
			header('Content-Type: application/octet-stream');
			header('Content-Disposition: attachment; filename='.basename($file));
			header('Content-Transfer-Encoding: binary');
			header('Expires: 0');
			header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
			header('Pragma: public');
			header('Content-Length: ' . filesize($file));
			ob_clean();
			flush();
			readfile($file);
			exit;
		}


How would I write the headers to allow files to open in the browser window?
  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

  • 8 comments