username
隱藏欄位username
enctype="multipart/form-data"
is_dir("uploads")
可以判斷是否為資料夾,並用mkdir("uploads")
建立資料夾。LIMIT 0,9
{assign var="cover" value="uploads/thumb_`$article.sn`.jpg"} {if file_exists($cover)} <img src="{$cover}" alt="{$article.title} " class="cover rounded"> {else} <img src="https://picsum.photos/400/300?image={$article@index}" alt="{$article.title} " class="cover rounded"> {/if}
img.cover { width: 100%; height: 200px; object-fit: cover; }
$all[$i]['summary'] = mb_substr(strip_tags($data['content']), 0, 60);
<nav>
的class改為
navbar navbar-expand-md navbar-dark
data-target
需對應下方選單內容
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#menu"> <span class="navbar-toggler-icon"></span> </button>
<a class="navbar-brand" href="index.php"> <img alt="Brand" src="images/logo.png" class="img-fluid"> </a>
<div class="collapse navbar-collapse" id="menu"> 選單 </div>
<div class="navbar-nav mr-auto"></div> <div class="navbar-nav"></div>
<nav>
中加上.sticky-top
.fixed-bottom
來固定住。
<p class="mt-3 d-none d-sm-block">電腦螢幕長頁尾</p> <p class="mt-3 d-block d-sm-none">手機螢幕短頁尾</p>
<div class="footer"></div>
.footer{ margin-top: 120px; }
{if $smarty.session.username==$article.username}管理功能{/if}
class="btn btn-danger"
做成按鈕):
<a href="admin.php?op=delete_article&sn={$article.sn}">刪除</a> <a href="admin.php?op=article_form&sn={$article.sn}">修改</a>
DELETE FROM 資料表 WHERE 條件
AND username='{$_SESSION['username']}'
if (file_exists("uploads/cover_{$sn}.jpg")) { unlink("uploads/cover_{$sn}.jpg"); unlink("uploads/thumb_{$sn}.jpg"); }
$op
值,多一組 article_form
的case
設定,記得帶入$sn
(須先變數過濾),並根據$sn
取出原先填入內容,並塞到樣板檔中。<input type="text" name="xx" {if $article.title}value="{$article.title}"{/if} > <textarea>{if $article.content}{$article.title}{/if}</textarea>
{if $article.sn} <input type="hidden" name="sn" value="{$article.sn}"> <input type="hidden" name="op" value="update"> {else} <input type="hidden" name="op" value="insert"> {/if}
$op
值,多一組update
的case
設定,記得帶入$sn
,並根據$sn
更新內容。UPDATE 資料表 SET 欄1='新值1', 欄2='新值2' WHERE 條件
AND username='{$_SESSION['username']}'