问题描述
任何人都可以建议什么是用于显示存储在文件系统中的图像的最佳PHP函数 - file_get_contents
或 readfile
。我们正在切换显示存储在数据库中的图像,所以我们仍然需要通过PHP文件调用图像,并且不能直接链接到文件系统。我见过有人推荐这两个函数,但我倾向于使用 readfile
。如果您不需要操作图像(调整大小,添加水印,.. ..) )将是最佳选择因为它直接将文件写入输出缓冲区。 将文件读入内存 - 需要大量文件的内存。 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来显示文件系统映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!