使用php的Google云存储显示pdf

使用php的Google云存储显示pdf,php,iframe,google-cloud-storage,Php,Iframe,Google Cloud Storage,我试图在iframe中显示一个带有php的pdf文件,但该文件已下载 客户端代码: <iframe style="height: 700px;width: 80%;margin-left: 100px;" src="<?php echo $publicUrl;?>#zoom=100"></iframe> 如何在iframe中显示pdf文件?您需要在浏览器中安装pdf viewer附加组件。您可以在下面查看更多详细信息 要在浏览器中显示PDF,服务器必须返回

我试图在iframe中显示一个带有php的pdf文件,但该文件已下载

客户端代码:

 <iframe style="height: 700px;width: 80%;margin-left: 100px;" src="<?php echo $publicUrl;?>#zoom=100"></iframe>

如何在iframe中显示pdf文件?

您需要在浏览器中安装pdf viewer附加组件。您可以在下面查看更多详细信息


要在浏览器中显示PDF,服务器必须返回两个标题:

  • 内容类型:application/pdf
    告诉浏览器该文件是pdf文件
  • Content-Disposition:inline
    告诉浏览器显示PDF而不是保存它

  • 您可以使用该函数在PHP中设置标题,但必须在发送任何其他内容之前设置标题。

    wich add-ons?我可以在本地服务器的iframe中显示pdf,而不需要任何附加组件,但是当我在app engine和google storage中上载我的项目时,我发现了问题。下载的pdf文件是有效的pdf文件吗?$publicUrl变量中是否有“.pdf”扩展名?pdf下载无效,“.pdf”在$publicUrl中是的,我在url中有问题,我修复了它,现在我可以在下载后读取pdf,并且在iframe中有消息“NoSuchKeyThe specified key not Existence.”url:{Bucket}/上传/签名/事件/大会/大会5/association\u dpss/dpss\u 8.pdf谢谢您的帮助
    App::uses('APIController', 'Controller');
    require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php';
    $publicFileText = sprintf('new file written at %s', date('Y-m-d H:i:s'));
    
    $options = ['gs' => ['acl' => 'public-read']];
    $context = stream_context_create($options);
    $fileName = "gs://{Project_ID}.appspot.com/test/test.pdf";
    file_put_contents($fileName, $publicFileText, 0, $context);
    $publicUrl = CloudStorageTools::getPublicUrl($fileName, false);