readfile 相当于二进制数据?
我正在使用 http://unDesign.org.za /2007/10/22/amazon-s3-php-class/documentation 使用 php 访问私有文件。我可以通过 $object->body 来获取文件的数据。我实际上想在浏览器中查看图像或在视频播放器中播放视频。有办法做到这一点吗?
我想我需要类似 readfile 的东西。问题是 readfile 是我需要文件的路径。该路径是私有的,所以我不能使用它。有没有办法对二进制数据进行读取文件?
我把它放在 php 中,认为这会有所帮助,但它仍然显示二进制数据。
header('Content: image/jpeg');
header('Content-Disposition: inline; filename=IMAG0108.jpg');
echo $object->body;
I'm using http://undesigned.org.za/2007/10/22/amazon-s3-php-class/documentation to access private files using php. I can get the data of the file by saying $object->body. I actually want to see the image in the browser or play the video in a video player. Is there a way to do that?
I think I need something like readfile. The problem is readfile is I need the path to the file. The path is private so I cannot use that. Is there a way to do a readfile of the binary data?
I put this in the php thinking this would help but it still displays the binary data.
header('Content: image/jpeg');
header('Content-Disposition: inline; filename=IMAG0108.jpg');
echo $object->body;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需设置内容类型标头并将读取文件输出到浏览器。我所做的是创建一个新的 php 文件,例如“showimage.php”,它接受 ID 或类似的信息以了解要显示的图像。然后我在浏览器页面中使用它: 。
在 showimage.php 中,类似:
将从本地系统读取文件并将其输出为图像。我实在是想不通,所以我可能搞砸了这段代码!
You just set the content-type header and output the readfile to the browser. What I do is create a new php file, like "showimage.php", that accepts an ID or some such to know what image to display. Then I use it in a browser page: .
In showimage.php, something like:
That would read a file from the local system and output it as an image. Off the top of my head, so I might have messed up that code!
应该可以正常工作(对于 JPEG),您需要知道有问题的文件类型,然后发送适当的内容标头。
Should work fine (for JPEGs), you need know what filetype is in question and then send appropriate content headers.