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) . 'IMG'; //读取本地图片 $file_path = './timg.jpg'; //1. 取出图片数据 $fq_1 = fopen($file_path, 'rb'); $imgData = fread($fq_1, filesize($file_path)); fclose($fp_1); //2. 写入图片数据 $fp = fopen($string, 'wb'); //$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!