Heim  >  Artikel  >  Backend-Entwicklung  >  Smarty-Dateianzeige in PHP

Smarty-Dateianzeige in PHP

墨辰丷
墨辰丷Original
2018-05-15 17:21:221791Durchsuche

Dieser Artikel stellt hauptsächlich die Dateianzeige von Smarty in PHP vor. Ich hoffe, dass er für alle hilfreich ist.

Erstellen Sie zunächst ein einfaches Formular

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="insert.php" method="post" enctype="multipart/form-data">
<center>
<table>
<tr>
<td>账号</td>
<td><input type="text" name="aa"></td>
</tr>
<tr>
<td>密码</td>
<td><input type="text" name="bb"></td>
</tr>
<tr>
<td>文件</td>
<td><input type="file" name="img"></td>
</tr>
<tr>
<td><input type="submit" value="添加"></td>
</tr>
</table>
</center>
</form>
</body>
</html>


Hinzufügen Zur Hinzufügen-Seite springen

<?php 
header("content-type:text/html;charset=utf-8");include ("./DB.class.php");                                                                      //引入自己的增删改查封装并且进行文件移动$d= new DB("127.0.0.1","root","root","user");                                       //实例化入库选库 并传参$p3=new SC();                 //实例化添加类
$res=$p3->say($_POST,$_FILES,&#39;img&#39;,"images/",&#39;image&#39;);                   //1参数为上传的文本信息,2参数为上传图片信息,                                                                                                                   3 参数为图片的name名,4参数为移动文件目录,5参             
                                                                                                         数为添加到的数据表。
if ($res) {echo "<script>alert(&#39;上传成功&#39;);location.href=&#39;index.php&#39;</script>";//成功则自动跳转查询页面}else{echo "<script>alert(&#39;上传失败&#39;);location.href=&#39;form.php&#39;</script>";//失败则自动跳转form表单}
 ?>

Abfrageseite

<?php 
header("content-type:text/html;charset=utf-8");
include ("./DB.class.php");                                                        //引入文件
$d= new DB("127.0.0.1","root","root","user");
$p7=new F;         //实例化类
$aa=isset($_GET[&#39;aa&#39;])?$_GET[&#39;aa&#39;]:"";     //三元运算符进行判断页数是否为空
$data=$p7->say(&#39;bb&#39;,&#39;2&#39;,$aa);        //三个值分别为表名 分页每页的个数 和查询的值
$shang=$p7->shang;        //获取上一页的变量 
$xia=$p7->xia;          //获取下一页的变量
$wei=$p7->wei;           //获取尾wei页的变量
include ("libs/Smarty.class.php");      //引入Smarty文件
$ok = new Smarty;
$ok->assign("aa",$aa);
$ok->assign("shang",$shang);
$ok->assign("xia",$xia);
$ok->assign("wei",$wei);
$ok->assign("list",$data);       //指向并赋值
$ok->display("show.php");      
 //指向的页面
?>

Anzeige- und Suchseite

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>展示</title>
</head>
<body>
<form action="index.php" method="get">
<table>
<tr>
<td colspan="2" align="center"><input type="text" name="aa"><input type="submit" value="搜索"></td>
</tr>
<tr>
<td>id</td>
<td>name</td>
<td>pwd</td>
<td>img</td>
</tr>
{section loop=$list name=l}
<tr>
<td>{$list[l].id}</td>
<td>{$list[l].aa}</td>
<td>{$list[l].bb}</td>
<td><img src="{$list[l].img}" alt="" height="50" width="60"> </td>
{if {$list[l].ll} eq 1}
<td><a href="up.php?id={$list[l].id}&ll=0">上架</a></td>
{else}
<td><a href="up.php?id={$list[l].id}&ll=1">下架</a></td>
{/if}
<td><a href="del.php?id={$list[l].id}">删除</a></td>
</tr>
{/section}
<tr>
<td><a href="index.php?page=1&aa={$aa}">首页</a></td>
<td><a href="index.php?page={$shang}&aa={$aa}">上一页</a></td>
<td><a href="index.php?page={$xia}&aa={$aa}">下一页</a></td>
<td><a href="index.php?page={$wei}&aa={$aa}">为页</a></td>
</tr>
</table>
</form>
</body>
</html>

Verwandte Empfehlungen:

Weiterführende Hinweise zu Smarty in PHP

Konfigurationsdateidaten und gespeicherte Daten der Smarty-Vorlagen-Engine

In PHP integrierter Smarty im Detail Erläuterungen zur Funktion enthalten

Das obige ist der detaillierte Inhalt vonSmarty-Dateianzeige in PHP. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn