php相册功能的实现方法:1、创建相册首页并实现分页效果;2、创建后台处理页面;3、实现相册上传页面;4、定义图片浏览功能;5、通过“unlink($imgfile);”等语句实现删除图片功能即可。
本文操作环境:Windows7系统、PHP7.1版、DELL G3电脑
php相册功能怎么实现?
相册功能实现(包含php图片上传,后台管理,浏览和删除)教程例子包括五个部分:
一、相册首页
立即学习“PHP免费学习笔记(深入)”;
相册首页 body{ width:800px; margin:0 auto; test-align:center; }The simple photo album.
<?php error_reporting(0); if(!$_GET["page"]){ $page = 1; }else $page = $_GET["page"]; $filename = "data.dat"; $myfile = file($filename); $z = $myfile[0]; if($z == NULL){ echo "目前记录条数为:0"; }else{ $temp = explode("||",$myfile[0]); echo "共有".$temp[0]."条内容"; echo " "; $p_count = ceil($temp[0]/8); echo "分".$_count."页显示"; echo " "; echo "当前显示第".$page."页"; echo " "; echo "
"; if($page != ceil($temp[0]/8)){ $current_size = 8; }else{ $current_size = $temp[0]%8; } if($current_size == 0){ $current_size = 8; } for($i=0;$i180||$flag[1]>100){ echo " width=180 height=".ceil($flag[1]*180/$flag[0]); } echo " border="0">"; }else{ echo ""; } } } echo ""; } echo "
"; $prev_page = $page - 1; $next_page = $page + 1; if($page 第一页 | "; } if($prev_page 上一页 | "; } if($next_page > $p_count){ echo "下一页 | "; }else{ echo "下一页 | "; } if($page >= $p_count){ echo "最后一页
"; }else{ echo "最后一页"; } ?> Upload Files
登录后复制
二、后台管理
后台处理页面 <?php error_reporting(1); if($_FILES['upfile']['name'] == NULL){ echo "No file choice."; echo "返回"; }else{ $filepath = "/Library/WebServer/Documents/test/images/"; $tmp_name = $_FILES['upfile']['tmp_name']; $filename = $filepath.$_FILES['upfile']['name'];// echo $filename; if(move_uploaded_file($tmp_name,$filename)){ $dataname = "data.dat"; $myfile = file($dataname); if($myfile[0] == ""){ $fp = fopen($dataname, "a+"); fwrite($fp,"1||".$_FILES['upfile']['name']."||".$_POST["content"]."||".date(Y年m月d日).""); fclose($fp); }else{ $temp = explode("||", $myfile[0]); $temp[0]++; $fp = fopen($dataname, "r"); $line_has = fread($fp,filesize("$dataname")); fclose($fp); $fp = fopen($dataname, "w"); fwrite($fp,$temp[0]."||".$_FILES['upfile']['name']."||".$_POST["content"]."||".date("Y年m月d日").""); fwrite($fp,"$line_has"); fclose($fp); } echo ""; echo "指定文件已经上传成功!"; echo ""; echo "点返回"; }else{ echo "文件上传失败!"; } }?>
登录后复制
三、图片上传
相册上传页面 function Juge(theForm){ if(theForm.upfile.value==""){ alert("Please choice file!"); theForm.upfile.focus(); return (false); } if(theForm.content.value==""){ alert("Please input image information!"); theForm.content.focus(); return (false); } if(theForm.content.value.length>60){ alert("The information must less than 60 chars."); theForm.content.focus(); return (false); } }Image album upload page
选择图片: | |
输入说明: | (*限30字) |
登录后复制
四、图片浏览
查看图片 View images.
<?php error_reporting(0); if(!$_GET["id"]){ echo "No assign id."; echo "首页"; exit(); }else{ ?> 返回首页 ">删除图片
<?php $id = $_GET["id"]; $filename = "data.dat"; $myfile = file($filename); $z = $myfile[0]; if($z == ""){ echo "目前记录条数为0"; }else{ $temp = explode("||", $myfile[$z-$id]); echo ""."文件名:".$temp[1].""; echo "
"; echo "图片简介:".$temp[2]."
"; echo "上传日期:".$temp[3]."
"; } } ?>
登录后复制
五、删除图片
删除图片 <?php error_reporting(0); if(!$_GET["id"]){ echo "No id assign."; echo "
"; echo "首页"; exit(); }else{ $id = $_GET["id"]; $filename = "data.dat"; $myfile = file($filename); $z = $myfile[0]; if($z == NULL){ echo "目前记录条数为:0"; }else{ $temp = explode("||", $myfile[$z-$id]); print_r($temp); $filepath = "/Library/WebServer/Documents/test/images/"; $imgfile = $filepath.$temp[1]; echo $imgfile; unlink($imgfile); for($i=0;$i0) $text2 = $text2.$temp2[0]."||".$temp2[1]."||".$temp2[2]."||".$temp2[3]; } for($i=($z-$id+1);$i首页"; } }?>
登录后复制
推荐学习:《PHP视频教程》
以上就是php相册功能怎么实现的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2092085.html