


PHP photo album function implementation includes PHP image upload, background management, browsing and deletion tutorial examples
The photo album function implementation (including PHP image upload, background management, browsing and deletion) tutorial example includes five parts:
1. Album homepage
<html> <head> <meta charset="utf-8"> <title>相册首页</title> <style><span> body{ width</span>:<span>800px; margin</span>:0<span> auto; test</span>-align:<span>center; } </span></style> </head> <body> <h1>The simple photo album.</h1> <center> <?<span>php </span><span>error_reporting</span>(0<span>); </span><span>if</span>(!<span>$_GET</span>["page"<span>]){ </span><span>$page</span> = 1<span>; }</span><span>else</span><span>$page</span> = <span>$_GET</span>["page"<span>]; </span><span>$filename</span> = "data.dat"<span>; </span><span>$myfile</span> = <span>file</span>(<span>$filename</span><span>); </span><span>$z</span> = <span>$myfile</span>[0<span>]; </span><span>if</span>(<span>$z</span> == <span>NULL</span><span>){ </span><span>echo</span> "目前记录条数为:0"<span>; }</span><span>else</span><span>{ </span><span>$temp</span> = <span>explode</span>("||",<span>$myfile</span>[0<span>]); </span><span>echo</span> "共有".<span>$temp</span>[0]."条内容"<span>; </span><span>echo</span> " "<span>; </span><span>$p_count</span> = <span>ceil</span>(<span>$temp</span>[0]/8<span>); </span><span>echo</span> "分".<span>$_count</span>."页显示"<span>; </span><span>echo</span> " "<span>; </span><span>echo</span> "当前显示第".<span>$page</span>."页"<span>; </span><span>echo</span> " "<span>; </span><span>echo</span> "<br>"<span>; </span><span>if</span>(<span>$page</span> != <span>ceil</span>(<span>$temp</span>[0]/8<span>)){ </span><span>$current_size</span> = 8<span>; }</span><span>else</span><span>{ </span><span>$current_size</span> = <span>$temp</span>[0]%8<span>; } </span><span>if</span>(<span>$current_size</span> == 0<span>){ </span><span>$current_size</span> = 8<span>; } </span><span>for</span>(<span>$i</span>=0;<span>$i</span><<span>ceil</span>(<span>$current_size</span>/4);<span>$i</span>++<span>){ </span><span>for</span>(<span>$j</span>=0;<span>$j</span><4;<span>$j</span>++<span>){ </span><span>$temp</span> = <span>explode</span>("||", <span>$myfile</span>[<span>$i</span>*4+<span>$j</span>+(<span>$page</span>-1)*8<span>]); </span><span>if</span>((<span>$i</span>*4+<span>$j</span>+(<span>$page</span>-1)*8)<<span>$z</span><span>){ </span><span>$imgfile</span> = "./images/".<span>$temp</span>[1<span>]; </span><span>$flag</span> = <span>getimagesize</span>(<span>$imgfile</span><span>); </span><span>echo</span> "<a href=viewimage.php?id=".<span>$temp</span>[0]."><img src=/test/images/".<span>$temp</span>[1<span>]; </span><span>if</span>(<span>$flag</span>[0]>180||<span>$flag</span>[1]>100<span>){ </span><span>echo</span> " width=180 height=".<span>ceil</span>(<span>$flag</span>[1]*180/<span>$flag</span>[0<span>]); } </span><span>echo</span> " border=\"0\"></a>"<span>; }</span><span>else</span><span>{ </span><span>echo</span> ""<span>; } } } </span><span>echo</span> "</table>"<span>; } </span><span>echo</span> "<p>"<span>; </span><span>$prev_page</span> = <span>$page</span> - 1<span>; </span><span>$next_page</span> = <span>$page</span> + 1<span>; </span><span>if</span>(<span>$page</span> <= 1<span>){ </span><span>echo</span> "第一页 | "<span>; }</span><span>else</span><span>{ </span><span>echo</span> "<a href='<span>$PATH_INFO</span>?page=1'>第一页</a> | "<span>; } </span><span>if</span>(<span>$prev_page</span> < 1<span>){ </span><span>echo</span> "上一页 | "<span>; }</span><span>else</span><span>{ </span><span>echo</span> "<a href='<span>$PATH_INFO</span>?page=<span>$prev_page</span>'>上一页</a> | "<span>; } </span><span>if</span>(<span>$next_page</span> > <span>$p_count</span><span>){ </span><span>echo</span> "下一页 | "<span>; }</span><span>else</span><span>{ </span><span>echo</span> "<a href='<span>$PATH_INFO</span>?page=<span>$next_page</span>'>下一页</a> | "<span>; } </span><span>if</span>(<span>$page</span> >= <span>$p_count</span><span>){ </span><span>echo</span> "最后一页</p>\n"<span>; }</span><span>else</span><span>{ </span><span>echo</span> "<a href='<span>$PATH_INFO</span>?page=<span>$p_count</span>'>最后一页</a></p>\n"<span>; } </span>?> </center> <a href="upfile.php">Upload Files</a> </body> </html>
2. Background management
<html> <head> <meta charset="utf-8"> <title>后台处理页面</title> </head> <body> <?<span>php </span><span>error_reporting</span>(1<span>); </span><span>if</span>(<span>$_FILES</span>['upfile']['name'] == <span>NULL</span><span>){ </span><span>echo</span> "No file choice."<span>; </span><span>echo</span> "<a href='upfile.php'>返回</a>"<span>; }</span><span>else</span><span>{ </span><span>$filepath</span> = "/Library/WebServer/Documents/test/images/"<span>; </span><span>$tmp_name</span> = <span>$_FILES</span>['upfile']['tmp_name'<span>]; </span><span>$filename</span> = <span>$filepath</span>.<span>$_FILES</span>['upfile']['name'<span>]; </span><span>//</span><span> echo $filename;</span><span>if</span>(<span>move_uploaded_file</span>(<span>$tmp_name</span>,<span>$filename</span><span>)){ </span><span>$dataname</span> = "data.dat"<span>; </span><span>$myfile</span> = <span>file</span>(<span>$dataname</span><span>); </span><span>if</span>(<span>$myfile</span>[0] == ""<span>){ </span><span>$fp</span> = <span>fopen</span>(<span>$dataname</span>, "a+"<span>); </span><span>fwrite</span>(<span>$fp</span>,"1||".<span>$_FILES</span>['upfile']['name']."||".<span>$_POST</span>["content"]."||".<span>date</span>(Y年m月d日)."\n"<span>); </span><span>fclose</span>(<span>$fp</span><span>); }</span><span>else</span><span>{ </span><span>$temp</span> = <span>explode</span>("||", <span>$myfile</span>[0<span>]); </span><span>$temp</span>[0]++<span>; </span><span>$fp</span> = <span>fopen</span>(<span>$dataname</span>, "r"<span>); </span><span>$line_has</span> = <span>fread</span>(<span>$fp</span>,<span>filesize</span>("<span>$dataname</span>"<span>)); </span><span>fclose</span>(<span>$fp</span><span>); </span><span>$fp</span> = <span>fopen</span>(<span>$dataname</span>, "w"<span>); </span><span>fwrite</span>(<span>$fp</span>,<span>$temp</span>[0]."||".<span>$_FILES</span>['upfile']['name']."||".<span>$_POST</span>["content"]."||".<span>date</span>("Y年m月d日")."\n"<span>); </span><span>fwrite</span>(<span>$fp</span>,"<span>$line_has</span>"<span>); </span><span>fclose</span>(<span>$fp</span><span>); } </span><span>echo</span> "<p></p>"<span>; </span><span>echo</span> "指定文件已经上传成功!"<span>; </span><span>echo</span> "<p></p>"<span>; </span><span>echo</span> "点<a href='index.php'>返回</a>"<span>; }</span><span>else</span><span>{ </span><span>echo</span> "文件上传失败!"<span>; } } </span>?> </body> </html>
3. Picture upload
<html> <head> <meta charset="utf-8"> <title>相册上传页面</title> </head> <body> <script language="javascript"> <span>function</span><span> Juge(theForm){ </span><span>if</span>(theForm.upfile.value==""<span>){ alert(</span>"Please choice file!"<span>); theForm</span>.upfile.<span>focus(); </span><span>return</span> (<span>false</span><span>); } </span><span>if</span>(theForm.content.value==""<span>){ alert(</span>"Please input image information!"<span>); theForm</span>.content.<span>focus(); </span><span>return</span> (<span>false</span><span>); } </span><span>if</span>(theForm.content.value.length>60<span>){ alert(</span>"The information must less than 60 chars."<span>); theForm</span>.content.<span>focus(); </span><span>return</span> (<span>false</span><span>); } } </span></script> <center> <h1>Image album upload page</h1> <p> <a href="index.php">返回首页</a> <table border="1"> <form enctype="multipart/form-data" action="system.php" method="post" type="file"></td> </tr> <tr> <td>输入说明:</td> <td><input name="content" type="text">(*限30字)</td> </tr> <tr> <td colspan="2"> <center> <input type="submit" value="提交"> <input type="reset" value="重置"> </center> </td> </tr> </form> </table> </p> </center> </body> </html>
4. Picture browsing
<html> <head> <meta charset="utf-8"> <title>查看图片</title> </head> <body> <center> <h1>View images.</h1> <?<span>php </span><span>error_reporting</span>(0<span>); </span><span>if</span>(!<span>$_GET</span>["id"<span>]){ </span><span>echo</span> "No assign id."<span>; </span><span>echo</span> "<a href='index.php'>首页</a>"<span>; </span><span>exit</span><span>(); }</span><span>else</span><span>{ </span>?> <a href="index.php">返回首页</a> &<span>nbsp; </span><a href="delimage.php?id=<?php echo <span>$_GET</span>['id'] ?>">删除图片</a><br> <?<span>php </span><span>$id</span> = <span>$_GET</span>["id"<span>]; </span><span>$filename</span> = "data.dat"<span>; </span><span>$myfile</span> = <span>file</span>(<span>$filename</span><span>); </span><span>$z</span> = <span>$myfile</span>[0<span>]; </span><span>if</span>(<span>$z</span> == ""<span>){ </span><span>echo</span> "目前记录条数为0"<span>; }</span><span>else</span><span>{ </span><span>$temp</span> = <span>explode</span>("||", <span>$myfile</span>[<span>$z</span>-<span>$id</span><span>]); </span><span>echo</span> "<p>"."文件名:".<span>$temp</span>[1]."</p>"<span>; </span><span>echo</span> "<p><img src=/test/images/".<span>$temp</span>[1]."></p>"<span>; </span><span>echo</span> "<p>图片简介:".<span>$temp</span>[2]."</p>"<span>; </span><span>echo</span> "<p>上传日期:".<span>$temp</span>[3]."</p>"<span>; } } </span>?> </center> </body> </html>
5. Delete pictures
<html> <head> <meta charset="utf-8"> <title>删除图片</title> </head> <body> <?<span>php </span><span>error_reporting</span>(0<span>); </span><span>if</span>(!<span>$_GET</span>["id"<span>]){ </span><span>echo</span> "No id assign."<span>; </span><span>echo</span> "<br>"<span>; </span><span>echo</span> "<a href='index.php'>首页</a>"<span>; </span><span>exit</span><span>(); }</span><span>else</span><span>{ </span><span>$id</span> = <span>$_GET</span>["id"<span>]; </span><span>$filename</span> = "data.dat"<span>; </span><span>$myfile</span> = <span>file</span>(<span>$filename</span><span>); </span><span>$z</span> = <span>$myfile</span>[0<span>]; </span><span>if</span>(<span>$z</span> == <span>NULL</span><span>){ </span><span>echo</span> "目前记录条数为:0"<span>; }</span><span>else</span><span>{ </span><span>$temp</span> = <span>explode</span>("||", <span>$myfile</span>[<span>$z</span>-<span>$id</span><span>]); </span><span>print_r</span>(<span>$temp</span><span>); </span><span>$filepath</span> = "/Library/WebServer/Documents/test/images/"<span>; </span><span>$imgfile</span> = <span>$filepath</span>.<span>$temp</span>[1<span>]; </span><span>echo</span><span>$imgfile</span><span>; </span><span>unlink</span>(<span>$imgfile</span><span>); </span><span>for</span>(<span>$i</span>=0;<span>$i</span><(<span>$z</span>-<span>$id</span>);<span>$i</span>++<span>){ </span><span>$temp2</span> = <span>explode</span>("||", <span>$myfile</span>[<span>$i</span><span>]); </span><span>$temp2</span>[0]--<span>; </span><span>if</span>(<span>$temp2</span>[0]>0<span>) </span><span>$text2</span> = <span>$text2</span>.<span>$temp2</span>[0]."||".<span>$temp2</span>[1]."||".<span>$temp2</span>[2]."||".<span>$temp2</span>[3<span>]; } </span><span>for</span>(<span>$i</span>=(<span>$z</span>-<span>$id</span>+1);<span>$i</span><<span>$z</span>;<span>$i</span>++<span>){ </span><span>$text1</span> = <span>$text1</span>.<span>$myfile</span>[<span>$i</span><span>]; } </span><span>$fp</span> = <span>fopen</span>(<span>$filename</span>, "w"<span>); </span><span>fwrite</span>(<span>$fp</span>, <span>$text2</span><span>); </span><span>fwrite</span>(<span>$fp</span>, <span>$text1</span><span>); </span><span>fclose</span>(<span>$fp</span><span>); </span><span>echo</span> "指定文件已经删除成功!"<span>; </span><span>echo</span> "<a href='index.php'>首页</a>"<span>; } } </span>?> </body> </html>
The above has introduced the implementation of the PHP photo album function, including PHP image uploading, background management, browsing and deletion tutorial examples, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

The temp folder is our temporary file storage location. The system will save temporary files to this folder. If there are too many temporary files, especially when the temp folder is on the system disk, it is likely to affect the system running speed. We can solve the problem by changing the temp location. Let’s take a look below. Tutorial on changing the location of win7temp 1. First, right-click "Computer" and open "Properties" 2. Click "Advanced System Settings" on the left 3. Click "Environment Variables" below 4. Select "temp" and click "Edit" 5. Then change Just change the "Variable Value" to the path that needs to be changed.

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps
![How to Fix Processor Thermal Trip Error in Windows 11/10 [Fix]](https://img.php.cn/upload/article/000/000/164/168169038621890.png?x-oss-process=image/resize,m_fill,h_207,w_330)
Most of the devices, such as laptops and desktops, have been heavily used by young gamers and coders for a long time. The system sometimes hangs due to application overload. This forces users to shut down their systems. This mainly happens to players who install and play heavy games. When the system tries to boot after force shutdown, it throws an error on a black screen as shown below: Below are the warnings detected during this boot. These can be viewed in the settings on the event log page. Warning: Processor thermal trip. Press any key to continue. ..These types of warning messages are always thrown when the processor temperature of a desktop or laptop exceeds its threshold temperature. Listed below are the reasons why this happens on Windows systems. Many heavy applications are in

In today's era of rapid technological development, programming languages are springing up like mushrooms after a rain. One of the languages that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated
![Internal error: Unable to create temporary directory [Resolved]](https://img.php.cn/upload/article/000/000/164/168171504798267.png?x-oss-process=image/resize,m_fill,h_207,w_330)
Windows system allows users to install various types of applications on your system using executable/setup files. Recently, many Windows users have started complaining that they are receiving an error named INTERNALERROR:cannotCreateTemporaryDirectory on their systems while trying to install any application using an executable file. The problem is not limited to this but also prevents the users from launching any existing applications, which are also installed on the Windows system. Some possible reasons are listed below. Run the executable to install without granting administrator privileges. An invalid or different path was provided for the TMP variable. damaged system

temp is a temporary folder. In the path "C:\Documents and Settings\Administrator\Local Settings\", many temporary files are placed here, including favorites, temporary files for browsing web pages, editing files, etc.

In computers, temp means "temporary folder", which contains many temporary files; its function is to temporarily save the user's work results in the application to prevent losses caused by accidents. Deleting temp files can free up hard disk storage space, but it will be slower to open the application for the first time after deletion.
