file_get_contents或readfile来显示文件系统映像 [英] file_get_contents or readfile for displaying filesystem image

查看:115
本文介绍了file_get_contents或readfile来显示文件系统映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以建议什么是用于显示存储在文件系统中的图像的最佳PHP函数 - file_get_contents readfile 。我们正在切换显示存储在数据库中的图像,所以我们仍然需要通过PHP文件调用图像,并且不能直接链接到文件系统。我见过有人推荐这两个函数,但我倾向于使用 readfile 。如果您不需要操作图像(调整大小,添加水印,.. ..) ) readfile() 将是最佳选择因为它直接将文件写入输出缓冲区。 file_get_contents() 将文件读入内存 - 需要大量文件的内存。


Can anyone advise on what is the best PHP function for displaying an image stored in a filesystem - file_get_contents or readfile. We are switching from displaying images stored in the database so we still need to call the images through a PHP file and cannot link directly to the filesystem. I've seen people recommending both functions but I'm inclined towards using readfile. Would appreciate any input on this.

解决方案

If you don't need to manipulate the images (resizing, adding watermarks,...) readfile() will be the best choice as it writes the file directly to the output buffer. file_get_contents() will read the file into memory instead - requiring a lot of memory with large files.

这篇关于file_get_contents或readfile来显示文件系统映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆