:::
所有書籍
「[1012]PHP進階開發及TadTools工具應用」目錄
MarkDown
7-1 上課範例:admin/index.php
1. jQuery的用法
1-1 上課範例:index.html
2. 連動選單
2-1 上課範例:admin/index.php
2-2 上課範例:admin/ajax.php
3. 郵遞區號地址
3-1 上課範例:admin/index.php
3-2 上課範例:index.php
3-3 上課範例:ajax.php
4. 點擊編輯
4-1 上課範例:index.html
4-2 上課範例:save.php
4-3 上課範例:admin/index.php
4-4 上課範例:admin/save.php
5. 表單驗證
5-1 上課範例:admin/index.php
5-2 上課範例:index.php
5-3 上課範例:ajax.php
6. 表格拉動排序
6-1 上課範例:admin/cate.php
6-2 上課範例:admin/save_sort.php
7. 整合型上傳工具
7-1 上課範例:admin/index.php
7-2 上課範例:up_file.php
7-3 上課範例:index.php
8. 頁籤與小月曆之應用
8-1 上課範例:admin/index.php
8-2 上課範例:index.php
8-3 上課範例:ajax2.php
9. fullcalendar月曆應用
9-1 上課範例:birthday.php
9-2 上課範例:header.php
9-3 上課範例:get_events.php
10. QR Code應用
10-1 上課範例:xoops_version.php
10-2 上課範例:blocks/contact_qrcode.php
10-3 上課範例:templates/blocks/contact_qrcode.html
10-4 上課範例:pda.php
10-5 上課範例:blocks/contact_qrcode.php(不替換網址)
10-6 上課範例:index.php
11. Jquery Mobile
11-1 上課範例:blocks/contact_qrcode.php
11-2 上課範例:pda.php
11-3 上課範例:data.php
12. java上傳及影片播放
12-1 上課範例:data.php
12-2 上課範例:index.php
12-3 上課範例:jupload.php
12-4 上課範例:play.php
13. CSV的匯出與匯入
13-1 上課範例:通訊錄.csv
13-2 上課範例:admin/index.php
13-3 上課範例:__fgetcsv()
14. 產生Excel報表
14-1 上課範例:admin/excel.php
14-2 上課範例:admin/index.php
14-3 上課範例:admin/excel.php(多表)
15. 匯入Excel檔
15-1 上課範例:admin/excel.php
15-2 上課範例:admin/index.php
16. 用TCPDF產生PDF(上)
16-1 上課範例:admin/index.php
16-2 上課範例:admin/pdf.php
17. 用TCPDF產生PDF(下)
17-1 上課範例:admin/index.php
17-2 上課範例:admin/pdf2.php
17-3 上課範例:admin/pdf_all.php
18. 產出真實word檔
18-1 上課範例:admin/index.php
18-2 上課範例:admin/docx.php
7-3 上課範例:index.php
\[1012\]PHP進階開發及TadTools工具應用 ============================ ``` <pre class="brush: php;" title="code"> <?php //version 1.0 //2012-10-18 //設定模組目錄名稱 define("_MODDIR","contact"); /* include_once("up_file.php"); 表單: enctype='multipart/form-data' <script src='" . TADTOOLS_URL . "/jquery/jquery.js'></script> <script src='" . TADTOOLS_URL . "/multiple-file-upload/jquery.MultiFile.js'></script> <input type='file' name='upfile[]' class='multi' maxlength='1' accept='gif|jpg|png|GIF|JPG|PNG'>".list_del_file("news_sn", $news_sn)." 儲存:upload_file($col_name, $col_sn, $width); 顯示:show_files($col_name, $col_sn,true,false,false,false); //是否縮圖 , 顯示模式 filename、num , 顯示描述 , 顯示下載次數 單一相片:get_pic_file($col_name="", $col_sn="", $name="" , $sort="", $showkind="images") 刪除:del_files($files_sn, $col_name, $col_sn); 檔案數量:get_file_amount($col_name="", $col_sn=""); 種類:img,file 資料表: CREATE TABLE `files_center` ( `files_sn` smallint(5) unsigned NOT NULL AUTO_INCREMENT COMMENT '檔案流水號', `col_name` varchar(255) NOT NULL COMMENT '欄位名稱', `col_sn` smallint(5) unsigned NOT NULL COMMENT '欄位編號', `sort` smallint(5) unsigned NOT NULL COMMENT '排序', `kind` enum('img' , 'file') NOT NULL COMMENT '檔案種類', `file_name` varchar(255) NOT NULL COMMENT '檔案名稱', `file_type` varchar(255) NOT NULL COMMENT '檔案類型', `file_size` int(10) unsigned NOT NULL COMMENT '檔案大小', `description` text NOT NULL COMMENT '檔案說明', `counter` mediumint(8) unsigned NOT NULL COMMENT '下載人次', PRIMARY KEY (`files_sn`) ) ENGINE=MyISAM COMMENT='檔案資料表'; */ //檔案中心實體位置 define("_FILES_CENTER_DIR",XOOPS_ROOT_PATH."/uploads/"._MODDIR . "/file"); define("_FILES_CENTER_URL",XOOPS_URL."/uploads/"._MODDIR . "/file"); //檔案中心圖片實體位置 define("_FILES_CENTER_IMAGE_DIR",XOOPS_ROOT_PATH."/uploads/"._MODDIR . "/image"); define("_FILES_CENTER_IMAGE_URL",XOOPS_URL."/uploads/"._MODDIR . "/image"); //檔案中心縮圖實體位置 define("_FILES_CENTER_THUMB_DIR",XOOPS_ROOT_PATH."/uploads/"._MODDIR . "/image/.thumbs"); define("_FILES_CENTER_THUMB_URL",XOOPS_URL."/uploads/"._MODDIR . "/image/.thumbs"); //上傳圖檔,$col_name=對應欄位名稱, $col_sn=對應欄位編號, $種類:img,file, $sort=圖片排序, $files_sn="更新編號" function upload_file($col_name="", $col_sn="", $main_width="",$upfile='upfile', $sort="", $thumb_width="90", $files_sn=""){ global $xoopsDB, $xoopsUser, $xoopsModule; //引入上傳物件 include_once TADTOOLS_PATH."/upload/class.upload.php"; //取消上傳時間限制 set_time_limit(0); //設置上傳大小 ini_set('memory_limit', '80M'); //刪除勾選檔案 if(!empty($_POST['del_file'])){ foreach($_POST['del_file'] as $del_files_sn){ del_files($del_files_sn); } } $files = array(); foreach ($_FILES[$upfile] as $k => $l) { foreach ($l as $i => $v) { if (!array_key_exists($i, $files)){ $files[$i] = array(); } $files[$i][$k] = $v; } } foreach ($files as $file) { //先刪除舊檔 if(!empty($files_sn)){ del_files($files_sn); } //自動排序 if(empty($sort)){ $sort=auto_sort($col_name, $col_sn); } //取得檔案 $file_handle = new upload($file,"zh_TW"); if ($file_handle->uploaded) { //取得副檔名 $ext=strtolower($file_handle->file_src_name_ext); //判斷檔案種類 if($ext=="jpg" or $ext=="jpeg" or $ext=="png" or $ext=="gif"){ $kind="img"; }else{ $kind="file"; } $file_handle->file_safe_name = false; $file_handle->file_overwrite = true; $file_handle->file_new_name_body = "{$col_name}_{$col_sn}_{$sort}"; //若是圖片才縮圖 if($kind=="img"){ if($file_handle->image_src_x > $main_width){ $file_handle->image_resize = true; $file_handle->image_x = $main_width; $file_handle->image_ratio_y = true; } } $path=($kind=="img")?_FILES_CENTER_IMAGE_DIR:_FILES_CENTER_DIR; $file_handle->process($path); $file_handle->auto_create_dir = true; //若是圖片才製作小縮圖 if($kind=="img"){ $file_handle->file_safe_name = false; $file_handle->file_overwrite = true; $file_handle->file_new_name_body = "{$col_name}_{$col_sn}_{$sort}"; if($file_handle->image_src_x > $thumb_width){ $file_handle->image_resize = true; $file_handle->image_x = $thumb_width; $file_handle->image_ratio_y = true; } $file_handle->process(_FILES_CENTER_THUMB_DIR); $file_handle->auto_create_dir = true; } //上傳檔案 if ($file_handle->processed) { $file_handle->clean(); $file_name="{$col_name}_{$col_sn}_{$sort}.{$ext}"; if(empty($files_sn)){ $sql = "insert into ".$xoopsDB->prefix(_MODDIR . "_files_center")." (`col_name` , `col_sn` , `sort` , `kind` , `file_name` , `file_type` , `file_size` , `description`) values('$col_name' , '$col_sn' , '$sort' , '{$kind}' , '{$file_name}' , '{$file['type']}' , '{$file['size']}' , '{$file['name']}')"; $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error()); }else{ $sql = "replace into ".$xoopsDB->prefix(_MODDIR . "_files_center")." (`files_sn` , `col_name` , `col_sn` , `sort` , `kind` , `file_name` , `file_type` , `file_size` , `description`) values('{$files_sn}' , '$col_name' , '$col_sn' , '$sort' , '{$kind}' , '{$file_name}' , '{$file['type']}' , '{$file['size']}' , '{$file['name']}')"; $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error()); } } else { redirect_header($_SERVER['PHP_SELF'],3, "Error:".$file_handle->error); } } $sort=""; } } //刪除實體檔案 function del_files($files_sn="", $col_name="", $col_sn="", $sort=""){ global $xoopsDB, $xoopsUser; if(!empty($files_sn)){ $del_what="`files_sn`='{$files_sn}'"; }elseif(!empty($col_name) and !empty($col_sn)){ $and_sort=(empty($sort))?"":"and `sort`='{$sort}'"; $del_what="`col_name`='{$col_name}' and `col_sn`='{$col_sn}' $and_sort"; } $sql = "select * from ".$xoopsDB->prefix(_MODDIR . "_files_center")." where $del_what"; $result=$xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error()."<br>".$sql); while(list($files_sn, $col_name, $col_sn, $sort, $kind, $file_name, $file_type, $file_size, $description)=$xoopsDB->fetchRow($result)){ $del_sql = "delete from ".$xoopsDB->prefix(_MODDIR . "_files_center")." where files_sn='{$files_sn}'"; $xoopsDB->queryF($del_sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error()); if($kind=="img"){ unlink(_FILES_CENTER_IMAGE_DIR . "/$file_name"); unlink(_FILES_CENTER_THUMB_DIR . "/$file_name"); }else{ unlink(_FILES_CENTER_DIR . "/$file_name"); } } } //取得檔案 $kind=images(大圖),thumb(小圖),$mode=link(完整連結)or array(路徑陣列) function get_file($col_name="", $col_sn="", $sort=""){ global $xoopsDB, $xoopsUser, $xoopsModule; $and_sort=(!empty($sort))?" and `sort`='{$sort}'":""; $sql = "select * from ".$xoopsDB->prefix(_MODDIR . "_files_center")." where `col_name`='{$col_name}' and `col_sn`='{$col_sn}' $and_sort order by sort"; $result=$xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error()); while($all=$xoopsDB->fetchArray($result)){ //以下會產生這些變數: $files_sn, $col_name, $col_sn, $sort, $kind, $file_name, $file_type, $file_size, $description foreach($all as $k=>$v){ $$k=$v; } $files[$files_sn]['kind']=$kind; $files[$files_sn]['sort']=$sort; $files[$files_sn]['file_name']=$file_name; $files[$files_sn]['file_type']=$file_type; $files[$files_sn]['file_size']=$file_size; $files[$files_sn]['counter']=$counter; $files[$files_sn]['description']=$description; if($kind=="img"){ $pic_name=(file_exists(_FILES_CENTER_IMAGE_DIR . "/{$file_name}"))?_FILES_CENTER_IMAGE_URL."/{$file_name}":TADTOOLS_URL."/multiple-file-upload/no_thumb.gif"; $thumb_pic=(file_exists(_FILES_CENTER_THUMB_DIR . "/{$file_name}"))?_FILES_CENTER_THUMB_URL."/{$file_name}":TADTOOLS_URL."/multiple-file-upload/no_thumb.gif"; $files[$files_sn]['link']="<a href='{$_SERVER['PHP_SELF']}?fop=dl&files_sn=$files_sn' title='{$description}' rel='lytebox'><img src='{$pic_name}' alt='{$description}' title='{$description}' rel='lytebox'></a>"; $files[$files_sn]['path']=$pic_name; $files[$files_sn]['url']="<a href='{$_SERVER['PHP_SELF']}?fop=dl&files_sn=$files_sn' title='{$description}' target='_blank'>{$description}</a>"; $files[$files_sn]['tb_link']="<a href='{$_SERVER['PHP_SELF']}?fop=dl&files_sn=$files_sn' title='{$description}' rel='lytebox'><img src='$thumb_pic' alt='{$description}' title='{$description}'></a>"; $files[$files_sn]['tb_path']=$thumb_pic; $files[$files_sn]['tb_url']="<a href='{$_SERVER['PHP_SELF']}?fop=dl&files_sn=$files_sn' title='{$description}' rel='lytebox'>{$description}</a>"; }else{ $files[$files_sn]['link']="<a href='{$_SERVER['PHP_SELF']}?fop=dl&files_sn=$files_sn'>{$description}</a>"; $files[$files_sn]['path']="{$_SERVER['PHP_SELF']}?fop=dl&files_sn=$files_sn"; } } return $files; } //取得單一圖片 $kind=images(大圖),thumb(小圖) function get_pic_file($col_name="", $col_sn="", $sort="", $showkind="images"){ global $xoopsDB, $xoopsUser, $xoopsModule; $and_sort=(!empty($sort))?" and `sort`='{$sort}'":""; $sql = "select * from ".$xoopsDB->prefix(_MODDIR . "_files_center")." where `col_name`='{$col_name}' and `col_sn`='{$col_sn}' $and_sort order by sort limit 0,1"; $result=$xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error()); while($all=$xoopsDB->fetchArray($result)){ //以下會產生這些變數: $files_sn, $col_name, $col_sn, $sort, $kind, $file_name, $file_type, $file_size, $description foreach($all as $k=>$v){ $$k=$v; } if($showkind=="thumb"){ $files=(file_exists(_FILES_CENTER_THUMB_DIR . "/{$file_name}"))?_FILES_CENTER_THUMB_URL."/{$file_name}":""; }else{ $files=(file_exists(_FILES_CENTER_IMAGE_DIR . "/{$file_name}"))?_FILES_CENTER_IMAGE_URL."/{$file_name}":""; } } return $files; } //取得檔案數 function get_file_amount($col_name="", $col_sn=""){ global $xoopsDB, $xoopsUser, $xoopsModule; $sql = "select count(*) from ".$xoopsDB->prefix(_MODDIR . "_files_center")." where `col_name`='{$col_name}' and `col_sn`='{$col_sn}'"; $result=$xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error()); list($amount)=$xoopsDB->fetchRow($result); return $amount; } //列出可刪除檔案 function list_del_file($col_name="", $col_sn=""){ global $xoopsDB, $xoopsUser, $xoopsModule; $all_file=""; $sql = "select * from ".$xoopsDB->prefix(_MODDIR . "_files_center")." where `col_name`='{$col_name}' and `col_sn`='{$col_sn}' order by sort"; $result=$xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error()); while($all=$xoopsDB->fetchArray($result)){ //以下會產生這些變數: $files_sn, $col_name, $col_sn, $sort, $kind, $file_name, $file_type, $file_size, $description foreach($all as $k=>$v){ $$k=$v; } $all_file.="<input type='checkbox' name='del_file[]' value='{$files_sn}'> $description<br>"; } if(empty($all_file))return; $files.="<div>選取欲刪除檔案<br>$all_file</div>"; return $files; } //取得附檔或附圖 $show_mode=filename、num function show_files($col_name="" , $col_sn="" , $thumb=true , $show_mode="" , $show_description=false , $show_dl=false){ if($show_mode==""){ $all_files="<script type='text/javascript' language='javascript' src='" . TADTOOLS_URL . "/lytebox/lytebox.js'></script> <link rel='stylesheet' href='" . TADTOOLS_URL . "/lytebox/lytebox.css' type='text/css' media='screen' />"; }else{ $all_files=""; } $file_arr=""; $file_arr=get_file($col_name, $col_sn); if(empty($file_arr))return; if($file_arr){ $i=1; foreach($file_arr as $files_sn => $file_info){ if($show_mode=="filename"){ if($file_info['kind']=="file"){ $all_files.="<div>({$i}) {$file_info['link']}</div>"; }else{ $all_files.="<div>({$i}) {$file_info['url']}</div>"; } }else{ if($file_info['kind']=="file"){ $linkto=$file_info['path']; $description=$file_info['description']; $thumb_pic=TADTOOLS_URL."/multiple-file-upload/downloads.png"; $rel=""; }else{ $linkto=$file_info['path']; $description=$file_info['description']; $thumb_pic=($thumb)?$file_info['tb_path']:$file_info['path']; $rel="rel='lyteshow[{$col_name}_{$course_sn}]' title='{$description}'"; } //描述顯示 $show_description_txt=($show_description)?"<div style='height:40px;font-size:9pt;font-weight:normal;overflow:hidden;text-align:center;'><a href='{$linkto}' $rel style='font-size:9pt;font-weight:normal;'>{$description}</a></div>":""; //下載次數顯示 $show_dl_txt=($show_dl)?"<img src='" . TADTOOLS_URL . "/multiple-file-upload/dl_times.gif' alt='download counter' title='download counter' align='absmiddle' hspace=4>: {$file_info['counter']}":""; $width=($thumb)?110:400; $pic_height=($thumb)?90:300; $height=($thumb)?100:320; $height+=($show_description)?30:0; $all_files.=" <div style='border:0px solid gray;width:{$width}px;height:{$height}px;float:left;display:inline;margin:2px;'> <a href='{$linkto}' $rel> <div align='center' style=\"border:1px solid #CFCFCF;width:{$width}px;height:{$pic_height}px;overflow:hidden;margin:2px auto;background-image:url('{$thumb_pic}');background-repeat: no-repeat;background-position: center center;cursor:pointer;\"> $show_dl_txt </div> </a> $show_description_txt </div>"; } $i++; } }else{ $all_files=""; } $all_files.="<div style='clear:both;'></div>"; return $all_files; } //取得單一檔案資料 function get_one_file($files_sn=""){ global $xoopsDB, $xoopsUser, $xoopsModule; $sql = "select * from ".$xoopsDB->prefix(_MODDIR . "_files_center")." where `files_sn`='{$files_sn}'"; $result=$xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error()); $all=$xoopsDB->fetchArray($result); return $all; } //自動編號 function auto_sort($col_name="", $col_sn=""){ global $xoopsDB, $xoopsUser; $sql = "select max(sort) from ".$xoopsDB->prefix(_MODDIR . "_files_center")." where `col_name`='{$col_name}' and `col_sn`='{$col_sn}'"; $result=$xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error()); list($max)=$xoopsDB->fetchRow($result); return ++$max; } //下載並新增計數器 function add_file_counter($files_sn=""){ global $xoopsDB; $file=get_one_file($files_sn); $sql = "update ".$xoopsDB->prefix(_MODDIR . "_files_center")." set `counter`=`counter`+1 where `files_sn`='{$files_sn}'"; $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error()); if($file['kind']=="img"){ header("location:"._FILES_CENTER_IMAGE_URL."/{$file['file_name']}"); }else{ header("location:"._FILES_CENTER_URL."/{$file['file_name']}"); } } if($_GET['fop']=="dl"){ add_file_counter($_GET['files_sn']); } ?> ```
:::
搜尋
search
進階搜尋
QR Code 區塊
快速登入
所有討論區
「PHP全端開發」線上課程討論區
XOOPS使用討論區
一般研習學員
社大學員專用
路過哈啦區
XOOPS佈景設計
XOOPS模組開發
Tad書籍區
即時留言簿
書籍目錄
總目錄
1.jQuery的用法
1-1上課範例:index.html
2.連動選單
2-1上課範例:admin/index.php
2-2上課範例:admin/ajax.php
3.郵遞區號地址
3-1上課範例:admin/index.php
3-2上課範例:index.php
3-3上課範例:ajax.php
4.點擊編輯
4-1上課範例:index.html
4-2上課範例:save.php
4-3上課範例:admin/index.php
4-4上課範例:admin/save.php
5.表單驗證
5-1上課範例:admin/index.php
5-2上課範例:index.php
5-3上課範例:ajax.php
6.表格拉動排序
6-1上課範例:admin/cate.php
6-2上課範例:admin/save_sort.php
7.整合型上傳工具
7-1上課範例:admin/index.php
7-2上課範例:up_file.php
7-3上課範例:index.php
8.頁籤與小月曆之應用
8-1上課範例:admin/index.php
8-2上課範例:index.php
8-3上課範例:ajax2.php
9.fullcalendar月曆應用
9-1上課範例:birthday.php
9-2上課範例:header.php
9-3上課範例:get_events.php
10.QR Code應用
10-1上課範例:xoops_version.php
10-2上課範例:blocks/contact_qrcode.php
10-3上課範例:templates/blocks/contact_qrcode.html
10-4上課範例:pda.php
10-5上課範例:blocks/contact_qrcode.php(不替換網址)
10-6上課範例:index.php
11.Jquery Mobile
11-1上課範例:blocks/contact_qrcode.php
11-2上課範例:pda.php
11-3上課範例:data.php
12.java上傳及影片播放
12-1上課範例:data.php
12-2上課範例:index.php
12-3上課範例:jupload.php
12-4上課範例:play.php
13.CSV的匯出與匯入
13-1上課範例:通訊錄.csv
13-2上課範例:admin/index.php
13-3上課範例:__fgetcsv()
14.產生Excel報表
14-1上課範例:admin/excel.php
14-2上課範例:admin/index.php
14-3上課範例:admin/excel.php(多表)
15.匯入Excel檔
15-1上課範例:admin/excel.php
15-2上課範例:admin/index.php
16.用TCPDF產生PDF(上)
16-1上課範例:admin/index.php
16-2上課範例:admin/pdf.php
17.用TCPDF產生PDF(下)
17-1上課範例:admin/index.php
17-2上課範例:admin/pdf2.php
17-3上課範例:admin/pdf_all.php
18.產出真實word檔
18-1上課範例:admin/index.php
18-2上課範例:admin/docx.php
展開
|
闔起
線上使用者
58
人線上 (
8
人在瀏覽
線上書籍
)
會員: 0
訪客: 58
更多…
:::
主選單
NTPC OpenID
活動報名
模組控制台
進階區塊管理
站長工具箱(急救版)
網站地圖
Tad Tools 工具包
站長工具箱
行事曆
討論留言
嵌入區塊模組
快速登入
網站計數器
好站連結
最新消息
檔案下載
線上書籍
電子相簿
影音播放
常見問題
萬用表單
友站消息
社大學員
新聞
下載
教材
影音
討論
其他選單
好站連結
行事曆
電子相簿
常見問題
萬用表單
即時留言簿
友站消息
社大學員
登入
登入
帳號
密碼
登入