php中如何显示图片?

2020-07-30 16:19:23
php中如何显示图片?下面本篇文章就来给大家介绍使用PHP插入图片的两种方法,希望对你们有所帮助。

1、使用PHP的file_get_contents()函数

file_get_contents() 函数把整个文件读入一个字符串中。

示例:

<?phpheader('content-type:image/jpg;');$content=file_get_contents('1.jpg');echo $content;?>

输出:

1.jpg

2、使用echo+img标签

使用PHP插入图片,实际还是输出HTML代码。

示例:

<?phpecho "<img src='1.jpg' />";?>

输出:

2.jpg

相关文章 大家在看