我有阅读pdf的php url问题

Now I am developing codeigniter site. I have one issue. In order to read&open pdf into web browser.

header("Content-type:application/pdf");         
header('Content-Type: application/vnd.ms-excel'); //mime type
header('Cache-Control: max-age=0'); //no cache          
header("Content-Disposition:attachment;filename=\"".$file."\"");
readfile($filePath);

above code $file is filename and $filePath is pdf file path. When it runs on local server, $filePath is value such as "http://localhost/.pdf" and it runs well. But when runs on hosting server, this value is "http://.com/***.pdf" And doesn't run. We can not open with pdf format error. file content didn't include readed. I know that is cause of URL issue. But I have no issue!

Your Content-Disposition should be inline if you want to display the file in the browser and not as a download but I guess it doesn't really matter if you can get it to work.

If your allow_url_fopen config in PHP is set to Off, you will not be able to read URL file from within your PHP script.

Anyway, your code should look something like this.

<?php

$file = "lesson2.pdf";
$filePath = "http://kmmc.in/wp-content/uploads/2014/01/lesson2.pdf";

header("Content-Type: application/pdf");
header("Cache-Control: max-age=0");
header("Content-Disposition: inline; filename=\"" . $file . "\"");
readfile($filePath);