Can php only use code to display an image?

WBOY
Release: 2016-07-06 13:51:11
Original
1171 people have browsed it

Is there a way to use PHP functions to read an image and display it without using any front-end code? ? ?

Reply content:

Is there a way to use PHP functions to read an image and display it without using any front-end code? ? ?

file_get_contents(你的图片路径,可以是URL地址)

Can php only use code to display an image?

<code><?php
$imagedata=file_get_contents('logoquan14483280771.PNG');
$data=getimagesizefromstring($imagedata);

if(!$data){
    exit('图片无效');
}
header("content-type:".$data['mime']);
ob_clean();
echo $imagedata;</code>
Copy after login

Yes, the verification code is a separate php file.
First of all, you need to set the file header. If the content-type is an image format, then you can directly output the image you read in. You can check the PHP image api

http://php.net/manual/en/book.image.php

Just read the base64 of the image and output it

The verification code is output directly using PHP. Generally, PHP is used to output the content. Just set the request header and add the relevant API. Usually, the text/html type is used to output text. Any apk, doc, exls can be output.

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template