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-2
上課範例:up_file.php
005
define(
"_MODDIR"
,
"contact"
);
048
define(
"_FILES_CENTER_DIR"
,XOOPS_ROOT_PATH.
"/uploads/"
._MODDIR .
"/file"
);
049
define(
"_FILES_CENTER_URL"
,XOOPS_URL.
"/uploads/"
._MODDIR .
"/file"
);
051
define(
"_FILES_CENTER_IMAGE_DIR"
,XOOPS_ROOT_PATH.
"/uploads/"
._MODDIR .
"/image"
);
052
define(
"_FILES_CENTER_IMAGE_URL"
,XOOPS_URL.
"/uploads/"
._MODDIR .
"/image"
);
054
define(
"_FILES_CENTER_THUMB_DIR"
,XOOPS_ROOT_PATH.
"/uploads/"
._MODDIR .
"/image/.thumbs"
);
055
define(
"_FILES_CENTER_THUMB_URL"
,XOOPS_URL.
"/uploads/"
._MODDIR .
"/image/.thumbs"
);
058
function
upload_file(
$col_name
=
""
,
$col_sn
=
""
,
$main_width
=
""
,
$upfile
=
'upfile'
,
$sort
=
""
,
$thumb_width
=
"90"
,
$files_sn
=
""
){
059
global
$xoopsDB
,
$xoopsUser
,
$xoopsModule
;
062
include_once
TADTOOLS_PATH.
"/upload/class.upload.php"
;
067
ini_set
(
'memory_limit'
,
'80M'
);
071
if
(!
empty
(
$_POST
[
'del_file'
])){
072
foreach
(
$_POST
[
'del_file'
]
as
$del_files_sn
){
073
del_files(
$del_files_sn
);
078
foreach
(
$_FILES
[
$upfile
]
as
$k
=>
$l
) {
079
foreach
(
$l
as
$i
=>
$v
) {
080
if
(!
array_key_exists
(
$i
,
$files
)){
081
$files
[
$i
] =
array
();
087
foreach
(
$files
as
$file
) {
089
if
(!
empty
(
$files_sn
)){
090
del_files(
$files_sn
);
095
$sort
=auto_sort(
$col_name
,
$col_sn
);
099
$file_handle
=
new
upload(
$file
,
"zh_TW"
);
101
if
(
$file_handle
->uploaded) {
103
$ext
=
strtolower
(
$file_handle
->file_src_name_ext);
105
if
(
$ext
==
"jpg"
or
$ext
==
"jpeg"
or
$ext
==
"png"
or
$ext
==
"gif"
){
111
$file_handle
->file_safe_name = false;
112
$file_handle
->file_overwrite = true;
113
$file_handle
->file_new_name_body =
"{$col_name}_{$col_sn}_{$sort}"
;
116
if
(
$file_handle
->image_src_x >
$main_width
){
117
$file_handle
->image_resize = true;
118
$file_handle
->image_x =
$main_width
;
119
$file_handle
->image_ratio_y = true;
122
$path
=(
$kind
==
"img"
)?_FILES_CENTER_IMAGE_DIR:_FILES_CENTER_DIR;
123
$file_handle
->process(
$path
);
124
$file_handle
->auto_create_dir = true;
129
$file_handle
->file_safe_name = false;
130
$file_handle
->file_overwrite = true;
131
$file_handle
->file_new_name_body =
"{$col_name}_{$col_sn}_{$sort}"
;
132
if
(
$file_handle
->image_src_x >
$thumb_width
){
133
$file_handle
->image_resize = true;
134
$file_handle
->image_x =
$thumb_width
;
135
$file_handle
->image_ratio_y = true;
137
$file_handle
->process(_FILES_CENTER_THUMB_DIR);
138
$file_handle
->auto_create_dir = true;
143
if
(
$file_handle
->processed) {
144
$file_handle
->clean();
145
$file_name
=
"{$col_name}_{$col_sn}_{$sort}.{$ext}"
;
147
if
(
empty
(
$files_sn
)){
148
$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']}')"
;
149
$xoopsDB
->queryF(
$sql
)
or
redirect_header(
$_SERVER
[
'PHP_SELF'
],3, mysql_error());
151
$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']}')"
;
152
$xoopsDB
->queryF(
$sql
)
or
redirect_header(
$_SERVER
[
'PHP_SELF'
],3, mysql_error());
155
redirect_header(
$_SERVER
[
'PHP_SELF'
],3,
"Error:"
.
$file_handle
->error);
164
function
del_files(
$files_sn
=
""
,
$col_name
=
""
,
$col_sn
=
""
,
$sort
=
""
){
165
global
$xoopsDB
,
$xoopsUser
;
167
if
(!
empty
(
$files_sn
)){
168
$del_what
=
"`files_sn`='{$files_sn}'"
;
169
}
elseif
(!
empty
(
$col_name
)
and
!
empty
(
$col_sn
)){
170
$and_sort
=(
empty
(
$sort
))?
""
:
"and `sort`='{$sort}'"
;
171
$del_what
=
"`col_name`='{$col_name}' and `col_sn`='{$col_sn}' $and_sort"
;
174
$sql
=
"select * from "
.
$xoopsDB
->prefix(_MODDIR .
"_files_center"
).
" where $del_what"
;
175
$result
=
$xoopsDB
->query(
$sql
)
or
redirect_header(
$_SERVER
[
'PHP_SELF'
],3, mysql_error().
"<br>"
.
$sql
);
177
while
(list(
$files_sn
,
$col_name
,
$col_sn
,
$sort
,
$kind
,
$file_name
,
$file_type
,
$file_size
,
$description
)=
$xoopsDB
->fetchRow(
$result
)){
178
$del_sql
=
"delete from "
.
$xoopsDB
->prefix(_MODDIR .
"_files_center"
).
" where files_sn='{$files_sn}'"
;
179
$xoopsDB
->queryF(
$del_sql
)
or
redirect_header(
$_SERVER
[
'PHP_SELF'
],3, mysql_error());
182
unlink(_FILES_CENTER_IMAGE_DIR .
"/$file_name"
);
183
unlink(_FILES_CENTER_THUMB_DIR .
"/$file_name"
);
185
unlink(_FILES_CENTER_DIR .
"/$file_name"
);
192
function
get_file(
$col_name
=
""
,
$col_sn
=
""
,
$sort
=
""
){
193
global
$xoopsDB
,
$xoopsUser
,
$xoopsModule
;
195
$and_sort
=(!
empty
(
$sort
))?
" and `sort`='{$sort}'"
:
""
;
197
$sql
=
"select * from "
.
$xoopsDB
->prefix(_MODDIR .
"_files_center"
).
" where `col_name`='{$col_name}' and `col_sn`='{$col_sn}' $and_sort order by sort"
;
199
$result
=
$xoopsDB
->queryF(
$sql
)
or
redirect_header(
$_SERVER
[
'PHP_SELF'
],3, mysql_error());
200
while
(
$all
=
$xoopsDB
->fetchArray(
$result
)){
202
foreach
(
$all
as
$k
=>
$v
){
206
$files
[
$files_sn
][
'kind'
]=
$kind
;
207
$files
[
$files_sn
][
'sort'
]=
$sort
;
208
$files
[
$files_sn
][
'file_name'
]=
$file_name
;
209
$files
[
$files_sn
][
'file_type'
]=
$file_type
;
210
$files
[
$files_sn
][
'file_size'
]=
$file_size
;
211
$files
[
$files_sn
][
'counter'
]=
$counter
;
212
$files
[
$files_sn
][
'description'
]=
$description
;
215
$pic_name
=(
file_exists
(_FILES_CENTER_IMAGE_DIR .
"/{$file_name}"
))?_FILES_CENTER_IMAGE_URL.
"/{$file_name}"
:TADTOOLS_URL.
"/multiple-file-upload/no_thumb.gif"
;
216
$thumb_pic
=(
file_exists
(_FILES_CENTER_THUMB_DIR .
"/{$file_name}"
))?_FILES_CENTER_THUMB_URL.
"/{$file_name}"
:TADTOOLS_URL.
"/multiple-file-upload/no_thumb.gif"
;
217
$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>"
;
218
$files
[
$files_sn
][
'path'
]=
$pic_name
;
219
$files
[
$files_sn
][
'url'
]=
"<a href='{$_SERVER['PHP_SELF']}?fop=dl&files_sn=$files_sn' title='{$description}' target='_blank'>{$description}</a>"
;
220
$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>"
;
221
$files
[
$files_sn
][
'tb_path'
]=
$thumb_pic
;
222
$files
[
$files_sn
][
'tb_url'
]=
"<a href='{$_SERVER['PHP_SELF']}?fop=dl&files_sn=$files_sn' title='{$description}' rel='lytebox'>{$description}</a>"
;
224
$files
[
$files_sn
][
'link'
]=
"<a href='{$_SERVER['PHP_SELF']}?fop=dl&files_sn=$files_sn'>{$description}</a>"
;
225
$files
[
$files_sn
][
'path'
]=
"{$_SERVER['PHP_SELF']}?fop=dl&files_sn=$files_sn"
;
233
function
get_pic_file(
$col_name
=
""
,
$col_sn
=
""
,
$sort
=
""
,
$showkind
=
"images"
){
234
global
$xoopsDB
,
$xoopsUser
,
$xoopsModule
;
236
$and_sort
=(!
empty
(
$sort
))?
" and `sort`='{$sort}'"
:
""
;
238
$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"
;
240
$result
=
$xoopsDB
->queryF(
$sql
)
or
redirect_header(
$_SERVER
[
'PHP_SELF'
],3, mysql_error());
241
while
(
$all
=
$xoopsDB
->fetchArray(
$result
)){
243
foreach
(
$all
as
$k
=>
$v
){
247
if
(
$showkind
==
"thumb"
){
248
$files
=(
file_exists
(_FILES_CENTER_THUMB_DIR .
"/{$file_name}"
))?_FILES_CENTER_THUMB_URL.
"/{$file_name}"
:
""
;
250
$files
=(
file_exists
(_FILES_CENTER_IMAGE_DIR .
"/{$file_name}"
))?_FILES_CENTER_IMAGE_URL.
"/{$file_name}"
:
""
;
258
function
get_file_amount(
$col_name
=
""
,
$col_sn
=
""
){
259
global
$xoopsDB
,
$xoopsUser
,
$xoopsModule
;
261
$sql
=
"select count(*) from "
.
$xoopsDB
->prefix(_MODDIR .
"_files_center"
).
" where `col_name`='{$col_name}' and `col_sn`='{$col_sn}'"
;
263
$result
=
$xoopsDB
->queryF(
$sql
)
or
redirect_header(
$_SERVER
[
'PHP_SELF'
],3, mysql_error());
264
list(
$amount
)=
$xoopsDB
->fetchRow(
$result
);
270
function
list_del_file(
$col_name
=
""
,
$col_sn
=
""
){
271
global
$xoopsDB
,
$xoopsUser
,
$xoopsModule
;
274
$sql
=
"select * from "
.
$xoopsDB
->prefix(_MODDIR .
"_files_center"
).
" where `col_name`='{$col_name}' and `col_sn`='{$col_sn}' order by sort"
;
276
$result
=
$xoopsDB
->queryF(
$sql
)
or
redirect_header(
$_SERVER
[
'PHP_SELF'
],3, mysql_error());
277
while
(
$all
=
$xoopsDB
->fetchArray(
$result
)){
279
foreach
(
$all
as
$k
=>
$v
){
282
$all_file
.=
"<input type='checkbox' name='del_file[]' value='{$files_sn}'> $description<br>"
;
285
if
(
empty
(
$all_file
))
return
;
287
$files
.=
"<div>選取欲刪除檔案<br>$all_file</div>"
;
293
function
show_files(
$col_name
=
""
,
$col_sn
=
""
,
$thumb
=true ,
$show_mode
=
""
,
$show_description
=false ,
$show_dl
=false){
295
$all_files
=
"<script type='text/javascript' language='javascript' src='"
. TADTOOLS_URL . "/lytebox/lytebox.js'></script>
296
<link rel=
'stylesheet'
href=
'" . TADTOOLS_URL . "/lytebox/lytebox.css'
type=
'text/css'
media=
'screen'
/>";
301
$file_arr
=get_file(
$col_name
,
$col_sn
);
302
if
(
empty
(
$file_arr
))
return
;
306
foreach
(
$file_arr
as
$files_sn
=>
$file_info
){
307
if
(
$show_mode
==
"filename"
){
308
if
(
$file_info
[
'kind'
]==
"file"
){
309
$all_files
.=
"<div>({$i}) {$file_info['link']}</div>"
;
311
$all_files
.=
"<div>({$i}) {$file_info['url']}</div>"
;
314
if
(
$file_info
[
'kind'
]==
"file"
){
315
$linkto
=
$file_info
[
'path'
];
316
$description
=
$file_info
[
'description'
];
317
$thumb_pic
=TADTOOLS_URL.
"/multiple-file-upload/downloads.png"
;
320
$linkto
=
$file_info
[
'path'
];
321
$description
=
$file_info
[
'description'
];
322
$thumb_pic
=(
$thumb
)?
$file_info
[
'tb_path'
]:
$file_info
[
'path'
];
323
$rel
=
"rel='lyteshow[{$col_name}_{$course_sn}]' title='{$description}'"
;
327
$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>"
:
""
;
330
$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']}"
:
""
;
332
$width
=(
$thumb
)?110:400;
333
$pic_height
=(
$thumb
)?90:300;
334
$height
=(
$thumb
)?100:320;
335
$height
+=(
$show_description
)?30:0;
338
<div style=
'border:0px solid gray;width:{$width}px;height:{$height}px;float:left;display:inline;margin:2px;'
>
339
<a href=
'{$linkto}'
$rel
>
340
<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;\">
344
$show_description_txt
353
$all_files
.=
"<div style='clear:both;'></div>"
;
359
function
get_one_file(
$files_sn
=
""
){
360
global
$xoopsDB
,
$xoopsUser
,
$xoopsModule
;
362
$sql
=
"select * from "
.
$xoopsDB
->prefix(_MODDIR .
"_files_center"
).
" where `files_sn`='{$files_sn}'"
;
363
$result
=
$xoopsDB
->queryF(
$sql
)
or
redirect_header(
$_SERVER
[
'PHP_SELF'
],3, mysql_error());
364
$all
=
$xoopsDB
->fetchArray(
$result
);
370
function
auto_sort(
$col_name
=
""
,
$col_sn
=
""
){
371
global
$xoopsDB
,
$xoopsUser
;
373
$sql
=
"select max(sort) from "
.
$xoopsDB
->prefix(_MODDIR .
"_files_center"
).
" where `col_name`='{$col_name}' and `col_sn`='{$col_sn}'"
;
374
$result
=
$xoopsDB
->queryF(
$sql
)
or
redirect_header(
$_SERVER
[
'PHP_SELF'
],3, mysql_error());
375
list(
$max
)=
$xoopsDB
->fetchRow(
$result
);
381
function
add_file_counter(
$files_sn
=
""
){
384
$file
=get_one_file(
$files_sn
);
385
$sql
=
"update "
.
$xoopsDB
->prefix(_MODDIR .
"_files_center"
).
" set `counter`=`counter`+1 where `files_sn`='{$files_sn}'"
;
386
$xoopsDB
->queryF(
$sql
)
or
redirect_header(
$_SERVER
[
'PHP_SELF'
],3, mysql_error());
388
if
(
$file
[
'kind'
]==
"img"
){
389
header(
"location:"
._FILES_CENTER_IMAGE_URL.
"/{$file['file_name']}"
);
391
header(
"location:"
._FILES_CENTER_URL.
"/{$file['file_name']}"
);
396
if
(
$_GET
[
'fop'
]==
"dl"
){
397
add_file_counter(
$_GET
[
'files_sn'
]);
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