How to implement pictures without suffix in PHP

小云云
Release: 2023-03-22 10:18:01
Original
2024 people have browsed it

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
;?>
Copy after login

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!

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!