Output an Image in PHP

前端 未结 12 1253
萌比男神i
萌比男神i 2020-11-22 14:33

I have an image $file ( eg ../image.jpg )

which has a mime type $type

How can I output it to the browser?

12条回答
  •  青春惊慌失措
    2020-11-22 14:45

    header("Content-type: image/png"); 
    echo file_get_contents(".../image.png");
    

    The first step is retrieve the image from a particular location and then store it on to a variable for that purpose we use the function file_get_contents() with the destination as the parameter. Next we set the content type of the output page as image type using the header file. Finally we print the retrieved file using echo.

提交回复
热议问题