Toggle main menu visibility
新聞
下載
教材
影音
討論
其他選單
好站連結
行事曆
電子相簿
常見問題
萬用表單
即時留言簿
友站消息
社大學員
:::
登入
登入
帳號
密碼
登入
重整畫面
:::
所有書籍
「[981]PHP入門+XOOPS模組設計」目錄
MarkDown
8-1 index.php
1. 相見歡
1-1 index.php 內容
2. PHP與表單
2-1 contact/index.php
3. 讓程式聰明又乾淨
3-1 index.php 原始語法
4. 寫入資料庫
4-1 index.php
5. 撈取資料庫資料
5-1 index.php
6. 把資料庫資料作成列表
6-1 index.php
7. 讓程式套用佈景
7-1 index.php
8. 加入修改刪除功能
8-1 index.php
9. 上傳檔案並做縮圖
9-1 index.php
10. 安裝XOOPS
10-1 index.php
11. XOOPS模組架構
11-1 index.php
11-2 index2.php
12. $xoopsUser應用
12-1 index.php
13. 分頁與搜尋
13-1 include/search.php
13-2 index.php
14. 樣板及評論
14-1 view.php
14-2 index.php
14-3 comment_new.php
15. 製作XOOPS區塊
15-1 blocks/new_contact.php
16. 偏好設定與所見即所得
16-1 view.php
17. 多國語系與圖形驗證
17-1 index.php
17-2 [語系]language/tchinese_utf8/modinfo.php
17-3 [語系]xoops_version.php
17-4 [語系]admin/menu.php
17-5 [sprintf示範]index.php
17-6 [sprintf示範]main.php
18. 模組自動功能
18-1 include/onUninstall.php
18-2 include/onUpdate.php
9-1 index.php
\[981\]PHP入門+XOOPS模組設計 ====================== [](http://120.115.2.76/tad/tad_book3/file/9801/09.zip) ### 一、用PHP上傳檔案 1.若表單中有file元件(用來上傳的元件),其表單編碼(enctype)一定要加上:「enctype="multipart/form-data"」。 2.記得建立一個資料夾,例如:contact\_upload 3.每上傳一張圖(假設file欄位名稱為pic),都會產生一組 $\_FILES 超級全域變數: (1) $\_FILES\['pic'\]\['name'\]:上傳檔案原始名稱。 (2) $\_FILES\['pic'\]\['type'\]:檔案的 MIME 類型,例如“image/gif”。 (3) $\_FILES\['pic'\]\['size'\]:已上傳檔案的大小,單位為bytes。 (4) $\_FILES\['pic'\]\['tmp\_name'\]:檔案被上傳後的臨時檔案名。 (5) $\_FILES\['pic'\]\['error'\]:和該檔案上傳相關的錯誤代碼。 4.上傳的步驟:送出上傳→圖會暫時放到tmp中→程式要搬移該檔到指定的位置。 5.搬移上傳檔方法:move\_uploaded\_file(暫存檔 , 新路徑檔名) ### 二、用class.upload.php來上傳檔案 1.這是一個人家寫好的上傳物件,操作簡單,功能強大!強烈建議使用。 2.手冊:http://www.verot.net/res/sources/class.upload.html
<? include('class/upload/class.upload.php'); $old\_file=\_UPLOAD\_DIR."/{$sn}.png"; if(file\_exists($old\_file)){ unlink($old\_file); } $img\_handle = new upload($\_FILES\['pic'\],"zh\_TW"); if ($img\_handle->uploaded) { $img\_handle->file\_safe\_name = false; $img\_handle->file\_overwrite = true; $img\_handle->file\_new\_name\_body = $sn; $img\_handle->image\_convert = 'png'; $img\_handle->image\_resize = true; $img\_handle->image\_x = 80; $img\_handle->image\_ratio\_y = true; $img\_handle->process(\_UPLOAD\_DIR); if ($img\_handle->processed) { $img\_handle->clean(); } else { die($img\_handle->error); } } ?>
//引入物件檔,路徑請自行修改 //舊檔路徑 //判斷是否已經有舊檔存在 //若存在,刪除該檔案 //將上傳物件實體化 //假如檔案已經上傳到tmp //會把檔名的空白改為「\_」 //強制覆寫相同檔名 //重新設定新檔名 //轉檔為png格式,方便管理 //要重設圖片大小 //設定寬度為80px //按照比例縮放高度 //檔案搬移到目的地 //判斷搬移執行結果 //若搬移成功,則釋放記憶體 //否則 //秀出錯誤訊息。
3.include和include\_once都是用來引入檔案,後者可避免重複引入,故建議用後者。引不到檔案會出現錯誤息,但程式不會停止。 4.require和require\_once也是用來引入檔案,後者可避免重複引入,故建議用後者。引不到檔案會出現錯誤息,而且程式會停止執行。 5.define("常數名稱","值"):定義常數,常數通常前面會加上「\_」並以大寫命名。 6.file\_exists(檔案路徑):檢查檔是否存在 7.unlink(檔案路徑):刪除指定檔案 8.mkdir(目錄):建立資料夾
:::
搜尋
search
進階搜尋
QR Code 區塊
快速登入
所有討論區
「PHP全端開發」線上課程討論區
XOOPS使用討論區
一般研習學員
社大學員專用
路過哈啦區
XOOPS佈景設計
XOOPS模組開發
Tad書籍區
即時留言簿
書籍目錄
展開
|
闔起
線上使用者
69
人線上 (
10
人在瀏覽
線上書籍
)
會員: 0
訪客: 69
更多…