線上書籍

Home

網站程式設計-PHP

一、PHP上傳

  1. 透過表單,將檔案或圖片,上傳至伺服器的暫存區,系統會給一個臨時的檔名
  2. 我們在將該檔移至指定的位置即可

二、表單

  1. 在 form的標籤 加上 「enctype="multipart/form-data"」才能進行上傳檔案
  2. 在 input的 type設成 "file" =>type="file"
  3. input 的屬性 accept="image/*" 則只接受圖檔上傳
    http://www.iana.org/assignments/media-types/media-types.xhtml
  4. 當表單送出後,接收端會產生 $_FILES 超級全域變數
    $_FILES['column']['name']:檔案名稱
    $_FILES['column']['type']:檔案的MIME類型,例如image/gif
    $_FILES['column']['size']:檔案大小
    $_FILES['column']['tmp_name']:暫存檔名稱
    $_FILES['column']['error']:錯誤訊息
  5. move_uploaded_file($_FILES['column']['tmp_name'],"新的位置/檔案名稱")

三、將admin/system.php 的連結放到 /templates/admin/tpl/admin_nav.html

<li><a href="system.php"><i class="fa fa-gear fa-fw"></i> 系統變數管理</a></li>

四、圖片輪播

一、backstretch jquery 套件

  1. 官網:http://srobbin.com/jquery-plugins/backstretch/
  2. 下載:https://raw.githubusercontent.com/srobbin/jquery-backstretch/master/jquery.backstretch.min.js

/templates/default/tpl/creative_header.html

<!--輪播--> <script src="<{$smarty.const.WEB_URL}>/class/backstretch/jquery.backstretch.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('.header').backstretch([ "<{$themeUrl}>/img/1.jpg" , "<{$themeUrl}>/img/header.jpg" ], {duration: 3000, fade: 750}); }); </script>

五、

/function.php

################################# # 輪播圖 # ################################# function slider_home() { global $mysqli, $smarty; #取得所有記錄 $sql = "select files_sn,file_name,sub_dir from `creative_files_center` where `col_name`='system_slider_image' order by `sort` "; //die($sql); $result = $mysqli->query($sql) or die(printf("Error: %s <br>" . $sql, $mysqli->sqlstate)); $rows = array(); while ($row = $result->fetch_assoc()) { #過濾撈出資料 //Array ( [sn] => 3 [ofsn] => 0 [kind] => nav_home [title] => asdfasdf [sort] => 0 [enable] => 1 [url] => asdfasdf [target] => 0 [col_sn] => 0 [content] => ) $row['files_sn'] = intval($row['files_sn']); //http://www.w3school.com.cn/php/func_string_htmlspecialchars.asp $row['file_name'] = htmlspecialchars($row['file_name'], ENT_QUOTES); // 轉換雙引號和單引號 $row['sub_dir'] = htmlspecialchars($row['sub_dir'], ENT_QUOTES); // 轉換雙引號和單引號 $rows[] = $row; } //print_r($rows);die(); $smarty->assign("slider_home", $rows); return; }

/head.php

slider_home();

/templates/default/tpl/creative_header.html

<!--輪播--> <script src="<{$smarty.const.WEB_URL}>/class/backstretch/jquery.backstretch.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('.header').backstretch([ <{foreach from=$slider_home item=row key=i}> <{if $i}>,<{/if}>"<{$smarty.const.WEB_URL}>/uploads/creative/slider/image/<{$row.file_name}>" <{/foreach}> ], {duration: 3000, fade: 750}); }); </script> <header class="header"> <div class="header-content"> <div class="header-content-inner"> <h1 id="homeHeading">Your Favorite Source of Free Bootstrap Themes</h1> <hr> <p>Start Bootstrap can help you build better websites using the Bootstrap CSS framework! Just download your template and start going, no strings attached!</p> <a href="#about" class="btn btn-primary btn-xl page-scroll">Find Out More</a> </div> </div> </header>