Home >Backend Development >PHP Tutorial >How to implement pictures without suffix in PHP

How to implement pictures without suffix in PHP

小云云
小云云Original
2018-03-26 13:18:392082browse

When I accidentally developed a website and captured web content, I found that some pictures did not have suffixes. Then, with the mentality of walking alone, I tried this "major discovery" that I had never encountered before:

After completing the test, I found that the principle is really simple. In fact, it is just a Simple file operation and reading:

The display effect is as follows:


The source code is as follows:


<?php
//创建一个要新生成的文件名
$string = (string) mt_rand(0, 10000) . &#39;IMG&#39;;

//读取本地图片
$file_path = &#39;./timg.jpg&#39;;

//1. 取出图片数据
$fq_1 = fopen($file_path, &#39;rb&#39;);
$imgData = fread($fq_1, filesize($file_path));
fclose($fp_1);

//2. 写入图片数据
$fp = fopen($string, &#39;wb&#39;);
//$str = fread($fp,filesize($file_path));
fwrite($fp, $imgData);
fclose($fp);

?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
    <img src="./<?php echo $string; ?>" alt="" title="" />
    <img src="./timg.jpg" alt="" title="" />
</body>
</html>


<?php
;?>

The above is the detailed content of How to implement pictures without suffix in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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