:::
所有書籍
「[1032]PHP入門」目錄
MarkDown
7-6 eznews.sql
1. PHP開發環境與表單
1-1 post.php
1-2 index.php
2. 邏輯判斷及樣板引擎
2-1 index.php
2-2 post.php
2-3 index_tpl.html
3. MySQL的資料存取
3-1 index.php
3-2 post.php
3-3 post_tpl.html
3-4 eznews.sql
4. PHP函數與引入
4-1 post.php
4-2 index.php
4-3 list_tpl.html
4-4 function.php
5. 編輯與刪除資料
5-1 index.php
5-2 list_tpl.html
5-3 post.php
5-4 config.php
5-5 function.php
5-6 post_tpl.html
6. BootStrap各式應用
6-1 post.php
6-2 list_tpl.html
6-3 post_tpl.html
6-4 index.php
7. 置頂、計數器與 join
7-1 post.php
7-2 post_tpl.html
7-3 index.php
7-4 list_tpl.html
7-5 function.php
7-6 eznews.sql
8. 上傳與分頁
8-1 post.php
8-2 index.php
8-3 config.php
8-4 post_tpl.html
8-5 eznews.sql
9. 身份認證機制
9-1 eznews.sql
9-2 post_tpl.html
9-3 list_tpl.html
9-4 config.php
9-5 index.php
9-6 post.php
8-1 post.php
\[1032\]PHP入門 ============= [](http://www.tad0616.net/uploads/tad_book3/file/1032/08.zip) ### 一、 關於上傳 1. 若表單中有file元件(用來上傳的元件),其表單編碼(enctype)一定要加上: ``` <pre class="brush:xml;"> enctype="multipart/form-data" ``` 2. 記得建立一個資料夾,例如:uploads(linux下權限記得設定為777) 3. 每上傳一個附檔(假設file欄位名稱為file),都會產生一組 $\_FILES 超級全域變數: - (1) $\_FILES\['file'\]\['name'\]:上傳檔案原始名稱。 - (2) $\_FILES\['file'\]\['type'\]:檔案的 MIME 類型,例如“image/gif”。 - (3) $\_FILES\['file'\]\['size'\]:已上傳檔案的大小,單位為bytes。 - (4) $\_FILES\['file'\]\['tmp\_name'\]:檔案被上傳後的臨時檔案名。 - (5) $\_FILES\['file'\]\['error'\]:和該檔案上傳相關的錯誤代碼。 4. 上傳的步驟:送出上傳→檔案會暫時放到tmp中→程式要搬移該檔到指定的位置。 5. 搬移上傳檔方法:move\_uploaded\_file(暫存檔 , 新路徑檔名) ### 二、 中文檔名的問題 1. 在windows下,中文檔名是用Big5儲存,若網站是UTF-8編碼,會無法下載。 2. 一般解決方式有幾種: - (1) 無視之,或請使用者盡量安裝在Linux環境,或者告知僅支援英文數字檔名。 - (2) 上傳時,強制轉換成英文數字檔名。下載時,有三種作法: - a. 下載時即時產生檔案,此法若遇到大檔就不適合。 - b. 將英文檔名複製另一份並改為中文檔名(看平台來選擇適當編碼存檔) - c. 最後一種就是什麼都不處理,直接用英文數字存檔,最簡單。 3. 若要改成英文數字檔名,可用新聞序號為主檔名,從資料夾觀看時會比較容易辨識;並搭配順序或亂數產生其餘檔名,以避免檔名重複。 4. 取得附檔名的方法:(詳見:<http://liaosankai.pixnet.net/blog/post/27533126-php-%E5%8F%96%E5%BE%97%E6%AA%94%E6%A1%88%E7%9A%84%E5%89%AF%E6%AA%94%E5%90%8D%28php-get-file-extension%29>) ``` <pre class="brush:php;"> $ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION); ``` ### 三、 上傳多個檔案 1. file欄位要加上multiple始可多選,name要加上\[\],使之變成陣列,例如: ``` <pre class="brush:xml;"> <input type="file" name="file[]" multiple> ``` 2. 上傳後,陣列會像這樣:$\_FILES\['file'\]\['name'\]\[0\]、$\_FILES\['file'\]\['name'\]\[1\] ### 四、 建立檔案資料表eznews\_files  ### 五、 分頁工具 1. 請將PageBar.php引入,並在$sql和mysql\_query($sql);之間插入以下語法: ``` <pre class="brush:php;"> $PageBar = new PageBar($sql, 10); $bar_arr=$PageBar->makeBar(); $sql=$bar_arr['sql']; $bar=$bar_arr['bar']; ``` 2. 將$bar放到適當位置,這就是分頁工具(BootStrap3版)。
:::
搜尋
search
進階搜尋
QR Code 區塊
快速登入
所有討論區
「PHP全端開發」線上課程討論區
XOOPS使用討論區
一般研習學員
社大學員專用
路過哈啦區
XOOPS佈景設計
XOOPS模組開發
Tad書籍區
即時留言簿
書籍目錄
總目錄
1.PHP開發環境與表單
1-1post.php
1-2index.php
2.邏輯判斷及樣板引擎
2-1index.php
2-2post.php
2-3index_tpl.html
3.MySQL的資料存取
3-1index.php
3-2post.php
3-3post_tpl.html
3-4eznews.sql
4.PHP函數與引入
4-1post.php
4-2index.php
4-3list_tpl.html
4-4function.php
5.編輯與刪除資料
5-1index.php
5-2list_tpl.html
5-3post.php
5-4config.php
5-5function.php
5-6post_tpl.html
6.BootStrap各式應用
6-1post.php
6-2list_tpl.html
6-3post_tpl.html
6-4index.php
7.置頂、計數器與 join
7-1post.php
7-2post_tpl.html
7-3index.php
7-4list_tpl.html
7-5function.php
7-6eznews.sql
8.上傳與分頁
8-1post.php
8-2index.php
8-3config.php
8-4post_tpl.html
8-5eznews.sql
9.身份認證機制
9-1eznews.sql
9-2post_tpl.html
9-3list_tpl.html
9-4config.php
9-5index.php
9-6post.php
展開
|
闔起
線上使用者
55
人線上 (
7
人在瀏覽
線上書籍
)
會員: 0
訪客: 55
更多…
:::
主選單
NTPC OpenID
活動報名
模組控制台
進階區塊管理
站長工具箱(急救版)
網站地圖
Tad Tools 工具包
站長工具箱
行事曆
討論留言
嵌入區塊模組
快速登入
網站計數器
好站連結
最新消息
檔案下載
線上書籍
電子相簿
影音播放
常見問題
萬用表單
友站消息
社大學員
新聞
下載
教材
影音
討論
其他選單
好站連結
行事曆
電子相簿
常見問題
萬用表單
即時留言簿
友站消息
社大學員
登入
登入
帳號
密碼
登入