PHP,在浏览器中显示pdf文件
我真的在尝试阅读broswer中的pdf文件,我一直在互联网上搜索,我尝试了许多代码,这是我的代码:PHP,在浏览器中显示pdf文件,php,pdf,Php,Pdf,我真的在尝试阅读broswer中的pdf文件,我一直在互联网上搜索,我尝试了许多代码,这是我的代码: <?php $directory = 'C:/Users/Oscar/Documents/'; if(isset($_POST['libros'])) { $dir = $directory.'libros/'; file_put_contents('cache', $dir); $files = array_diff(scandir($dir), arr
<?php
$directory = 'C:/Users/Oscar/Documents/';
if(isset($_POST['libros']))
{
$dir = $directory.'libros/';
file_put_contents('cache', $dir);
$files = array_diff(scandir($dir), array('..', '.'));
ob_clean();
ob_start();
foreach($files as $file):?>
<table border="2px">
<tr>
<td>
<form method="post">
<input type="submit" value="<?php echo $file; ?>" name="libros-file" />
</form>
</td>
</tr>
</table>
<?php endforeach;;
}
if(isset($_POST['musica']))
echo "musica exists!";
if(isset($_POST['test']))
{
$dir = $directory.'test/';
file_put_contents('cache', $dir);
$files = array_diff(scandir($dir), array('..', '.'));
foreach($files as $file):?>
<table border="2px">
<tr>
<td>
<form method="post">
<input type="submit" value="<?php echo $file; ?>" name="test-file" />
</form>
</td>
</tr>
</table>
<?php endforeach;
}
if(isset($_POST['test-file']))
{
//print_r($_POST['file']);
$dir = file_get_contents('cache');
unlink('cache');
$file = file_get_contents($dir.$_POST['test-file']);
echo $file;
}
if(isset($_POST['libros-file']))
{
ob_clean();
$dir = file_get_contents('cache');
unlink('cache');
$file = file_get_contents($dir.$_POST['libros-file']);
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Type: application/pdf');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($file));
@read($file);
}
我试图读取libros中的一个文件,但一直以来,即使我尝试了所有代码,我都会访问pdf查看器,但我什么也看不到,我还收到一条建议,说pdf可能无法正确显示。请帮助您的代码非常混乱。在缓存文件中存储一个目录路径,然后读取该缓存文件,并执行文件获取内容。。在那个目录上。这不是你读文件的方式。。。您需要学习基本的调试技术,这将表明您没有读取任何文件,也没有向浏览器发送任何接近有效PDF的内容。您的意思是将PDF文件嵌入HTML文档?如果是,请尝试查看以下内容:[链接]