Subversion Repositories php-qbpwcf

Rev

Rev 226 | Rev 249 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
/*
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
239 liveuser 6
    Copyright (C) 2014~2026 MIN ZHI, CHEN
3 liveuser 7
 
8
    This file is part of QBPWCF.
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
*/
24
namespace qbpwcf;
25
 
26
/*
27
類別說明:
28
檔案存取應用的類別.
29
備註:
30
無.
31
*/
32
class fileAccess{
33
 
34
	/*
35
	#函式說明:
36
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
37
	#回傳結果:
38
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
39
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
40
	#$result["function"],當前執行的函式名稱.
41
	#必填參數:
42
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
43
	#$arguments,陣列,為呼叫方法時所用的參數.
44
	#參考資料:
45
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
46
	*/
47
	public function __call($method,$arguments){
226 liveuser 48
 
3 liveuser 49
		#取得當前執行的函式
50
		$result["function"]=__FUNCTION__;
226 liveuser 51
 
3 liveuser 52
		#設置執行不正常
53
		$result["status"]="false";
226 liveuser 54
 
3 liveuser 55
		#設置執行錯誤
56
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 57
 
3 liveuser 58
		#設置所丟入的參數
59
		$result["error"][]=$arguments;
226 liveuser 60
 
3 liveuser 61
		#回傳結果
62
		return $result;
226 liveuser 63
 
3 liveuser 64
		}#function __call end
226 liveuser 65
 
3 liveuser 66
	/*
67
	#函式說明:
68
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
69
	#回傳結果:
70
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
71
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
72
	#$result["function"],當前執行的函式名稱.
73
	#必填參數:
74
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
75
	#$arguments,陣列,為呼叫方法時所用的參數.
76
	#參考資料:
77
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
78
	*/
79
	public static function __callStatic($method,$arguments){
226 liveuser 80
 
3 liveuser 81
		#取得當前執行的函式
82
		$result["function"]=__FUNCTION__;
226 liveuser 83
 
3 liveuser 84
		#設置執行不正常
85
		$result["status"]="false";
226 liveuser 86
 
3 liveuser 87
		#設置執行錯誤
88
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 89
 
3 liveuser 90
		#設置所丟入的參數
91
		$result["error"][]=$arguments;
226 liveuser 92
 
3 liveuser 93
		#回傳結果
94
		return $result;
226 liveuser 95
 
3 liveuser 96
		}#function __callStatic end
97
 
98
	/*
99
	#函式說明:
100
	#將字串寫入到檔案
101
	#回傳結果:
102
	#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
103
	#$result["error"],錯誤訊息陣列.
104
	#$result["function"],當前執行的函數名稱.
105
	#$result["fileInfo"],實際上寫入的檔案資訊陣列.
106
	#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
107
	#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
108
	#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
109
	#$result["argu"],使用的參數.
110
	#必填參數:
111
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
112
	$conf["fileArgu"]=__FILE__;
113
	#可省略參數:
114
	#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
115
	#$conf["fileName"]="";
116
	#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
117
	#$conf["inputString"]="";
118
	#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
119
	#$conf["writeMethod"]="a";
120
	#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
121
	#$conf["checkRepeat"]="";
122
	#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
123
	#$conf["filenameExtensionStartPoint"]="";
124
	#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
125
	#$conf["repeatNameRule"]="";
126
	#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
127
	#$conf["web"]="true";
128
	#參考資料:
129
	#無.
130
	#備註:
131
	#無.
132
	*/
133
	public static function writeTextIntoFile(&$conf){
134
 
135
		#初始化要回傳的變數
136
		$result=array();
137
 
138
		#初始化當前執行的函數名稱
139
		$result["function"]=__FUNCTION__;
140
 
141
		#如果 $conf 不為陣列
142
		if(gettype($conf)!="array"){
226 liveuser 143
 
3 liveuser 144
			#設置執行失敗
145
			$result["status"]="false";
226 liveuser 146
 
3 liveuser 147
			#設置執行錯誤訊息
148
			$result["error"][]="\$conf變數須為陣列形態";
149
 
150
			#如果傳入的參數為 null
151
			if($conf==null){
226 liveuser 152
 
3 liveuser 153
				#設置執行錯誤訊息
154
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 155
 
3 liveuser 156
				}#if end
157
 
158
			#回傳結果
159
			return $result;
226 liveuser 160
 
3 liveuser 161
			}#if end
226 liveuser 162
 
3 liveuser 163
		#取得使用的參數
164
		$result["argu"]=$conf;
165
 
166
		#檢查參數
167
		#函式說明:
168
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
169
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
170
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
171
		#$result["function"],當前執行的函式名稱.
172
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
173
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
174
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
175
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
176
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
177
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
178
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
179
		#必填寫的參數:
180
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
181
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
182
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
183
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
226 liveuser 184
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 185
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
186
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
187
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
188
		#可以省略的參數:
189
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
190
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
191
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
192
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileName","inputString","writeMethod","checkRepeat","filenameExtensionStartPoint","repeatNameRule","web");
226 liveuser 193
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 194
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string");
195
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
196
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"","w","false",null,null,"true");
197
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
198
		#$conf["arrayCountEqualCheck"][]=array();
199
		#參考資料來源:
200
		#array_keys=>http://php.net/manual/en/function.array-keys.php
201
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
202
		unset($conf["variableCheck::checkArguments"]);
203
 
204
		#如果 $checkArguments["status"] 等於 "false"
205
		if($checkArguments["status"]=="false"){
226 liveuser 206
 
3 liveuser 207
			#設置錯誤識別
208
			$result["status"]="false";
226 liveuser 209
 
3 liveuser 210
			#設置錯誤訊息
211
			$result["error"]=$checkArguments;
226 liveuser 212
 
3 liveuser 213
			#回傳結果
220 liveuser 214
			return $result;
226 liveuser 215
 
3 liveuser 216
			}#if end
226 liveuser 217
 
3 liveuser 218
		#如果 $checkArguments["passed"] 等於 "false"
219
		if($checkArguments["passed"]=="false"){
226 liveuser 220
 
3 liveuser 221
			#設置錯誤識別
222
			$result["status"]="false";
226 liveuser 223
 
3 liveuser 224
			#設置錯誤訊息
225
			$result["error"]=$checkArguments;
226 liveuser 226
 
3 liveuser 227
			#回傳結果
220 liveuser 228
			return $result;
226 liveuser 229
 
3 liveuser 230
			}#if end
231
 
232
		#如果沒有設置 $conf["fileName"]
233
		if(!isset($conf["fileName"])){
226 liveuser 234
 
3 liveuser 235
			#設定要檢查是否有重複的檔案名稱
236
			$conf["checkRepeat"]="true";
226 liveuser 237
 
3 liveuser 238
			#亂數產生檔案名稱
239
			#函式說明:
240
			#建立以圖片(PNG格式)呈現的驗證碼.
241
			#回傳的解果:
242
			#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
243
			#$result["error"],錯誤訊息.
244
			#$result["function"],檔前執行的函數名稱.
245
			#$result["randNumberWord"],傳驗證碼的內容.
246
			#$result["imgAddress"],圖片的位置與名稱.
247
			#必填參數:
248
			#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生
249
			$conf["authenticate::validationCode"]["imgAddressAndName"]="don't need!";
250
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
251
			$conf["authenticate::validationCode"]["fileArgu"]=$conf["fileArgu"];
252
			#可省略參數:
253
			#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
254
			$conf["authenticate::validationCode"]["num"]="10";
255
			#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
256
			$conf["authenticate::validationCode"]["disableImg"]="true";
257
			#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
258
			#$conf["imgToData"]="true";
259
			$validationCode=authenticate::validationCode($conf["authenticate::validationCode"]);
260
			unset($conf["authenticate::validationCode"]);
226 liveuser 261
 
3 liveuser 262
			#如果亂數產生錯誤
263
			if($validationCode["status"]=="false"){
226 liveuser 264
 
3 liveuser 265
				#設置錯誤識別
266
				$result["status"]="false";
226 liveuser 267
 
3 liveuser 268
				#設置錯誤訊息
269
				$result["error"]=$validationCode;
226 liveuser 270
 
3 liveuser 271
				#回傳結果
226 liveuser 272
				return $result;
273
 
3 liveuser 274
				}#if end
226 liveuser 275
 
3 liveuser 276
			#取得產生的檔案名稱
277
			$conf["fileName"]=$validationCode["randNumberWord"];
226 liveuser 278
 
3 liveuser 279
			}#if end
280
 
281
		#剃除 $conf["fileName"] 開頭的 "./"
282
		#函式說明:
283
		#移除字串開頭的特定內容
284
		#回傳的接結果:
285
		#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
286
		#$result["error"],錯誤訊息陣列.
287
		#$result["function"],當前執行的函數.
288
		#$result["content"],處理好的字串.
289
		#必填參數:
290
		#$conf["inputStr"],字串,要檢查並移除開頭有 $conf["keyWords"] 的字串.
291
		$conf["stringProcess::delKeyWordsInStrHead"]["inputStr"]=$conf["fileName"];
292
		#$conf["keyWord"],字串,要移除的字串開頭關鍵字.
226 liveuser 293
		$conf["stringProcess::delKeyWordsInStrHead"]["keyWord"]="./";
3 liveuser 294
		#可省略參數:
295
		#無.
296
		$delKeyWordsInStrHead=stringProcess::delKeyWordsInStrHead($conf["stringProcess::delKeyWordsInStrHead"]);
297
		unset($conf["stringProcess::delKeyWordsInStrHead"]);
298
 
299
		#如果處理失敗
300
		if($delKeyWordsInStrHead["status"]=="false"){
226 liveuser 301
 
3 liveuser 302
			#設置錯誤識別
303
			$result["status"]="false";
226 liveuser 304
 
3 liveuser 305
			#設置錯誤訊息
306
			$result["error"]=$delKeyWordsInStrHead;
226 liveuser 307
 
3 liveuser 308
			#回傳結果
226 liveuser 309
			return $result;
310
 
3 liveuser 311
			}#if end
226 liveuser 312
 
3 liveuser 313
		#取得處理好的檔案名稱
314
		$conf["fileName"]=$delKeyWordsInStrHead["content"];
315
 
316
		#函式說明:
317
		#確保路徑存在.
318
		#回傳結果:
319
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
320
		#$result["error"],錯誤訊息陣列.
321
		#$resutl["function"],當前執行的涵式名稱.
322
		#必填參數:
323
		#$conf["path"],要檢查的路徑
220 liveuser 324
		$conf["fileAccess::validatePath"]["path"]=$conf["fileName"];
3 liveuser 325
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
326
		$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
327
		#可省略參數:
328
		#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
329
		$conf["fileAccess::validatePath"]["haveFileName"]="true";
330
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
331
		#$conf["dirPermission"]="";
332
		$conf["fileAccess::validatePath"]["web"]=$conf["web"];
333
		$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
334
		unset($conf["fileAccess::validatePath"]);
226 liveuser 335
 
3 liveuser 336
		#debug
337
		#var_dump($validatePath);exit;
226 liveuser 338
 
3 liveuser 339
		#如果確保路徑失敗
340
		if($validatePath["status"]=="false"){
226 liveuser 341
 
3 liveuser 342
			#設置錯誤識別
343
			$result["status"]="false";
226 liveuser 344
 
3 liveuser 345
			#設置錯誤訊息
346
			$result["error"]=$validatePath;
226 liveuser 347
 
3 liveuser 348
			#回傳結果
226 liveuser 349
			return $result;
350
 
3 liveuser 351
			}#if end
226 liveuser 352
 
220 liveuser 353
		#如果要檢查是否有同名的檔案
3 liveuser 354
		if($conf["checkRepeat"]=="true"){
226 liveuser 355
 
3 liveuser 356
			#函式說明:
357
			#檢查要建立的檔案路徑是否存在,若不存在則建立新檔案,若檔案已存在則會在原檔名後面加上從(1)開始的編號,再度嘗試建立檔案,以避免資料異常.
358
			#回傳的結果:
359
			#$result["status"],執行狀態,"true"代表執行正常,"false"代表執行失敗.
360
			#$result["error"],錯誤訊息陣列.
361
			#$result["function"],當前執行的函數名稱.
362
			#$result["createdFileName"],建立好的檔案名稱.
363
			#$result["createdFilePath"],檔案建立的路徑.
364
			#$result["createdFilePathAndName"].建立好的檔案名稱與路徑.
365
			#必填參數:
366
			#$conf["checkedFileAndPath"],字串陣列,要建立的檔案路徑
367
			$conf["fileAccess::createFileAfterCheck"]["checkedFileAndPath"]=$conf["fileName"];
368
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
369
			$conf["fileAccess::createFileAfterCheck"]["fileArgu"]=$conf["fileArgu"];
370
			#可省略參數:
226 liveuser 371
 
3 liveuser 372
			#如果有設定 $conf["filenameExtensionStartPoint"]
373
			if(isset($conf["filenameExtensionStartPoint"])){
226 liveuser 374
 
3 liveuser 375
				#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點.
376
				$conf["fileAccess::createFileAfterCheck"]["filenameExtensionStartPoint"]=$conf["filenameExtensionStartPoint"];
226 liveuser 377
 
3 liveuser 378
				}#if end
226 liveuser 379
 
3 liveuser 380
			#如果有設定 $conf["repeatNameRule"]
381
			if(isset($conf["repeatNameRule"])){
226 liveuser 382
 
3 liveuser 383
				#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)".
384
				$conf["fileAccess::createFileAfterCheck"]["repeatNameRule"]=$conf["repeatNameRule"];
226 liveuser 385
 
3 liveuser 386
				}#if end
226 liveuser 387
 
3 liveuser 388
			#如果有設定 $conf["web"] 參數
389
			if(isset($conf["web"])){
226 liveuser 390
 
3 liveuser 391
				$conf["fileAccess::createFileAfterCheck"]["web"]=$conf["web"];
226 liveuser 392
 
3 liveuser 393
				}#if end
226 liveuser 394
 
3 liveuser 395
			$createFileAfterCheck=fileAccess::createFileAfterCheck($conf["fileAccess::createFileAfterCheck"]);
396
			unset($conf["fileAccess::createFileAfterCheck"]);
226 liveuser 397
 
3 liveuser 398
			#debug
399
			#var_dump($createFileAfterCheck);
400
			#exit;
226 liveuser 401
 
3 liveuser 402
			#如果嘗試建立檔案失敗
403
			if($createFileAfterCheck["status"]=="false"){
226 liveuser 404
 
3 liveuser 405
				#設置執行不正常
406
				$result["status"]="false";
226 liveuser 407
 
3 liveuser 408
				#設置錯誤訊息
409
				$result["error"]=$createFileAfterCheck;
226 liveuser 410
 
3 liveuser 411
				#回傳結果
412
				return $result;
226 liveuser 413
 
3 liveuser 414
				}#if end
226 liveuser 415
 
3 liveuser 416
			#取得建立的檔案資訊
417
			$result["fileInfo"]["createdFilePathAndName"]=$createFileAfterCheck["createdFilePathAndName"];
418
			$result["fileInfo"]["createdFilePath"]=$createFileAfterCheck["createdFilePath"];
226 liveuser 419
			$result["fileInfo"]["createdFileName"]=$createFileAfterCheck["createdFileName"];
420
 
3 liveuser 421
			#取得建立好的檔案路徑與名稱
422
			$conf["fileName"]=$createFileAfterCheck["createdFilePathAndName"];
226 liveuser 423
 
220 liveuser 424
			}#if end
3 liveuser 425
 
426
		#反之沒有要檢查檔案是否存在
427
		else{
226 liveuser 428
 
3 liveuser 429
			#取得建立的檔案資訊
430
			$result["fileInfo"]["createdFilePathAndName"]=$conf["fileName"];
431
			$result["fileInfo"]["createdFilePath"]=$validatePath["path"];
220 liveuser 432
			$result["fileInfo"]["createdFileName"]=$validatePath["fileName"];
226 liveuser 433
 
3 liveuser 434
			}#else end
435
 
436
		#設定要寫入或複寫的檔案
437
		$fileopenResult=fopen($conf["fileName"],$conf["writeMethod"]);
226 liveuser 438
 
3 liveuser 439
		#如果 $fileopenResult 等於 FALSE
440
		if($fileopenResult==FALSE){
226 liveuser 441
 
3 liveuser 442
			#設置錯誤識別
443
			$result["status"]="false";
226 liveuser 444
 
3 liveuser 445
			#代表打開檔案失敗
446
			$result["error"][]="檔案".$conf["fileName"]."開啟失敗";
226 liveuser 447
 
3 liveuser 448
			#回傳結果
449
			return $result;
226 liveuser 450
 
3 liveuser 451
			}#if end
226 liveuser 452
 
3 liveuser 453
		#將資料寫入到檔案裡面
454
		$fwriteResult=fwrite($fileopenResult,$conf["inputString"]);
455
 
456
		#如果 $fwriteResult 等於 FALSE
457
		if($fwriteResult!=0 && $fwriteResult==FALSE){
226 liveuser 458
 
3 liveuser 459
			#設置錯誤識別
460
			$result["status"]="false";
226 liveuser 461
 
3 liveuser 462
			#代表檔案寫入失敗
463
			$result["error"][]="檔案".$conf["fileName"]."寫入失敗";
226 liveuser 464
 
3 liveuser 465
			#回傳結果
466
			return $result;
226 liveuser 467
 
3 liveuser 468
			}#if end
469
 
470
		#存檔並關閉檔案
471
		$fcloseResult=fclose($fileopenResult);
472
 
473
		#如果 $fcloseResult 等於 FALSE
474
		if($fcloseResult==FALSE){
226 liveuser 475
 
3 liveuser 476
			#設置錯誤識別
477
			$result["status"]="false";
226 liveuser 478
 
3 liveuser 479
			#代表檔案寫入失敗
480
			$result["error"][]="檔案".$conf["fileName"]."儲存失敗";
226 liveuser 481
 
3 liveuser 482
			#回傳結果
483
			return $result;
226 liveuser 484
 
3 liveuser 485
			}#if end
486
 
487
		#檢查用來寫入的檔案是否存在
488
		#函式說明:檢查多個檔案與資料夾是否存在
489
		#回傳的結果:
490
		#$result["varName"][$i],爲第$i個變數的名稱。
491
		#$result["varExist"][$i],爲第$i個變數是否存在,true代表存在,false代表不存在。
492
		#必填參數:
493
		$conf["fileAccess::checkMutiFileExist"]["fileArray"]=array($conf["fileName"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
494
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
495
		$conf["fileAccess::checkMutiFileExist"]["fileArgu"]=$conf["fileArgu"];
496
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false".
497
		$conf["fileAccess::checkMutiFileExist"]["web"]=$conf["web"];
498
		#參考資料來源:
499
		#http:#php.net/manual/en/function.file-exists.php
500
		#http:#php.net/manual/en/control-structures.foreach.php
501
		$fileAccess["checkMutiFileExist"]=fileAccess::checkMultiFileExist($conf["fileAccess::checkMutiFileExist"]);
502
		unset($conf["fileAccess::checkMutiFileExist"]);
503
 
504
		#如果檢查檔案是否存在失敗
505
		if($fileAccess["checkMutiFileExist"]["status"]==="false"){
226 liveuser 506
 
3 liveuser 507
			#設置錯誤識別
508
			$result["status"]="false";
226 liveuser 509
 
3 liveuser 510
			#設置錯誤訊息陣列
511
			$result["error"]=$fileAccess["checkMutiFileExist"];
226 liveuser 512
 
3 liveuser 513
			#回傳結果
514
			return $result;
226 liveuser 515
 
3 liveuser 516
			}#if end
517
 
226 liveuser 518
		#如果$fileAccess["checkMutiFileExist"]["varExist"][0] 等於 "false"
3 liveuser 519
		if($fileAccess["checkMutiFileExist"]["varExist"][0]==="false"){
226 liveuser 520
 
3 liveuser 521
			#設置錯誤識別
522
			$result["status"]="false";
226 liveuser 523
 
3 liveuser 524
			#設置錯誤訊息
525
			$result["error"]=$fileAccess["checkMutiFileExist"];
226 liveuser 526
 
3 liveuser 527
			#設置錯誤訊息陣列
528
			$result["error"][]="愈建立的檔案不存在";
226 liveuser 529
 
3 liveuser 530
			#回傳結果
531
			return $result;
226 liveuser 532
 
3 liveuser 533
			}#if end
226 liveuser 534
 
3 liveuser 535
		#函式說明:
536
		#依據取得檔案的擁有着資訊
537
		#回傳結果:
538
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
539
		#$result["error"],錯誤訊息陣列.
226 liveuser 540
		#$result["function"],函數名稱.
3 liveuser 541
		#$result["content"],檔案擁有着資訊.
542
		#$result["content"],檔案資訊陣列.
226 liveuser 543
		#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
3 liveuser 544
		#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
545
		#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
546
		#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
547
		#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
548
		#$result["content"]["ownerName"],檔案擁有着資訊.
549
		#$result["content"]["groupName"],檔案所屬擁有着資訊.
550
		#$result["content"]["size"],檔案大小.
551
		#$result["content"]["modifyDate"],檔案變更年月日.
552
		#$result["content"]["modifyTime"],檔案變更時分秒.
553
		#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
554
		#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
555
		#必填參數:
556
		#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
557
		$conf["fileAccess::fileInfo"]["fileArgu"]=$conf["fileArgu"];
558
		#$conf["file"],字串,要查看擁有者資訊的檔案.
559
		$conf["fileAccess::fileInfo"]["file"]=$conf["fileName"];
560
		#可省略參數:
561
		#$conf["fileToRead"],字串,要讀取的檔案名稱為何?預設為"help".
562
		#$conf["fileToRead"]="help";
563
		#$conf["output"],字串,輸出的網頁檔案位置與名稱,副檔名html會自動補上,預設為"help".
226 liveuser 564
		#$conf["output"]="help.html";
3 liveuser 565
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false".
566
		$conf["fileAccess::fileInfo"]["web"]=$conf["web"];
567
		#參考資料:
568
		#fileowner=>http://php.net/manual/en/function.fileowner.php
569
		#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
570
		$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
571
		unset($conf["fileAccess::fileInfo"]);
226 liveuser 572
 
3 liveuser 573
		#如果取得檔案資訊失敗
574
		if($fileInfo["status"]==="false"){
226 liveuser 575
 
3 liveuser 576
			#設置執行失敗
577
			$result["status"]="false";
226 liveuser 578
 
3 liveuser 579
			#設置錯誤訊息
580
			$result["error"]=$fileInfo;
226 liveuser 581
 
3 liveuser 582
			#回傳結果
583
			return $result;
226 liveuser 584
 
220 liveuser 585
			}#if end
226 liveuser 586
 
3 liveuser 587
		#取得檔案的擁有者名稱
588
		$fileOwner=$fileInfo["content"]["ownerName"];
226 liveuser 589
 
3 liveuser 590
		#執行php的帳戶
220 liveuser 591
		$runner=csInformation::runner();
226 liveuser 592
 
3 liveuser 593
		#如果執行php的使用者等於檔案的擁有者名稱或為root
594
		if($runner===$fileOwner || $runner==="root"){
226 liveuser 595
 
3 liveuser 596
			#改變檔案的權限為0770
597
			chmod($conf["fileName"],0770);
226 liveuser 598
 
3 liveuser 599
			}#if end
226 liveuser 600
 
3 liveuser 601
		#執行到這邊代表執行正常
602
		$result["status"]="true";
226 liveuser 603
 
3 liveuser 604
		#回傳結果
605
		return $result;
226 liveuser 606
 
3 liveuser 607
		}#function writeTextIntoFile end
608
 
609
	/*
610
	#函式說明:
611
	#一次建立多個檔案,並寫入內容.
612
	#回傳結果:
613
	#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
614
	#$result["error"],錯誤訊息陣列.
615
	#$result["function"],當前執行的函數名稱.
616
	#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
617
	#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
618
	#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
619
	#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
620
	#$result["argu"],使用的參數.
621
	#必填參數:
622
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
623
	$conf["fileArgu"]=__FILE__;
624
	#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
625
	$conf["fileName"]=array("");
626
	#可省略參數:
627
	#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
628
	#$conf["inputString"]=array("");
629
	#參考資料:
630
	#無.
631
	#備註:
632
	#無.
633
	*/
634
	public static function writeMultiFile(&$conf){
226 liveuser 635
 
3 liveuser 636
		#初始化要回傳的變數
637
		$result=array();
638
 
639
		#初始化當前執行的函數名稱
640
		$result["function"]=__FUNCTION__;
641
 
642
		#如果 $conf 不為陣列
643
		if(gettype($conf)!="array"){
226 liveuser 644
 
3 liveuser 645
			#設置執行失敗
646
			$result["status"]="false";
226 liveuser 647
 
3 liveuser 648
			#設置執行錯誤訊息
649
			$result["error"][]="\$conf變數須為陣列形態";
650
 
651
			#如果傳入的參數為 null
652
			if($conf==null){
226 liveuser 653
 
3 liveuser 654
				#設置執行錯誤訊息
655
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 656
 
3 liveuser 657
				}#if end
658
 
659
			#回傳結果
660
			return $result;
226 liveuser 661
 
3 liveuser 662
			}#if end
226 liveuser 663
 
3 liveuser 664
		#取得使用的參數
665
		$result["argu"]=$conf;
666
 
667
		#檢查參數
668
		#函式說明:
669
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
670
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
671
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
672
		#$result["function"],當前執行的函式名稱.
673
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
674
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
675
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
676
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
677
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
678
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
679
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
680
		#必填寫的參數:
681
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
682
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
683
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
684
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","fileName");
226 liveuser 685
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 686
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array");
687
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
688
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
689
		#可以省略的參數:
690
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
691
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
692
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
693
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("inputString");
226 liveuser 694
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 695
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
696
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
697
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
698
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
699
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("fileName","inputString");
700
		#參考資料來源:
701
		#array_keys=>http://php.net/manual/en/function.array-keys.php
702
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
703
		unset($conf["variableCheck::checkArguments"]);
704
 
705
		#如果 $checkArguments["status"] 等於 "false"
706
		if($checkArguments["status"]=="false"){
226 liveuser 707
 
3 liveuser 708
			#設置錯誤識別
709
			$result["status"]="false";
226 liveuser 710
 
3 liveuser 711
			#設置錯誤訊息
712
			$result["error"]=$checkArguments;
226 liveuser 713
 
3 liveuser 714
			#回傳結果
220 liveuser 715
			return $result;
226 liveuser 716
 
3 liveuser 717
			}#if end
226 liveuser 718
 
3 liveuser 719
		#如果 $checkArguments["passed"] 等於 "false"
720
		if($checkArguments["passed"]=="false"){
226 liveuser 721
 
3 liveuser 722
			#設置錯誤識別
723
			$result["status"]="false";
226 liveuser 724
 
3 liveuser 725
			#設置錯誤訊息
726
			$result["error"]=$checkArguments;
226 liveuser 727
 
3 liveuser 728
			#回傳結果
220 liveuser 729
			return $result;
226 liveuser 730
 
3 liveuser 731
			}#if end
226 liveuser 732
 
3 liveuser 733
		#如果沒有設定要個別寫入的內容
734
		if(!isset($conf["inputString"])){
226 liveuser 735
 
3 liveuser 736
			#針對每個檔案名稱
737
			for($i=0;$i<count($conf["fileName"]);$i++){
226 liveuser 738
 
3 liveuser 739
				#建立空的 $conf["inputString"]
740
				$conf["inputString"][$i]="";
226 liveuser 741
 
3 liveuser 742
				}#for end
226 liveuser 743
 
3 liveuser 744
			}#if end
226 liveuser 745
 
3 liveuser 746
		#針對每個要寫入的檔案
747
		foreach($conf["fileName"] as $index => $file2writre){
226 liveuser 748
 
3 liveuser 749
			#取得要寫入的內容
750
			$content2writre=$conf["inputString"][$index];
226 liveuser 751
 
3 liveuser 752
			#函式說明:
753
			#將字串寫入到檔案
754
			#回傳結果:
755
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
756
			#$result["error"],錯誤訊息陣列.
757
			#$result["function"],當前執行的函數名稱.
758
			#$result["fileInfo"],實際上寫入的檔案資訊陣列.
759
			#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
760
			#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
761
			#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
762
			#$result["argu"],使用的參數.
763
			#必填參數:
764
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
765
			$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
766
			#可省略參數:
767
			#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
768
			$conf["fileAccess::writeTextIntoFile"]["fileName"]=$file2writre;
769
			#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
770
			$conf["fileAccess::writeTextIntoFile"]["inputString"]=$content2writre;
771
			#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
772
			#$conf["writeMethod"]="a";
773
			#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
774
			#$conf["checkRepeat"]="";
775
			#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
776
			#$conf["filenameExtensionStartPoint"]="";
777
			#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
778
			#$conf["repeatNameRule"]="";
779
			#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
780
			$conf["fileAccess::writeTextIntoFile"]["web"]="false";
781
			#備註:
782
			#無.
783
			$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
784
			unset($conf["fileAccess::writeTextIntoFile"]);
226 liveuser 785
 
3 liveuser 786
			#如果建立檔案失敗
787
			if($writeTextIntoFile["status"]==="false"){
226 liveuser 788
 
3 liveuser 789
				#設置錯誤識別
790
				$result["status"]="false";
226 liveuser 791
 
3 liveuser 792
				#設置錯誤訊息
793
				$result["error"]=$writeTextIntoFile;
226 liveuser 794
 
3 liveuser 795
				#回傳結果
220 liveuser 796
				return $result;
226 liveuser 797
 
3 liveuser 798
				}#if end
226 liveuser 799
 
3 liveuser 800
			#設置建立好的檔案資訊
220 liveuser 801
			$result["content"][]=$writeTextIntoFile["fileInfo"];
226 liveuser 802
 
3 liveuser 803
			}#foreach end
226 liveuser 804
 
3 liveuser 805
			#設置執行正常
806
			$result["status"]="true";
226 liveuser 807
 
3 liveuser 808
			#回傳結果
226 liveuser 809
			return $result;
810
 
3 liveuser 811
		}#function writeMultiFile end
812
 
813
	/*
814
	#函式說明:
815
	#將多行字串寫入到檔案
816
	#回傳結果:
817
	#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
818
	#$result["error"],錯誤訊息陣列.
819
	#$result["function"],當前執行函數的名稱.
820
	#必填參數:
821
	#$conf["fileName"],字串,爲要編輯的檔案名稱
822
	$conf["fileName"]="";
823
	#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
824
	$conf["inputString"]=array("");
825
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
826
	$conf["fileArgu"]=__FILE__;
827
	#可省略參數:
220 liveuser 828
	#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
829
	#$conf["writeMethod"]="a";
830
	#$conf["fastWrite"],字串,“true”代表要一次寫入多行內容;預設為"false"代表一次寫入一行,比較安全,但行數一多會需要等待多時.
831
	#$conf["fastWrite"]="false";
3 liveuser 832
	#參考資料:
833
	#無.
834
	#備註:
835
	#無.
836
	*/
837
	public static function writeMultiLine(&$conf){
226 liveuser 838
 
3 liveuser 839
		#初始化要回傳的結果
840
		$result=array();
226 liveuser 841
 
3 liveuser 842
		#取得當前執行的函數
843
		$result["function"]=__FUNCTION__;
844
 
845
		#如果 $conf 不為陣列
846
		if(gettype($conf)!="array"){
226 liveuser 847
 
3 liveuser 848
			#設置執行失敗
849
			$result["status"]="false";
226 liveuser 850
 
3 liveuser 851
			#設置執行錯誤訊息
852
			$result["error"][]="\$conf變數須為陣列形態";
853
 
854
			#如果傳入的參數為 null
855
			if($conf==null){
226 liveuser 856
 
3 liveuser 857
				#設置執行錯誤訊息
858
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 859
 
3 liveuser 860
				}#if end
861
 
862
			#回傳結果
863
			return $result;
226 liveuser 864
 
3 liveuser 865
			}#if end
226 liveuser 866
 
3 liveuser 867
		#檢查必填參數
868
		#函式說明:
869
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
870
		#回傳的結果:
871
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
872
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
873
		#$result["function"],當前執行的函式名稱.
874
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
875
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
876
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
877
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
878
		#必填寫的參數:
879
		$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
880
		$conf["variableCheck.isexistMulti"]["variableCheck"]=array("fileName","inputString","fileArgu");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
881
		#可以省略的參數:
226 liveuser 882
		$conf["variableCheck.isexistMulti"]["variableType"]=array("string","array","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
3 liveuser 883
		$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
884
		$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
885
		unset($conf["variableCheck.isexistMulti"]);
226 liveuser 886
 
3 liveuser 887
		#如果檢查失敗
888
		if($checkResult["status"]=="false"){
226 liveuser 889
 
3 liveuser 890
			#設置執行錯誤
891
			$result["status"]="false";
226 liveuser 892
 
3 liveuser 893
			#設置執行錯誤訊息
894
			$result["error"]=$checkResult;
226 liveuser 895
 
3 liveuser 896
			#回傳結果
897
			return $result;
226 liveuser 898
 
3 liveuser 899
			}#if end
226 liveuser 900
 
3 liveuser 901
		#如果檢查不通過
902
		if($checkResult["passed"]=="false"){
226 liveuser 903
 
3 liveuser 904
			#設置執行錯誤
905
			$result["status"]="false";
226 liveuser 906
 
3 liveuser 907
			#設置執行錯誤訊息
908
			$result["error"]=$checkResult;
226 liveuser 909
 
3 liveuser 910
			#回傳結果
911
			return $result;
226 liveuser 912
 
3 liveuser 913
			}#if end
226 liveuser 914
 
915
		#檢查可省略參數
3 liveuser 916
		#函式說明:
917
		#檢查一包含數個可省略變數的陣列變數,其型態是否正確,省略掉的陣列變數可以直接給定預設值。
918
		#回傳結果:
919
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
920
		#$result["error"],錯誤訊息陣列.
921
		#$result["function"],當前執行的函式名稱.
922
		#$result["passed"],參數是否都通過檢查,"true",代表有通過檢查,"false"代表沒有通過檢查。
923
		#必填參數:
924
		#$conf["variableCheck.checkSkipableVarType"]["checkedVar"],陣列,要檢查的變數陣列名稱為?
925
		$conf["variableCheck.checkSkipableVarType"]["checkedVar"]=$conf;
926
		#$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"],字串陣列,要檢查型態是否設定正確的變數名稱陣列.
220 liveuser 927
		$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"]=array("writeMethod","fastWrite");
3 liveuser 928
		#$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"],字串陣列,要檢查的每個變數,其型態應該要為何?
220 liveuser 929
		$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"]=array("string","string");
3 liveuser 930
		#$argu,要直接存取的陣列變數名稱,變數前面加上「&」,如果要在別的函式裡面使用本函式,請記得將變動過結果($argu)給使用該函式的設定變數(通常是$conf=$argu).
931
		$argu=&$conf;
932
		#可省略參數:
933
		#$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"],字串陣列,每個不存的變數要初始化為什麼,"null"代表不指定.
220 liveuser 934
		$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"]=array("w","false");
3 liveuser 935
		#無
936
		$checkResult=variableCheck::checkSkipableVarType($conf["variableCheck.checkSkipableVarType"],$argu);
937
		unset($conf["variableCheck.checkSkipableVarType"]);
226 liveuser 938
 
3 liveuser 939
		#如果檢查不通過
940
		if($checkResult["status"]=="false"){
226 liveuser 941
 
3 liveuser 942
			#設置執行錯誤
943
			$result["status"]="false";
226 liveuser 944
 
3 liveuser 945
			#設置執行錯誤訊息
946
			$result["error"]=$checkResult;
226 liveuser 947
 
3 liveuser 948
			#回傳結果
949
			return $result;
226 liveuser 950
 
3 liveuser 951
			}#if end
226 liveuser 952
 
3 liveuser 953
		#如果檢查不通過
954
		if($checkResult["passed"]=="false"){
226 liveuser 955
 
3 liveuser 956
			#設置執行錯誤
957
			$result["status"]="false";
226 liveuser 958
 
3 liveuser 959
			#設置執行錯誤訊息
960
			$result["error"]=$checkResult;
226 liveuser 961
 
3 liveuser 962
			#回傳結果
963
			return $result;
226 liveuser 964
 
3 liveuser 965
			}#if end
966
 
220 liveuser 967
		#如果有設置快速寫入
968
		if($conf["fastWrite"]==="true"){
226 liveuser 969
 
220 liveuser 970
			#初始化要寫入的字串
971
			$inputStrAll="";
226 liveuser 972
 
220 liveuser 973
			#有幾行字要寫就執行幾次
974
			foreach($conf["inputString"] as $inputStr){
975
 
976
				#附加 "\r\n"
977
				$inputStrAll=$inputStrAll.$inputStr.PHP_EOL;
978
 
979
				}#foreach end
226 liveuser 980
 
220 liveuser 981
			#函式說明:
982
			#將字串寫入到檔案
983
			#回傳結果:
984
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
985
			#$result["error"],錯誤訊息陣列.
986
			#必填參數:
987
			$conf["fileAccess.writeTextIntoFile"]["fileName"]=$conf["fileName"];#爲要編輯的檔案名稱
988
			$conf["fileAccess.writeTextIntoFile"]["inputString"]=$inputStrAll;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
989
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
990
			$conf["fileAccess.writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
991
			#可省略參數:
992
			$conf["fileAccess.writeTextIntoFile"]["writeMethod"]=$conf["writeMethod"];#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
993
			#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
994
			$conf["fileAccess.writeTextIntoFile"]["web"]="false";
995
			$writeStatus=fileAccess::writeTextIntoFile($conf["fileAccess.writeTextIntoFile"]);
996
			unset($conf["fileAccess.writeTextIntoFile"]);
226 liveuser 997
 
220 liveuser 998
			#如果寫入失敗
999
			if($writeStatus["status"]=="false"){
226 liveuser 1000
 
220 liveuser 1001
				#設置執行錯誤
1002
				$result["status"]="false";
226 liveuser 1003
 
220 liveuser 1004
				#設置執行錯誤訊息
1005
				$result["error"]=$writeStatus;
226 liveuser 1006
 
220 liveuser 1007
				#回傳結果
1008
				return $result;
226 liveuser 1009
 
220 liveuser 1010
				}#if end
226 liveuser 1011
 
220 liveuser 1012
			#設置執行正常
1013
			$result["status"]="true";
226 liveuser 1014
 
220 liveuser 1015
			#回傳結果
1016
			return $result;
226 liveuser 1017
 
220 liveuser 1018
			}#if end
1019
 
3 liveuser 1020
		#初始化第一次寫入識別變數
1021
		$firstTimeToWrite="true";
226 liveuser 1022
 
3 liveuser 1023
		#有幾行字要寫就執行幾次
1024
		foreach($conf["inputString"] as $inputStr){
1025
 
1026
			#附加 "\r\n"
1027
			$inputStr=$inputStr.PHP_EOL;
1028
 
1029
			#如果是第一次寫入
1030
			if($firstTimeToWrite=="true"){
226 liveuser 1031
 
3 liveuser 1032
				#如果是要重新寫入
220 liveuser 1033
				if($conf["writeMethod"]==="w"){
226 liveuser 1034
 
3 liveuser 1035
					#函式說明:
1036
					#將字串寫入到檔案
1037
					#回傳結果:
1038
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1039
					#$result["error"],錯誤訊息陣列.
1040
					#必填參數:
1041
					$conf["fileAccess.writeTextIntoFile"]["fileName"]=$conf["fileName"];#爲要編輯的檔案名稱
1042
					$conf["fileAccess.writeTextIntoFile"]["inputString"]=$inputStr;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
1043
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1044
					$conf["fileAccess.writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
1045
					#可省略參數:
1046
					$conf["fileAccess.writeTextIntoFile"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
1047
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1048
					$conf["fileAccess.writeTextIntoFile"]["web"]="false";
1049
					$writeStatus=fileAccess::writeTextIntoFile($conf["fileAccess.writeTextIntoFile"]);
1050
					unset($conf["fileAccess.writeTextIntoFile"]);
226 liveuser 1051
 
3 liveuser 1052
					#如果寫入失敗
1053
					if($writeStatus["status"]=="false"){
226 liveuser 1054
 
3 liveuser 1055
						#設置執行錯誤
1056
						$result["status"]="false";
226 liveuser 1057
 
3 liveuser 1058
						#設置執行錯誤訊息
1059
						$result["error"]=$writeStatus;
226 liveuser 1060
 
3 liveuser 1061
						#回傳結果
1062
						return $result;
226 liveuser 1063
 
3 liveuser 1064
						}#if end
226 liveuser 1065
 
3 liveuser 1066
					}#if end
226 liveuser 1067
 
3 liveuser 1068
				#反之不是重新寫入,而是附加寫入。
1069
				else{
226 liveuser 1070
 
3 liveuser 1071
					#函式說明:
1072
					#將字串寫入到檔案
1073
					#回傳結果:
1074
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1075
					#$result["error"],錯誤訊息陣列.
1076
					#必填參數:
1077
					$conf["fileAccess.writeTextIntoFile"]["fileName"]=$conf["fileName"];#爲要編輯的檔案名稱
1078
					$conf["fileAccess.writeTextIntoFile"]["inputString"]=$inputStr;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
1079
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1080
					$conf["fileAccess.writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
1081
					#可省略參數:
1082
					$conf["fileAccess.writeTextIntoFile"]["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
1083
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1084
					$conf["fileAccess.writeTextIntoFile"]["web"]="false";
1085
					$writeStatus=fileAccess::writeTextIntoFile($conf["fileAccess.writeTextIntoFile"]);
1086
					unset($conf["fileAccess.writeTextIntoFile"]);
226 liveuser 1087
 
3 liveuser 1088
					#如果寫入失敗
1089
					if($writeStatus["status"]=="false"){
226 liveuser 1090
 
3 liveuser 1091
						#設置執行錯誤
1092
						$result["status"]="false";
226 liveuser 1093
 
3 liveuser 1094
						#設置執行錯誤訊息
1095
						$result["error"]=$writeStatus;
226 liveuser 1096
 
3 liveuser 1097
						#回傳結果
1098
						return $result;
226 liveuser 1099
 
3 liveuser 1100
						}#if end
226 liveuser 1101
 
3 liveuser 1102
					}#else end
226 liveuser 1103
 
3 liveuser 1104
				#將之設為不是第一次寫入
1105
				$firstTimeToWrite="false";
226 liveuser 1106
 
3 liveuser 1107
				}#if end
226 liveuser 1108
 
3 liveuser 1109
			#反之不是第一次寫入
1110
			else{
226 liveuser 1111
 
3 liveuser 1112
				#函式說明:
1113
				#將字串寫入到檔案
1114
				#回傳結果:
1115
				#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1116
				#$result["error"],錯誤訊息陣列.
1117
				#必填參數:
1118
				$conf["fileAccess.writeTextIntoFile"]["fileName"]=$conf["fileName"];#爲要編輯的檔案名稱
1119
				$conf["fileAccess.writeTextIntoFile"]["inputString"]=$inputStr;#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
1120
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1121
				$conf["fileAccess.writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
1122
				#可省略參數:
1123
				$conf["fileAccess.writeTextIntoFile"]["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
1124
				#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1125
				$conf["fileAccess.writeTextIntoFile"]["web"]="false";
1126
				$writeStatus=fileAccess::writeTextIntoFile($conf["fileAccess.writeTextIntoFile"]);
1127
				unset($conf["fileAccess.writeTextIntoFile"]);
226 liveuser 1128
 
3 liveuser 1129
				#如果寫入失敗
1130
				if($writeStatus["status"]=="false"){
226 liveuser 1131
 
3 liveuser 1132
					#設置執行錯誤
1133
					$result["status"]="false";
226 liveuser 1134
 
3 liveuser 1135
					#設置執行錯誤訊息
1136
					$result["error"]=$writeStatus;
226 liveuser 1137
 
3 liveuser 1138
					#回傳結果
1139
					return $result;
226 liveuser 1140
 
3 liveuser 1141
					}#if end
226 liveuser 1142
 
3 liveuser 1143
				}#else end
226 liveuser 1144
 
3 liveuser 1145
			}#foreach end
226 liveuser 1146
 
3 liveuser 1147
		#執行到這邊代表一切正常
1148
		$result["status"]="true";
226 liveuser 1149
 
3 liveuser 1150
		#回傳結果
1151
		return $result;
226 liveuser 1152
 
3 liveuser 1153
		}#function writeMultiLine end
226 liveuser 1154
 
3 liveuser 1155
	/*
1156
	#函式說明:
1157
	#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
1158
	#回傳的變數說明:
1159
	#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
1160
	#$result["error"],錯誤訊息提示.
1161
	#$result["warning"],警告訊息.
1162
	#$result["function"],當前執行的函數名稱.
1163
	#$result["fileContent"],爲檔案的內容陣列.
1164
	#$result["lineCount"],爲檔案內容總共的行數.
1165
	#$result["fullContent"],為檔案的完整內容.
200 liveuser 1166
	#$result["base64dataOnly"],檔案的base64data.
1167
	#$result["base64data"],為在網頁上給予src參數的數值.
3 liveuser 1168
	#$result["mimeType"],為檔案的mime type.
1169
	#必填參數:
1170
	#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
1171
	$conf["filePositionAndName"]="";
1172
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1173
	$conf["fileArgu"]=__FILE__;
1174
	#可省略參數:
1175
	#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
1176
	#$conf["web"]="true";
1177
	#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
1178
	#$conf["createIfnotExist"]="false";
1179
	#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
1180
	#$conf["autoDeleteSpaceOnEachLineStart"]="false";
1181
	#參考資料:
1182
	#file(),取得檔案內容的行數.
1183
	#file=>http:#php.net/manual/en/function.file.php
1184
	#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
1185
	#filesize=>http://php.net/manual/en/function.filesize.php
1186
	#參考資料:
1187
	#無.
1188
	#備註:
1189
	#無.
1190
	*/
1191
	public static function getFileContent($conf){
1192
 
1193
		#初始化要回傳的內容
1194
		$result=array();
226 liveuser 1195
 
3 liveuser 1196
		#取得當前執行函數名稱
1197
		$result["function"]=__FUNCTION__;
1198
 
1199
		#如果 $conf 不為陣列
1200
		if(gettype($conf)!="array"){
226 liveuser 1201
 
3 liveuser 1202
			#設置執行失敗
1203
			$result["status"]="false";
226 liveuser 1204
 
3 liveuser 1205
			#設置執行錯誤訊息
1206
			$result["error"][]="\$conf變數須為陣列形態";
1207
 
1208
			#如果傳入的參數為 null
1209
			if($conf==null){
226 liveuser 1210
 
3 liveuser 1211
				#設置執行錯誤訊息
1212
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 1213
 
3 liveuser 1214
				}#if end
1215
 
1216
			#回傳結果
1217
			return $result;
226 liveuser 1218
 
3 liveuser 1219
			}#if end
1220
 
1221
		#檢查參數
1222
		#函式說明:
1223
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
1224
		#回傳結果:
1225
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1226
		#$result["error"],執行不正常結束的錯訊息陣列.
1227
		#$result["simpleError"],簡單表示的錯誤訊息.
1228
		#$result["function"],當前執行的函式名稱.
1229
		#$result["argu"],設置給予的參數.
1230
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1231
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1232
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1233
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
1234
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
1235
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1236
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1237
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1238
		#必填參數:
1239
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1240
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1241
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1242
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1243
		#可省略參數:
1244
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1245
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePositionAndName","fileArgu");
1246
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
1247
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
1248
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
1249
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1250
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
1251
		#$conf["canNotBeEmpty"]=array();
1252
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
1253
		#$conf["canBeEmpty"]=array();
1254
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
1255
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("createIfnotExist","web","autoDeleteSpaceOnEachLineStart");
1256
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1257
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("createIfnotExist","web","autoDeleteSpaceOnEachLineStart");
1258
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
1259
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
1260
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1261
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false","false");
1262
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
1263
		#$conf["disallowAllSkipableVarIsEmpty"]="";
1264
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
1265
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
1266
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
1267
		#$conf["disallowAllSkipableVarNotExist"]="";
1268
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1269
		#$conf["arrayCountEqualCheck"][]=array();
1270
		#參考資料:
1271
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1272
		#備註:
1273
		#無.
1274
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1275
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 1276
 
3 liveuser 1277
		#如果檢查出錯
1278
		if($checkArguments["status"]==="false"){
226 liveuser 1279
 
3 liveuser 1280
			#設置執行錯誤識別
1281
			$result["status"]="false";
226 liveuser 1282
 
3 liveuser 1283
			#設置執行錯誤訊息
1284
			$result["error"]=$checkArguments;
226 liveuser 1285
 
3 liveuser 1286
			#回傳結果
1287
			return $result;
226 liveuser 1288
 
3 liveuser 1289
			}#if end
226 liveuser 1290
 
3 liveuser 1291
		#如果檢查參數不通過
1292
		if($checkArguments["passed"]==="false"){
226 liveuser 1293
 
3 liveuser 1294
			#設置執行錯誤識別
1295
			$result["status"]="false";
226 liveuser 1296
 
3 liveuser 1297
			#設置執行錯誤訊息
1298
			$result["error"]=$checkArguments;
226 liveuser 1299
 
3 liveuser 1300
			#回傳結果
1301
			return $result;
226 liveuser 1302
 
3 liveuser 1303
			}#if end
226 liveuser 1304
 
3 liveuser 1305
		#檢查檔案是否存在
1306
		#函式說明:檢查多個檔案與資料夾是否存在
1307
		#回傳的結果:
1308
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1309
		#$result["error"],錯誤訊息陣列.
1310
		#$resutl["function"],當前執行的涵式名稱.
1311
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
1312
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
1313
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
1314
		#必填參數:
1315
		$conf["fileAccess"]["checkMutiFileExist"]["fileArray"]=array($conf["filePositionAndName"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
1316
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1317
		$conf["fileAccess"]["checkMutiFileExist"]["fileArgu"]=$conf["fileArgu"];
1318
		#可省略參數:
1319
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
1320
		$conf["fileAccess"]["checkMutiFileExist"]["disableWebSearch"]="true";
226 liveuser 1321
 
3 liveuser 1322
		#如果有設置 $conf["web"]
1323
		if(isset($conf["web"])){
226 liveuser 1324
 
3 liveuser 1325
			#設置 web 參數.
1326
			$conf["fileAccess"]["checkMutiFileExist"]["web"]=$conf["web"];
226 liveuser 1327
 
3 liveuser 1328
			}#if end
226 liveuser 1329
 
3 liveuser 1330
		#參考資料來源:
1331
		#http:#php.net/manual/en/function.file-exists.php
1332
		#http:#php.net/manual/en/control-structures.foreach.php
1333
		$fileCheckResult=fileAccess::checkMultiFileExist($conf["fileAccess"]["checkMutiFileExist"]);
1334
		unset($conf["fileAccess"]["checkMutiFileExist"]);
1335
 
1336
		#如果檢查檔案是否存在出錯
1337
		if($fileCheckResult["status"]=="false"){
226 liveuser 1338
 
3 liveuser 1339
			#設置執行錯誤識別
1340
			$result["status"]="false";
226 liveuser 1341
 
3 liveuser 1342
			#設置執行錯誤訊息
1343
			$result["error"]=$fileCheckResult;
226 liveuser 1344
 
3 liveuser 1345
			#回傳結果
1346
			return $result;
226 liveuser 1347
 
3 liveuser 1348
			}#if end
1349
 
1350
		#如果該檔案不存在
1351
		if($fileCheckResult["varExist"][0]=="false"){
226 liveuser 1352
 
3 liveuser 1353
			#如果也不要自動建立檔案
1354
			if($conf["createIfnotExist"]==="false"){
226 liveuser 1355
 
3 liveuser 1356
				#設置執行錯誤識別
1357
				$result["status"]="false";
226 liveuser 1358
 
3 liveuser 1359
				#設置執行錯誤訊息
1360
				$result["error"]=$fileCheckResult;
226 liveuser 1361
 
3 liveuser 1362
				#設置易讀的錯誤訊息
1363
				$result["error"][]="名為".$fileCheckResult["varName"][0]."的檔案不存在";
226 liveuser 1364
 
3 liveuser 1365
				#回傳結果
1366
				return $result;
226 liveuser 1367
 
3 liveuser 1368
				}#if end
226 liveuser 1369
 
3 liveuser 1370
			#執行到這邊代表需要建立該檔案
1371
			#函式說明:
1372
			#將字串寫入到檔案
1373
			#回傳結果:
1374
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1375
			#$result["error"],錯誤訊息陣列.
1376
			#$result["function"],當前執行的函數名稱.
1377
			#$result["fileInfo"],實際上寫入的檔案資訊陣列.
1378
			#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
1379
			#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
1380
			#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
1381
			#$result["argu"],使用的參數.
1382
			#必填參數:
1383
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1384
			$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
1385
			#可省略參數:
1386
			#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
1387
			$conf["fileAccess::writeTextIntoFile"]["fileName"]=$fileCheckResult["varNameFullPath"][0];
1388
			#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
200 liveuser 1389
			$conf["fileAccess::writeTextIntoFile"]["inputString"]="";
3 liveuser 1390
			#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
1391
			#$conf["checkRepeat"]="";
1392
			#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
1393
			#$conf["filenameExtensionStartPoint"]="";
1394
			#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
1395
			#$conf["repeatNameRule"]="";
226 liveuser 1396
 
3 liveuser 1397
			#如果有設置 $conf["web"]
1398
			if(isset($conf["web"])){
226 liveuser 1399
 
3 liveuser 1400
				#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1401
				$conf["fileAccess::writeTextIntoFile"]["web"]=$conf["web"];
226 liveuser 1402
 
200 liveuser 1403
				}#if end
226 liveuser 1404
 
3 liveuser 1405
			#參考資料:
1406
			#無.
1407
			#備註:
1408
			#無.
1409
			$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
1410
			unset($conf["fileAccess::writeTextIntoFile"]);
226 liveuser 1411
 
3 liveuser 1412
			#如果建立檔案失敗
1413
			if($writeTextIntoFile["status"]=="false"){
226 liveuser 1414
 
3 liveuser 1415
				#設置執行錯誤識別
1416
				$result["status"]="false";
226 liveuser 1417
 
3 liveuser 1418
				#設置執行錯誤訊息
1419
				$result["error"]=$writeTextIntoFile;
226 liveuser 1420
 
3 liveuser 1421
				#回傳結果
1422
				return $result;
226 liveuser 1423
 
3 liveuser 1424
				}#if end
226 liveuser 1425
 
3 liveuser 1426
			}#if end
1427
 
1428
		#file absolute addr
1429
		$fileAbAddr=$fileCheckResult["varNameFullPath"][0];
226 liveuser 1430
 
3 liveuser 1431
		#將檔案的內容放進變數裡面(會得到陣列)
1432
		$fileContent=file($fileAbAddr);
1433
 
1434
		#如果 $fileContent 等於
1435
		if($fileContent==FALSE){
1436
 
1437
			#如果檔案大小為0bytes
1438
			if(filesize($fileAbAddr)==0){
226 liveuser 1439
 
3 liveuser 1440
				#設置錯誤識別
1441
				$result["warning"][]="執行結果沒有輸出內容";
1442
 
1443
				}#if end
226 liveuser 1444
 
3 liveuser 1445
			#反之檔案有內容
1446
			else{
1447
 
1448
				#設置錯誤識別
1449
				$result["status"]="false";
1450
 
1451
				#設置錯誤訊息
1452
				$result["error"][]="讀取檔案失敗";
1453
 
42 liveuser 1454
				#取得詳細的錯誤訊息
1455
				$result["error"][]=$fileCheckResult;
226 liveuser 1456
 
3 liveuser 1457
				#回傳結果
1458
				return $result;
226 liveuser 1459
 
3 liveuser 1460
				}#else end
1461
 
1462
			}#if end
1463
 
1464
		#針對每行內容
1465
		for($i=0;$i<count($fileContent);$i++){
226 liveuser 1466
 
3 liveuser 1467
			#剔除字串尾的換行符號
1468
			$fileContent[$i]=rtrim($fileContent[$i]);
226 liveuser 1469
 
3 liveuser 1470
			#如果要移除開頭的空白
1471
			if($conf["autoDeleteSpaceOnEachLineStart"]==="true"){
226 liveuser 1472
 
3 liveuser 1473
				#如果開頭是空格
1474
				while(strpos($fileContent[$i]," ")===0){
226 liveuser 1475
 
3 liveuser 1476
					#函式說明:
1477
					#將字串特定關鍵字與其前面的內容剔除
1478
					#回傳結果:
1479
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1480
					#$result["error"],錯誤訊息陣列.
1481
					#$result["warning"],警告訊息鎮列.
1482
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
1483
					#$result["function"],當前執行的函數名稱.
1484
					#$result["argu"],使用的參數.
1485
					#$result["oriStr"],要處理的原始字串內容.
226 liveuser 1486
					#$result["content"],處理好的的字串內容.
3 liveuser 1487
					#必填參數:
1488
					#$conf["stringIn"],字串,要處理的字串.
1489
					$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$fileContent[$i];
1490
					#$conf["keyWord"],字串,特定字串.
1491
					$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=" ";
1492
					#可省略參數:
1493
					#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
1494
					#$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
1495
					#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
1496
					#$conf["lastResult"]=$delStrBeforeKeyWord;
1497
					#參考資料:
1498
					#無.
1499
					#備註:
1500
					#無.
1501
					$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
1502
					unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 1503
 
3 liveuser 1504
					#如果建立檔案失敗
1505
					if($delStrBeforeKeyWord["status"]=="false"){
226 liveuser 1506
 
3 liveuser 1507
						#設置執行錯誤識別
1508
						$result["status"]="false";
226 liveuser 1509
 
3 liveuser 1510
						#設置執行錯誤訊息
1511
						$result["error"]=$delStrBeforeKeyWord;
226 liveuser 1512
 
3 liveuser 1513
						#回傳結果
1514
						return $result;
226 liveuser 1515
 
3 liveuser 1516
						}#if end
226 liveuser 1517
 
3 liveuser 1518
					#取得剔除開頭空格後的內容
1519
					$fileContent[$i]=$delStrBeforeKeyWord["content"];
226 liveuser 1520
 
3 liveuser 1521
					}#while end
226 liveuser 1522
 
3 liveuser 1523
				}#if end
226 liveuser 1524
 
3 liveuser 1525
			}#for end
1526
 
1527
		#取得總共有幾行
1528
		$lineCount=count($fileContent);
1529
 
1530
		#將檔案內容的陣列放進 $result 陣列變數裏面
1531
		$result["fileContent"]=$fileContent;
226 liveuser 1532
 
3 liveuser 1533
		#建立暫存檔案
1534
		$tmpFile=tempnam("/tmp", "qbpwcf");
226 liveuser 1535
 
3 liveuser 1536
		#讀取要取得的檔案內容
1537
		$content=file_get_contents($fileAbAddr);
226 liveuser 1538
 
3 liveuser 1539
		#開啟暫存檔案(寫入模式)
1540
		$file=fopen($tmpFile,'w');
226 liveuser 1541
 
3 liveuser 1542
		#寫入讀取到的內容
1543
		fwrite($file,$content);
226 liveuser 1544
 
3 liveuser 1545
		#關閉暫存檔案
1546
		fclose($file);
226 liveuser 1547
 
3 liveuser 1548
		#取得檔案的 mime 類型
1549
		$mimeType=mime_content_type($tmpFile);
226 liveuser 1550
 
3 liveuser 1551
		#設置檔案的mime類型
1552
		$result["mimeType"]=$mimeType;
226 liveuser 1553
 
3 liveuser 1554
		#取得檔案的內容為字串
1555
		$result["fullContent"]=file_get_contents($tmpFile);
226 liveuser 1556
 
3 liveuser 1557
		#取得檔案的base64data
200 liveuser 1558
		$result["base64dataOnly"]=base64_encode($result["fullContent"]);
226 liveuser 1559
 
200 liveuser 1560
		#取得檔案用 data:mimeType;base64,base64data 表示的字串
203 liveuser 1561
		$result["base64data"]="data:".$result["mimeType"].";base64,".$result["base64dataOnly"];
226 liveuser 1562
 
3 liveuser 1563
		#移除暫存檔案
1564
		unlink($tmpFile);
226 liveuser 1565
 
3 liveuser 1566
		#將檔案內容的行數放進 $result 陣列變數裏面
1567
		$result["lineCount"]=$lineCount;
1568
 
1569
		#執行到這邊代表執行成功
1570
		$result["status"]="true";
1571
 
1572
		#回傳結果
1573
		return $result;
1574
 
1575
		}#function getFileContent end
1576
 
1577
	/*
1578
	#函式說明:
1579
	#依據逗號分隔抓取檔案的內容,結果會回傳一個陣列
226 liveuser 1580
	#回傳結果:
3 liveuser 1581
	#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
1582
	#$result["error"],錯誤訊息提示.
1583
	#$result["function"],函數名稱.
1584
	#$result["lineCount"]爲總共有幾行
1585
	#$result["lineContent"][i]["dataCounts"],爲第 i+1 行總共有幾個字串
1586
	#$result["lineContent"][0][i],爲第1行第 i+1 個分割好的字串
1587
	#$result["lineContent"][1][i],爲第2行第 i+1 個分割好的字串
1588
	#必填參數:
1589
	#$conf["filePositionAndName"],字串,要抓取的檔案位置與名稱
1590
	$conf["filePositionAndName"]="";
1591
	#可省略參數:
1592
	#$conf["spiltSign"],字串,爲要用來分割字串的符號,可省略,預設爲「,」
1593
	#$conf["spiltSign"]="";
1594
	#參考資料:
1595
	#無.
1596
	#備註:
1597
	#無.
1598
	*/
1599
	public static function getFileContentSpiltBySomething($conf){
1600
 
1601
		#初始化要回傳的內容
1602
		$result=array();
226 liveuser 1603
 
3 liveuser 1604
		#取得當前執行函數名稱
1605
		$result["function"]=__FUNCTION__;
1606
 
1607
		#如果 $conf 不為陣列
1608
		if(gettype($conf)!="array"){
226 liveuser 1609
 
3 liveuser 1610
			#設置執行失敗
1611
			$result["status"]="false";
226 liveuser 1612
 
3 liveuser 1613
			#設置執行錯誤訊息
1614
			$result["error"][]="\$conf變數須為陣列形態";
1615
 
1616
			#如果傳入的參數為 null
1617
			if($conf==null){
226 liveuser 1618
 
3 liveuser 1619
				#設置執行錯誤訊息
1620
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 1621
 
3 liveuser 1622
				}#if end
1623
 
1624
			#回傳結果
1625
			return $result;
226 liveuser 1626
 
3 liveuser 1627
			}#if end
1628
 
1629
		#如果 $conf["spiltSign"] 爲空,則預設爲","。
1630
		if(!isset($conf["spiltSign"])){
1631
 
1632
			$conf["spiltSign"]=",";
1633
 
1634
			}#if end
1635
 
1636
		#依據行號抓取所有的內容
1637
		#函式說明:
1638
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
1639
		#回傳的變數說明:
1640
		#$result["fileContent"],爲檔案的內容陣列
1641
		#$result["lineCount"],爲檔案內容總共的行數
1642
		#必填參數:
1643
		$conf["fileAccess"]["getFileContent"]["filePositionAndName"]=$conf["filePositionAndName"];#爲檔案的位置以及名稱
1644
		#參考資料:
1645
		#file():取得檔案內容的行數
1646
		#http:#php.net/manual/en/function.file.php
1647
		$fileContent=fileAccess::getFileContent($conf["fileAccess"]["getFileContent"]);
1648
		unset($conf["fileAccess"]["getFileContent"]);
1649
 
1650
		#如果取得檔案內容失敗
1651
		if($fileContent["status"]=="false"){
226 liveuser 1652
 
3 liveuser 1653
			#設置執行失敗
1654
			$result["status"]="false";
226 liveuser 1655
 
3 liveuser 1656
			#設置執行錯誤訊息
1657
			$result["error"]=$fileContent;
1658
 
1659
			#回傳結果
1660
			return $result;
226 liveuser 1661
 
3 liveuser 1662
			}#if end
1663
 
1664
		#迴圈,有幾行資料就執行幾次
1665
		for($i=0;$i<$fileContent["lineCount"];$i++){
1666
 
1667
			#將該行內容用逗號分隔
1668
			$conf["stringProcess"]["spiltString"]["stringIn"]=$fileContent["fileContent"][$i];#要處理的字串。
1669
			$conf["stringProcess"]["spiltString"]["spiltSymbol"]=$conf["spiltSign"];#爲以哪個符號作爲分割
1670
			$lineSpiltResult[$i]=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
226 liveuser 1671
			unset($conf["stringProcess"]["spiltString"]);
3 liveuser 1672
 
1673
			#如果分割字串失敗
1674
			if($lineSpiltResult[$i]["status"]=="false"){
226 liveuser 1675
 
3 liveuser 1676
				#設置執行失敗
1677
				$result["status"]="false";
226 liveuser 1678
 
3 liveuser 1679
				#設置執行錯誤訊息
1680
				$result["error"]=$lineSpiltResult[$i];
1681
 
1682
				#回傳結果
1683
				return $result;
226 liveuser 1684
 
3 liveuser 1685
				}#if end
1686
 
1687
			}#for end
1688
 
1689
		#取得
1690
		$result["lineContent"]=$lineSpiltResult;
1691
 
1692
		#取得資料的行數
1693
		$result["lineCount"]=$fileContent["lineCount"];
1694
 
1695
		#回傳結果
1696
		return $result;
226 liveuser 1697
 
3 liveuser 1698
		}#function getFileContentSpiltBySomething end
1699
 
1700
	/*
1701
	#函式說明:
1702
	#檢查多個檔案與資料夾是否存在.
1703
	#回傳的結果:
1704
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1705
	#$result["error"],錯誤訊息陣列.
1706
	#$resutl["function"],當前執行的涵式名稱.
1707
	#$result["argu"],使用的參數.
1708
	#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
1709
	#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
1710
	#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
1711
	#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
1712
	#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
1713
	#必填參數:
1714
	#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
1715
	$conf["fileArray"]=array();
1716
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1717
	$conf["fileArgu"]=__FILE__;
1718
	#可省略參數:
1719
	#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
1720
	#$conf["disableWebSearch"]="false";
1721
	#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
1722
	#$conf["userDir"]="true";
1723
	#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
1724
	#$conf["web"]="true";
1725
	#參考資料:
1726
	#http://php.net/manual/en/function.file-exists.php
1727
	#http://php.net/manual/en/control-structures.foreach.php
1728
	#備註:
1729
	#函數file_exists檢查的路徑為檔案系統的路徑
1730
	#$result["varName"][$i]結果未實作
1731
	*/
1732
	public static function checkMultiFileExist(&$conf){
226 liveuser 1733
 
3 liveuser 1734
		#初始化要回傳的變數
1735
		$result=array();
226 liveuser 1736
 
3 liveuser 1737
		#設置當前執行的涵式
1738
		$result["function"]=__FUNCTION__;
226 liveuser 1739
 
3 liveuser 1740
		#如果 $conf 不為陣列
1741
		if(gettype($conf)!="array"){
226 liveuser 1742
 
3 liveuser 1743
			#設置執行失敗
1744
			$result["status"]="false";
226 liveuser 1745
 
3 liveuser 1746
			#設置執行錯誤訊息
1747
			$result["error"][]="\$conf變數須為陣列形態";
1748
 
1749
			#如果傳入的參數為 null
1750
			if($conf==null){
226 liveuser 1751
 
3 liveuser 1752
				#設置執行錯誤訊息
1753
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 1754
 
3 liveuser 1755
				}#if end
1756
 
1757
			#回傳結果
1758
			return $result;
226 liveuser 1759
 
3 liveuser 1760
			}#if end
226 liveuser 1761
 
3 liveuser 1762
		#取得使用的參數
1763
		$result["argu"]=$conf;
226 liveuser 1764
 
3 liveuser 1765
		#檢查參數
1766
		#函式說明:
1767
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1768
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1769
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1770
		#$result["function"],當前執行的函式名稱.
1771
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1772
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1773
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1774
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
1775
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1776
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1777
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1778
		#必填寫的參數:
1779
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1780
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1781
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1782
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArray","fileArgu");
226 liveuser 1783
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 1784
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
1785
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1786
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1787
		#可以省略的參數:
1788
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
1789
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1790
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1791
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("disableWebSearch","userDir","web");
226 liveuser 1792
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 1793
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
1794
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1795
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true","true","true");
1796
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1797
		#$conf["arrayCountEqualCheck"][]=array();
1798
		#參考資料來源:
1799
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1800
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1801
		unset($conf["variableCheck::checkArguments"]);
1802
 
1803
		#如果 $checkArguments["status"] 等於 "false"
1804
		if($checkArguments["status"]=="false"){
226 liveuser 1805
 
3 liveuser 1806
			#設置錯誤識別
1807
			$result["status"]="false";
226 liveuser 1808
 
3 liveuser 1809
			#設置錯誤訊息
1810
			$result["error"]=$checkArguments;
226 liveuser 1811
 
3 liveuser 1812
			#回傳結果
42 liveuser 1813
			return $result;
226 liveuser 1814
 
3 liveuser 1815
			}#if end
226 liveuser 1816
 
3 liveuser 1817
		#如果 $checkArguments["passed"] 等於 "false"
1818
		if($checkArguments["passed"]=="false"){
226 liveuser 1819
 
3 liveuser 1820
			#設置錯誤識別
1821
			$result["status"]="false";
226 liveuser 1822
 
3 liveuser 1823
			#設置錯誤訊息
1824
			$result["error"]=$checkArguments;
226 liveuser 1825
 
3 liveuser 1826
			#回傳結果
42 liveuser 1827
			return $result;
226 liveuser 1828
 
3 liveuser 1829
			}#if end
226 liveuser 1830
 
3 liveuser 1831
		#初始化儲存每個檔案是否存在的陣列變數
1832
		$result["varName"]=array();
1833
		$result["varExist"]=array();
1834
 
1835
		#針對每個要檢查的檔案
1836
		foreach($conf["fileArray"] as $i=>$varName){
226 liveuser 1837
 
3 liveuser 1838
			#儲存要判斷是否存在的物件
1839
			$result["varName"][]=$varName;
226 liveuser 1840
 
3 liveuser 1841
			#函式說明:
1842
			#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
1843
			#回傳結果:
1844
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1845
			#$result["error"],錯誤訊息陣列.
226 liveuser 1846
			#$result["function"],函數名稱.
3 liveuser 1847
			#$result["argu"],使用的參數.
1848
			#$result["content"],網址,若是在命令列執行,則為"null".
1849
			#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
1850
			#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
1851
			#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
1852
			#必填參數:
1853
			#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
1854
			$conf["fileAccess::getInternetAddressV2"]["address"]=$varName;
1855
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
1856
			$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
1857
			#可省略參數:
1858
			$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
1859
			#備註:
1860
			#建構中,fileSystemRelativePosition尚未實作.
1861
			$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
1862
			unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 1863
 
3 liveuser 1864
			#如果轉換成絕對路徑失敗
1865
			if($getInternetAddressV2["status"]=="false"){
226 liveuser 1866
 
3 liveuser 1867
				#設置錯誤識別
1868
				$result["status"]="false";
226 liveuser 1869
 
3 liveuser 1870
				#設置錯誤訊息
1871
				$result["error"]=$getInternetAddressV2;
226 liveuser 1872
 
3 liveuser 1873
				#回傳結果
1874
				return $result;
226 liveuser 1875
 
3 liveuser 1876
				}#if end
226 liveuser 1877
 
3 liveuser 1878
			#傳參考
1879
			$getInternetAddress=&$getInternetAddressV2;
226 liveuser 1880
 
3 liveuser 1881
			#如果沒有檔案的絕對路徑位置
1882
			if(!isset($getInternetAddress["fileSystemAbsoulutePosition"])){
226 liveuser 1883
 
3 liveuser 1884
				#置換成給予的參數網址
1885
				$conf["fileArray"][$i]=$getInternetAddress["content"];
226 liveuser 1886
 
3 liveuser 1887
				#設置無法從檔案系統找到
1888
				$exist=FALSE;
226 liveuser 1889
 
3 liveuser 1890
				}#if end
226 liveuser 1891
 
3 liveuser 1892
			#反之取得
1893
			else{
226 liveuser 1894
 
3 liveuser 1895
				#轉換好的絕對路徑
1896
				$conf["fileArray"][$i]=$getInternetAddress["fileSystemAbsoulutePosition"];
226 liveuser 1897
 
42 liveuser 1898
				#無窮迴圈
1899
				while(true){
226 liveuser 1900
 
42 liveuser 1901
					#判斷該檔案是否存在
1902
					$exist=file_exists($conf["fileArray"][$i]);
226 liveuser 1903
 
42 liveuser 1904
					#如果不存在
1905
					if($exist===false){
226 liveuser 1906
 
42 liveuser 1907
						#無窮迴圈
1908
						while(true){
226 liveuser 1909
 
42 liveuser 1910
							#當要檢查的目標是 link 時
1911
							if(is_link($conf["fileArray"][$i])){
226 liveuser 1912
 
42 liveuser 1913
								#取得link的路徑
1914
								$conf["fileArray"][$i]=readlink($conf["fileArray"][$i]);
226 liveuser 1915
 
42 liveuser 1916
								#結束連結的判斷,回到判斷目標是否存在的地方.
1917
								continue 2;
226 liveuser 1918
 
42 liveuser 1919
								}#if end
226 liveuser 1920
 
42 liveuser 1921
							#結束連結的判斷
1922
							break;
226 liveuser 1923
 
42 liveuser 1924
							}#while end
226 liveuser 1925
 
42 liveuser 1926
						}#if end
226 liveuser 1927
 
42 liveuser 1928
					#結束到判斷目標是否存在
1929
					break;
226 liveuser 1930
 
42 liveuser 1931
					}#while end
226 liveuser 1932
 
3 liveuser 1933
				}#else end
226 liveuser 1934
 
3 liveuser 1935
			#如果 $exist 等於 false (檔案不存在) 且 沒有停用網路搜尋功能
1936
			if($exist===FALSE && $conf["disableWebSearch"]==="false"){
1937
 
1938
				#將目標轉換成網址
1939
				#函式說明:
1940
				#將檔案的位置名稱變成網址
1941
				#回傳結果:
1942
				#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1943
				#$result["error"],錯誤訊息陣列.
226 liveuser 1944
				#$result["function"],函數名稱.
3 liveuser 1945
				#$result["content"],網址.
1946
				#必填參數:
1947
				#$conf["address"],字串,檔案的相對位置.
1948
				$conf["fileAccess::getInternetAddress"]["address"]=$conf["fileArray"][$i];
1949
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
1950
				$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
1951
				$getInternetAddress=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddress"]);
1952
				unset($conf["fileAccess::getInternetAddress"]);
1953
 
1954
				#如果轉換失敗
1955
				if($getInternetAddress["status"]=="false"){
226 liveuser 1956
 
3 liveuser 1957
					#設置錯誤識別
1958
					$result["status"]="false";
226 liveuser 1959
 
3 liveuser 1960
					#設置錯誤訊息
1961
					$result["error"]=$getInternetAddress;
226 liveuser 1962
 
3 liveuser 1963
					#回傳結果
226 liveuser 1964
					return $result;
1965
 
3 liveuser 1966
					}#if end
226 liveuser 1967
 
3 liveuser 1968
				#函式說明:
1969
				#運行curl cmd
1970
				#回傳結果:
1971
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1972
				#$result["error"],錯誤訊息陣列.
1973
				#$result["function"],當前執行的函式名稱.
1974
				#$result["content"],取得的回應內容.
1975
				#$result["cookie"],cookie檔案的位置與名稱.
1976
				#$result["cmd"],執行的command.
1977
				#$result["argu],使用的參數.
1978
				#必填參數:
1979
				#$conf["url"],字串,目標url.
1980
				$conf["catchWebContent::curlCmd"]["url"]=$getInternetAddress["content"];
1981
				#$conf["fileArgu"],字串,變數__FILE__的內容.
1982
				$conf["catchWebContent::curlCmd"]["fileArgu"]=$conf["fileArgu"];
1983
				#可省略參數:
1984
				#$conf["header"],字串陣列,要傳送的header.
1985
				#$conf["header"]=array();
1986
				#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
1987
				#$conf["allowAnySSLcertificate"]="";
1988
				#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
1989
				#$conf["postVar"]=array();
1990
				#$conf["rawPost"]="字串",要傳送的raw post內容.
1991
				#$conf["rawPost"]="";
1992
				#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
1993
				#$conf["urlEncode"]="false";
1994
				#$conf["agent"],字串,user agent的名稱.
1995
				#$conf["agent"]="";
1996
				#$conf["cookie"],字串,cookie位置與檔案位置.
1997
				#$conf["cookie"]="";
1998
				#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
1999
				#$conf["forceNewCookie"]="";
2000
				$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
2001
				unset($conf["catchWebContent::curlCmd"]);
226 liveuser 2002
 
3 liveuser 2003
				#如果抓取資料失敗
2004
				if($curlCmd["status"]==="false"){
226 liveuser 2005
 
3 liveuser 2006
					#設置錯誤識別
2007
					$result["status"]="false";
226 liveuser 2008
 
3 liveuser 2009
					#設置錯誤訊息
2010
					$result["error"]=$curlCmd;
226 liveuser 2011
 
3 liveuser 2012
					#回傳結果
2013
					return $result;
226 liveuser 2014
 
3 liveuser 2015
					}#if end
226 liveuser 2016
 
3 liveuser 2017
				#反之檔案存在網路上
2018
				else{
226 liveuser 2019
 
3 liveuser 2020
					#將該檔案的路徑名稱與是否存在的訊息儲存到 $result 陣列變數裏面
2021
					$result["varName"][$i]=$getInternetAddress["content"];
226 liveuser 2022
 
3 liveuser 2023
					#如果存在檔案路徑的絕對位置
2024
					if(isset($getInternetAddress["fileSystemAbsoulutePosition"])){
226 liveuser 2025
 
42 liveuser 2026
						#設置該檔案的絕對路徑位置
3 liveuser 2027
						$result["varNameFullPath"][$i]=$getInternetAddress["fileSystemAbsoulutePosition"];
226 liveuser 2028
 
3 liveuser 2029
						}#if end
226 liveuser 2030
 
2031
					#反之代表輸入參數是網址
3 liveuser 2032
					else{
226 liveuser 2033
 
3 liveuser 2034
						#設置該檔案的網址
2035
						$result["varNameWebPath"][$i]=$getInternetAddress["content"];
226 liveuser 2036
 
3 liveuser 2037
						}#else end
226 liveuser 2038
 
3 liveuser 2039
					#設置有無找到的識別
2040
					$result["varExist"][$i]=$curlCmd["founded"];
226 liveuser 2041
 
3 liveuser 2042
					}#else end
226 liveuser 2043
 
3 liveuser 2044
				}#if end
2045
 
2046
			#反之檔案不存在,且停用網路搜尋.
2047
			else if($exist===FALSE){
226 liveuser 2048
 
3 liveuser 2049
				#將該檔案的路徑名稱與是否存在的訊息儲存到 $result 陣列變數裏面
2050
				$result["varName"][$i]=$conf["fileArray"][$i];
2051
				$result["varNameFullPath"][$i]=$conf["fileArray"][$i];
2052
				$result["varExist"][$i]="false";
2053
 
2054
				#設置全部檔案都存在的識別變數為 "false"
2055
				$result["allExist"]="false";
226 liveuser 2056
 
3 liveuser 2057
				}#if end
2058
 
2059
			#反之代表檔案存在
2060
			else{
226 liveuser 2061
 
3 liveuser 2062
				#將該檔案的路徑名稱與是否存在的訊息儲存到 $result 陣列變數裏面
2063
				$result["varNameFullPath"][$i]=$conf["fileArray"][$i];
226 liveuser 2064
 
3 liveuser 2065
				#如果 web 參數為 "true"
2066
				if($conf["web"]==="true"){
226 liveuser 2067
 
3 liveuser 2068
					#設置網路上的位置
2069
					$result["varNameWebPath"][$i]=$getInternetAddress["content"];
226 liveuser 2070
 
3 liveuser 2071
					}#if end
226 liveuser 2072
 
3 liveuser 2073
				$result["varExist"][$i]="true";
2074
 
2075
				}#else end
226 liveuser 2076
 
3 liveuser 2077
			}#foreach end
226 liveuser 2078
 
3 liveuser 2079
		#如果所有檔案與資料夾都找到的識別變數不存在
2080
		if(!isset($result["allExist"])){
226 liveuser 2081
 
3 liveuser 2082
			#設置全部檔案與資料夾都有找到
2083
			$result["allExist"]="true";
226 liveuser 2084
 
3 liveuser 2085
			}#if end
2086
 
2087
		#執行到這邊代表執行正常
2088
		$result["status"]="true";
2089
 
2090
		#回傳結果
2091
		return $result;
2092
 
2093
		}#function checkMutiFileExist
2094
 
2095
	/*
2096
	#函式說明:
2097
	#檢查要建立的檔案路徑是否存在,若不存在則建立新檔案,若檔案已存在則會在原檔名後面加上從(1)開始的編號,再度嘗試建立檔案,以避免資料異常.
2098
	#回傳結果:
2099
	#$result["status"],執行狀態,"true"代表執行正常,"false"代表執行失敗.
2100
	#$result["error"],錯誤訊息陣列.
2101
	#$result["function"],當前執行的函數名稱.
2102
	#$result["argu"],使用的參數.
2103
	#$result["createdFileName"],建立好的檔案名稱.
2104
	#$result["createdFilePath"],檔案建立的路徑.
2105
	#$result["createdFilePathAndName"].建立好的檔案名稱與路徑.
2106
	#必填參數:
2107
	#$conf["checkedFileAndPath"],字串陣列,要建立的檔案路徑
2108
	$conf["checkedFileAndPath"]="";
2109
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2110
	$conf["fileArgu"]=__FILE__;
2111
	#可省略參數:
2112
	#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點.
2113
	#$conf["filenameExtensionStartPoint"]="";
2114
	#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)".
2115
	#$conf["repeatNameRule"]="";
2116
	#$conf["web"],"true"代表為網頁系統,"false"代表檔案系統,預設為"false".
2117
	#$conf["web"]="false";
2118
	#參考資料:
2119
	#無.
2120
	#備註:
2121
	#如果要在/tmp底下建立檔案,若在apache環境下則會被作業系統特殊處理,即不等於實際上的路徑.
2122
	*/
2123
	public static function createFileAfterCheck(&$conf){
226 liveuser 2124
 
3 liveuser 2125
		#初始化要回傳的結果
2126
		$result=array();
226 liveuser 2127
 
3 liveuser 2128
		#設置當前執行的涵式
2129
		$result["function"]=__FUNCTION__;
226 liveuser 2130
 
3 liveuser 2131
		#如果 $conf 不為陣列
2132
		if(gettype($conf)!="array"){
226 liveuser 2133
 
3 liveuser 2134
			#設置執行失敗
2135
			$result["status"]="false";
226 liveuser 2136
 
3 liveuser 2137
			#設置執行錯誤訊息
2138
			$result["error"][]="\$conf變數須為陣列形態";
2139
 
2140
			#如果傳入的參數為 null
2141
			if($conf==null){
226 liveuser 2142
 
3 liveuser 2143
				#設置執行錯誤訊息
2144
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 2145
 
3 liveuser 2146
				}#if end
2147
 
2148
			#回傳結果
2149
			return $result;
226 liveuser 2150
 
3 liveuser 2151
			}#if end
226 liveuser 2152
 
3 liveuser 2153
		#取得參數
2154
		$result["argu"]=$conf;
226 liveuser 2155
 
3 liveuser 2156
		#檢查參數
2157
		#函式說明:
2158
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2159
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2160
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2161
		#$result["function"],當前執行的函式名稱.
2162
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2163
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2164
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2165
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
2166
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
2167
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
2168
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
2169
		#必填寫的參數:
2170
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2171
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2172
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2173
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","checkedFileAndPath");
226 liveuser 2174
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 2175
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
2176
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2177
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2178
		#可以省略的參數:
2179
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
2180
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2181
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2182
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("filenameExtensionStartPoint","repeatNameRule","web");
226 liveuser 2183
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 2184
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
2185
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2186
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("1","(\$i)","false");
2187
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2188
		#$conf["arrayCountEqualCheck"][]=array();
2189
		#參考資料來源:
2190
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2191
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2192
		unset($conf["variableCheck::checkArguments"]);
2193
 
2194
		#如果 $checkArguments["status"] 等於 "false"
2195
		if($checkArguments["status"]=="false"){
226 liveuser 2196
 
3 liveuser 2197
			#設置錯誤識別
2198
			$result["status"]="false";
226 liveuser 2199
 
3 liveuser 2200
			#設置錯誤訊息
2201
			$result["error"]=$checkArguments;
226 liveuser 2202
 
3 liveuser 2203
			#回傳結果
226 liveuser 2204
			return $result;
2205
 
3 liveuser 2206
			}#if end
226 liveuser 2207
 
3 liveuser 2208
		#如果 $checkArguments["passed"] 等於 "false"
2209
		if($checkArguments["passed"]=="false"){
226 liveuser 2210
 
3 liveuser 2211
			#設置錯誤識別
2212
			$result["status"]="false";
226 liveuser 2213
 
3 liveuser 2214
			#設置錯誤訊息
2215
			$result["error"]=$checkArguments;
226 liveuser 2216
 
3 liveuser 2217
			#回傳結果
226 liveuser 2218
			return $result;
2219
 
2220
			}#if end
2221
 
3 liveuser 2222
		#確保要建立檔案的路徑
2223
		#函式說明:
2224
		#確保路徑存在.
2225
		#回傳結果:
2226
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
2227
		#$result["error"],錯誤訊息陣列.
2228
		#$resutl["function"],當前執行的涵式名稱.
2229
		#$result["path"],建立好的路徑字串.
2230
		#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
2231
		#必填參數:
2232
		#$conf["path"],要檢查的路徑
226 liveuser 2233
		$conf["fileAccess::validatePath"]["path"]=$conf["checkedFileAndPath"];
3 liveuser 2234
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2235
		$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
2236
		#可省略參數:
2237
		#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
2238
		$conf["fileAccess::validatePath"]["haveFileName"]="true";
2239
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
2240
		#$conf["dirPermission"]="";
2241
		$conf["fileAccess::validatePath"]["web"]=$conf["web"];
2242
		$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
226 liveuser 2243
		unset($conf["fileAccess::validatePath"]);
2244
 
3 liveuser 2245
		#debug
2246
		#var_dump($validatePath);
226 liveuser 2247
		#exit;
2248
 
3 liveuser 2249
		#如果確保路徑失敗
2250
		if($validatePath["status"]==="false"){
226 liveuser 2251
 
3 liveuser 2252
			#設置錯誤識別
2253
			$result["status"]="false";
226 liveuser 2254
 
3 liveuser 2255
			#設置錯誤訊息
2256
			$result["error"]=$validatePath;
226 liveuser 2257
 
3 liveuser 2258
			#回傳結果
2259
			return $result;
226 liveuser 2260
 
3 liveuser 2261
			}#if end
226 liveuser 2262
 
3 liveuser 2263
		#取得要建立的檔案名稱
2264
		$createdFileName=$validatePath["fileName"];
226 liveuser 2265
 
2266
		#取得要建立的路徑
3 liveuser 2267
		$createdFilePath=$validatePath["path"];
226 liveuser 2268
 
3 liveuser 2269
		#透過無窮迴圈嘗試建立不同編號的檔案
2270
		for($i=0;$i>-1;$i++){
226 liveuser 2271
 
3 liveuser 2272
			#如果 $i 為 0
2273
			if($i==0){
226 liveuser 2274
 
3 liveuser 2275
				#檢查該檔案是否存在
2276
				#函式說明:
2277
				#檢查多個檔案與資料夾是否存在.
2278
				#回傳的結果:
2279
				#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
2280
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
2281
				#必填參數:
2282
				$conf["fileAccess"]["checkMutiFileExist"]["fileArray"]=array($createdFilePath."/".$createdFileName);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
2283
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2284
				$conf["fileAccess"]["checkMutiFileExist"]["fileArgu"]=$conf["fileArgu"];
2285
				#參考資料來源:
2286
				#http://php.net/manual/en/function.file-exists.php
2287
				#http://php.net/manual/en/control-structures.foreach.php
2288
				$conf["fileAccess"]["checkMutiFileExist"]["web"]=$conf["web"];
2289
				$checkResult=fileAccess::checkMultiFileExist($conf["fileAccess"]["checkMutiFileExist"]);
2290
				unset($conf["fileAccess"]["checkMutiFileExist"]);
226 liveuser 2291
 
3 liveuser 2292
				#debug
2293
				#var_dump($checkResult);
2294
				#exit;
226 liveuser 2295
 
3 liveuser 2296
				#如果檢查檔案是否存在失敗
2297
				if($checkResult["status"]=="false"){
226 liveuser 2298
 
3 liveuser 2299
					#設置執行失敗
2300
					$result["status"]="false";
226 liveuser 2301
 
3 liveuser 2302
					#設置錯誤訊息
2303
					$result["error"]=$checkResult;
226 liveuser 2304
 
3 liveuser 2305
					#回傳結果
2306
					return $result;
226 liveuser 2307
 
3 liveuser 2308
					}#if end
226 liveuser 2309
 
3 liveuser 2310
				#如果 $createFilePath.$createdFileName 檔案存在
2311
				if($checkResult["varExist"][0]=="true"){
226 liveuser 2312
 
3 liveuser 2313
					#跳過這次迴圈
2314
					continue;
226 liveuser 2315
 
3 liveuser 2316
					}#if end
226 liveuser 2317
 
3 liveuser 2318
				#反之代表 $createFilePath.$createdFileName 檔案不存在
2319
				else{
226 liveuser 2320
 
3 liveuser 2321
					#嘗試建立該檔案
2322
					#函式說明:
2323
					#將字串寫入到檔案
2324
					#回傳結果:
2325
					#$result["status"],true表示檔案寫入成功,false表示檔案寫入失敗.
2326
					#$result["error"],錯誤訊息陣列.
2327
					#必填參數:
2328
					$conf["fileAccess"]["writeTextIntoFile"]["fileName"]=$createdFilePath."/".$createdFileName;#爲要編輯的檔案名稱
2329
					$conf["fileAccess"]["writeTextIntoFile"]["inputString"]="";#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
2330
					$conf["fileAccess"]["writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
2331
					#可省略參數:
2332
					$conf["fileAccess"]["writeTextIntoFile"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
2333
					$conf["fileAccess"]["writeTextIntoFile"]["web"]=$conf["web"];
2334
					$fileCreateResult=fileAccess::writeTextIntoFile($conf["fileAccess"]["writeTextIntoFile"]);
2335
					unset($conf["fileAccess"]["writeTextIntoFile"]);
226 liveuser 2336
 
3 liveuser 2337
					#如果 $fileCreateResult["status"] 等於 "true"
2338
					if($fileCreateResult["status"]=="true"){
226 liveuser 2339
 
3 liveuser 2340
						#代表檔案建立成功
226 liveuser 2341
 
3 liveuser 2342
						#更新建立的檔案名稱
2343
						$result["createdFileName"]=$createdFileName;
226 liveuser 2344
 
3 liveuser 2345
						#設置新建立的檔案名稱與路徑
2346
						$result["createdFilePathAndName"]=$createdFilePath."/".$result["createdFileName"];
226 liveuser 2347
 
3 liveuser 2348
						#設置新建立的檔與路徑
2349
						$result["createdFilePath"]=$createdFilePath;
226 liveuser 2350
 
3 liveuser 2351
						#跳出迴圈
2352
						break;
226 liveuser 2353
 
3 liveuser 2354
						}#if end
226 liveuser 2355
 
3 liveuser 2356
					#反之代表檔案建立失敗
2357
					else{
226 liveuser 2358
 
3 liveuser 2359
						#設置錯誤識別
2360
						$result["status"]="false";
226 liveuser 2361
 
3 liveuser 2362
						#設置錯誤訊息
2363
						$result["error"]=$fileCreateResult;
226 liveuser 2364
 
3 liveuser 2365
						#回傳結果
2366
						return $result;
226 liveuser 2367
 
3 liveuser 2368
						}#else end
226 liveuser 2369
 
2370
					}#else end
2371
 
3 liveuser 2372
				}#if end
226 liveuser 2373
 
3 liveuser 2374
			#反之代表有相同檔名存在
226 liveuser 2375
			else{
2376
 
3 liveuser 2377
				#用「.」分割檔案名稱
2378
				#函式說明:
2379
				#將固定格式的字串分開,並回傳分開的結果。
2380
				#回傳結果:
2381
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2382
				#$result["error"],錯誤訊息陣列
2383
				#$result["function"],當前執行的函數名稱.
2384
				#$result["oriStr"],要分割的原始字串內容
2385
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
2386
				#$result["dataCounts"],爲總共分成幾段
2387
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
2388
				#必填參數:
2389
				$conf["stringProcess::spiltString"]["stringIn"]=$createdFileName;#要處理的字串。
2390
				$conf["stringProcess::spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
2391
				#可省略參數:
2392
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
2393
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
2394
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 2395
				unset($conf["stringProcess::spiltString"]);
2396
 
3 liveuser 2397
				#如果分割檔案名稱失敗
2398
				if($spiltString["status"]=="false"){
226 liveuser 2399
 
3 liveuser 2400
					#設置執行失敗
2401
					$result["status"]="false";
226 liveuser 2402
 
3 liveuser 2403
					#設置錯誤訊息
2404
					$result["error"]=$spiltString;
226 liveuser 2405
 
3 liveuser 2406
					#回傳結果
2407
					return $result;
226 liveuser 2408
 
3 liveuser 2409
					}#if end
226 liveuser 2410
 
3 liveuser 2411
				#初始化儲存建立的檔案名稱
2412
				$createdFileName="";
226 liveuser 2413
 
3 liveuser 2414
				#初始化儲存編號的變數
2415
				$no="";
226 liveuser 2416
 
3 liveuser 2417
				#如果沒有dot存在
2418
				if($spiltString["found"]=="false"){
226 liveuser 2419
 
3 liveuser 2420
					#解析 $conf["repeatNameRule"],用 \$i 分割.
2421
					#函式說明:
2422
					#將固定格式的字串分開,並回傳分開的結果。
2423
					#回傳結果:
2424
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2425
					#$result["error"],錯誤訊息陣列
2426
					#$result["function"],當前執行的函數名稱.
2427
					#$result["oriStr"],要分割的原始字串內容
2428
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
2429
					#$result["dataCounts"],爲總共分成幾段
2430
					#必填參數:
2431
					$conf["stringProcess::spiltString"]["stringIn"]=$conf["repeatNameRule"];#要處理的字串。
2432
					$conf["stringProcess::spiltString"]["spiltSymbol"]="\$i";#爲以哪個符號作爲分割
2433
					#可省略參數:
2434
					#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
2435
					$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
2436
					$noString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 2437
					unset($conf["stringProcess::spiltString"]);
2438
 
3 liveuser 2439
					#如果分割檔案名稱失敗
2440
					if($noString["status"]=="false"){
226 liveuser 2441
 
3 liveuser 2442
						#設置執行失敗
2443
						$result["status"]="false";
226 liveuser 2444
 
3 liveuser 2445
						#設置錯誤訊息
2446
						$result["error"]=$noString;
226 liveuser 2447
 
3 liveuser 2448
						#回傳結果
2449
						return $result;
226 liveuser 2450
 
3 liveuser 2451
						}#if end
226 liveuser 2452
 
3 liveuser 2453
					#如果 編號規則字串 分割出來的段數為2
2454
					if($noString["dataCounts"]==2){
226 liveuser 2455
 
3 liveuser 2456
						#組合編號
2457
						$no=$noString["dataArray"][0].$i.$noString["dataArray"][1];
226 liveuser 2458
 
3 liveuser 2459
						}#if end
226 liveuser 2460
 
3 liveuser 2461
					#反之 號規則字串 分割出來的段數為1
2462
					else if($noString["dataCounts"]==1){
226 liveuser 2463
 
3 liveuser 2464
						#判斷 "\$i" 在開頭或結尾
2465
						#函式說明:
2466
						#取得關鍵字在字串的哪個位置
2467
						#回傳結果:
2468
						#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
2469
						#$result["error"],錯誤訊息陣列.
2470
						#$result["function"],當前執行的函數名稱.
2471
						#$result["argu"],傳入的參數.
2472
						#$result["head"],關鍵字是否在字串的開頭,"true"代表是,"false"代表不是.
2473
						#$result["tail"],關鍵字是否在字串的尾端,"true"代表是,"false"代表不是.
2474
						#$result["center"],關鍵字是否在字串的中間,"true"代表是,"false"代表不是.
2475
						#必填參數:
2476
						#$conf["inputStr"],字串,被搜尋的字串.
2477
						$conf["search::findKeyWordPosition"]["inputStr"]=$conf["repeatNameRule"];
2478
						#$conf["keyWord"],字串,關鍵字.
2479
						$conf["search::findKeyWordPosition"]["keyWord"]="\$i";
2480
						#參考資料:
2481
						#http://php.net/manual/en/function.strpos.php
2482
						$findKeyWordPosition=search::findKeyWordPosition($conf["search::findKeyWordPosition"]);
2483
						unset($conf["search::findKeyWordPosition"]);
226 liveuser 2484
 
3 liveuser 2485
						#如果取得關鍵字位置失敗
2486
						if($findKeyWordPosition["status"]=="false"){
226 liveuser 2487
 
3 liveuser 2488
							#設置執行失敗
2489
							$result["status"]="false";
226 liveuser 2490
 
3 liveuser 2491
							#設置錯誤訊息
2492
							$result["error"]=$findKeyWordPosition;
226 liveuser 2493
 
3 liveuser 2494
							#回傳結果
2495
							return $result;
226 liveuser 2496
 
3 liveuser 2497
							}#if end
226 liveuser 2498
 
3 liveuser 2499
						#如果關鍵字在開頭
2500
						if($findKeyWordPosition["head"]=="true"){
226 liveuser 2501
 
3 liveuser 2502
							#組合編號
2503
							$no=$i.$noString["dataArray"][0];
226 liveuser 2504
 
3 liveuser 2505
							}#if end
226 liveuser 2506
 
3 liveuser 2507
						#反之如果關鍵字在結尾
2508
						else if($findKeyWordPosition["tail"]=="true"){
226 liveuser 2509
 
3 liveuser 2510
							#組合編號
2511
							$no=$noString["dataArray"][0].$i;
226 liveuser 2512
 
3 liveuser 2513
							}#if end
226 liveuser 2514
 
3 liveuser 2515
						#其他情況
2516
						else{
226 liveuser 2517
 
3 liveuser 2518
							#設置執行失敗
2519
							$result["status"]="false";
226 liveuser 2520
 
3 liveuser 2521
							#設置錯誤訊息
2522
							$result["error"]=$findKeyWordPosition;
226 liveuser 2523
 
3 liveuser 2524
							#設置額外的錯誤訊息
2525
							$result["error"][]="非預期的結果";
226 liveuser 2526
 
3 liveuser 2527
							#回傳結果
2528
							return $result;
226 liveuser 2529
 
3 liveuser 2530
							}#else end
226 liveuser 2531
 
3 liveuser 2532
						}#if end
226 liveuser 2533
 
3 liveuser 2534
					#反之 編號規則字串 分割出來的段數為0
2535
					else if($noString["dataCounts"]==0){
226 liveuser 2536
 
3 liveuser 2537
						#組合編號
2538
						$no=$j;
226 liveuser 2539
 
3 liveuser 2540
						}#if end
226 liveuser 2541
 
3 liveuser 2542
					#其他結果
2543
					else{
226 liveuser 2544
 
3 liveuser 2545
						#設置執行失敗
2546
						$result["status"]="false";
226 liveuser 2547
 
3 liveuser 2548
						#設置錯誤訊息
2549
						$result["error"]=$noString;
226 liveuser 2550
 
3 liveuser 2551
						#設置額外的錯誤訊息
2552
						$result["error"][]="非預期的結果";
226 liveuser 2553
 
3 liveuser 2554
						#回傳結果
2555
						return $result;
226 liveuser 2556
 
2557
						}#else end
2558
 
3 liveuser 2559
					#串接編號到檔案名稱上
2560
					$createdFileName=$validatePath["fileName"].$no;
226 liveuser 2561
 
3 liveuser 2562
					}#if end
226 liveuser 2563
 
2564
				#反之有dot存在
3 liveuser 2565
				else{
226 liveuser 2566
 
3 liveuser 2567
					#依據 $spiltString["dataCounts"] 值來組裝新的檔案名稱
2568
					for($j=0;$j<$spiltString["dataCounts"];$j++){
226 liveuser 2569
 
3 liveuser 2570
						#如果是副檔名的前一段內容
2571
						if(($conf["filenameExtensionStartPoint"]+1)==($spiltString["dataCounts"]-$j)){
226 liveuser 2572
 
3 liveuser 2573
							#解析 $conf["repeatNameRule"],用 \$i 分割.
2574
							#函式說明:
2575
							#將固定格式的字串分開,並回傳分開的結果。
2576
							#回傳結果:
2577
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2578
							#$result["error"],錯誤訊息陣列
2579
							#$result["function"],當前執行的函數名稱.
2580
							#$result["oriStr"],要分割的原始字串內容
2581
							#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
2582
							#$result["dataCounts"],爲總共分成幾段
2583
							#必填參數:
2584
							$conf["stringProcess::spiltString"]["stringIn"]=$conf["repeatNameRule"];#要處理的字串。
2585
							$conf["stringProcess::spiltString"]["spiltSymbol"]="\$i";#爲以哪個符號作爲分割
2586
							#可省略參數:
2587
							#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
2588
							$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
2589
							$noString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 2590
							unset($conf["stringProcess::spiltString"]);
2591
 
3 liveuser 2592
							#如果分割檔案名稱失敗
2593
							if($noString["status"]=="false"){
226 liveuser 2594
 
3 liveuser 2595
								#設置執行失敗
2596
								$result["status"]="false";
226 liveuser 2597
 
3 liveuser 2598
								#設置錯誤訊息
2599
								$result["error"]=$noString;
226 liveuser 2600
 
3 liveuser 2601
								#回傳結果
2602
								return $result;
226 liveuser 2603
 
3 liveuser 2604
								}#if end
226 liveuser 2605
 
3 liveuser 2606
							#如果 編號規則字串 分割出來的段數為2
2607
							if($noString["dataCounts"]==2){
226 liveuser 2608
 
3 liveuser 2609
								#組合編號
2610
								$no=$noString["dataArray"][0].$i.$noString["dataArray"][1];
226 liveuser 2611
 
3 liveuser 2612
								}#if end
226 liveuser 2613
 
3 liveuser 2614
							#反之 號規則字串 分割出來的段數為1
2615
							else if($noString["dataCounts"]==1){
226 liveuser 2616
 
3 liveuser 2617
								#判斷 "\$i" 在開頭或結尾
2618
								#函式說明:
2619
								#取得關鍵字在字串的哪個位置
2620
								#回傳結果:
2621
								#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
2622
								#$result["error"],錯誤訊息陣列.
2623
								#$result["function"],當前執行的函數名稱.
2624
								#$result["argu"],傳入的參數.
2625
								#$result["head"],關鍵字是否在字串的開頭,"true"代表是,"false"代表不是.
2626
								#$result["tail"],關鍵字是否在字串的尾端,"true"代表是,"false"代表不是.
2627
								#$result["center"],關鍵字是否在字串的中間,"true"代表是,"false"代表不是.
2628
								#必填參數:
2629
								#$conf["inputStr"],字串,被搜尋的字串.
2630
								$conf["search::findKeyWordPosition"]["inputStr"]=$conf["repeatNameRule"];
2631
								#$conf["keyWord"],字串,關鍵字.
2632
								$conf["search::findKeyWordPosition"]["keyWord"]="\$i";
2633
								#參考資料:
2634
								#http://php.net/manual/en/function.strpos.php
2635
								$findKeyWordPosition=search::findKeyWordPosition($conf["search::findKeyWordPosition"]);
2636
								unset($conf["search::findKeyWordPosition"]);
226 liveuser 2637
 
3 liveuser 2638
								#如果取得關鍵字位置失敗
2639
								if($findKeyWordPosition["status"]=="false"){
226 liveuser 2640
 
3 liveuser 2641
									#設置執行失敗
2642
									$result["status"]="false";
226 liveuser 2643
 
3 liveuser 2644
									#設置錯誤訊息
2645
									$result["error"]=$findKeyWordPosition;
226 liveuser 2646
 
3 liveuser 2647
									#回傳結果
2648
									return $result;
226 liveuser 2649
 
3 liveuser 2650
									}#if end
226 liveuser 2651
 
3 liveuser 2652
								#如果關鍵字在開頭
2653
								if($findKeyWordPosition["head"]=="true"){
226 liveuser 2654
 
3 liveuser 2655
									#組合編號
2656
									$no=$i.$noString["dataArray"][0];
226 liveuser 2657
 
3 liveuser 2658
									}#if end
226 liveuser 2659
 
3 liveuser 2660
								#反之如果關鍵字在結尾
2661
								else if($findKeyWordPosition["tail"]=="true"){
226 liveuser 2662
 
3 liveuser 2663
									#組合編號
2664
									$no=$noString["dataArray"][0].$i;
226 liveuser 2665
 
3 liveuser 2666
									}#if end
226 liveuser 2667
 
3 liveuser 2668
								#其他情況
2669
								else{
226 liveuser 2670
 
3 liveuser 2671
									#設置執行失敗
2672
									$result["status"]="false";
226 liveuser 2673
 
3 liveuser 2674
									#設置錯誤訊息
2675
									$result["error"]=$findKeyWordPosition;
226 liveuser 2676
 
3 liveuser 2677
									#設置額外的錯誤訊息
2678
									$result["error"][]="非預期的結果";
226 liveuser 2679
 
3 liveuser 2680
									#回傳結果
2681
									return $result;
226 liveuser 2682
 
3 liveuser 2683
									}#else end
226 liveuser 2684
 
3 liveuser 2685
								}#if end
226 liveuser 2686
 
3 liveuser 2687
							#反之 編號規則字串 分割出來的段數為0
2688
							else if($noString["dataCounts"]==0){
226 liveuser 2689
 
3 liveuser 2690
								#組合編號
2691
								$no=$j;
226 liveuser 2692
 
3 liveuser 2693
								}#if end
226 liveuser 2694
 
3 liveuser 2695
							#其他結果
2696
							else{
226 liveuser 2697
 
3 liveuser 2698
								#設置執行失敗
2699
								$result["status"]="false";
226 liveuser 2700
 
3 liveuser 2701
								#設置錯誤訊息
2702
								$result["error"]=$noString;
226 liveuser 2703
 
3 liveuser 2704
								#設置額外的錯誤訊息
2705
								$result["error"][]="非預期的結果";
226 liveuser 2706
 
3 liveuser 2707
								#回傳結果
2708
								return $result;
226 liveuser 2709
 
2710
								}#else end
2711
 
3 liveuser 2712
							#串接編號到檔案名稱上
2713
							$createdFileName=$createdFileName.$spiltString["dataArray"][$j].$no;
226 liveuser 2714
 
3 liveuser 2715
							#如果不是最後一段
2716
							if($j!=$spiltString["dataCounts"]-1){
226 liveuser 2717
 
3 liveuser 2718
								#串接並加上 dot
2719
								$createdFileName=$createdFileName.".";
226 liveuser 2720
 
3 liveuser 2721
								}#if end
226 liveuser 2722
 
3 liveuser 2723
							}#if end
226 liveuser 2724
 
3 liveuser 2725
						#反之如果不是最後一段
2726
						else if($j!=$spiltString["dataCounts"]-1){
226 liveuser 2727
 
3 liveuser 2728
							#串接並加上 dot
2729
							$createdFileName=$createdFileName.$spiltString["dataArray"][$j].".";
226 liveuser 2730
 
3 liveuser 2731
							}#if end
226 liveuser 2732
 
2733
						#反之是最後一段
3 liveuser 2734
						else{
226 liveuser 2735
 
3 liveuser 2736
							#串接並加上 dot
2737
							$createdFileName=$createdFileName.$spiltString["dataArray"][$j];
226 liveuser 2738
 
3 liveuser 2739
							}#else end
226 liveuser 2740
 
3 liveuser 2741
						}#for end
226 liveuser 2742
 
3 liveuser 2743
					}#else end
226 liveuser 2744
 
3 liveuser 2745
				#檢查加上編號的檔案是否存在
2746
				#函式說明:
2747
				#檢查多個檔案與資料夾是否存在.
2748
				#回傳的結果:
2749
				#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
2750
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
2751
				#必填參數:
2752
				$conf["fileAccess"]["checkMutiFileExist"]["fileArray"]=array($createdFilePath."/".$createdFileName);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
2753
				$conf["fileAccess"]["checkMutiFileExist"]["fileArgu"]=$conf["fileArgu"];
2754
				#參考資料來源:
2755
				#http://php.net/manual/en/function.file-exists.php
2756
				#http://php.net/manual/en/control-structures.foreach.php
2757
				$conf["fileAccess"]["checkMutiFileExist"]["web"]=$conf["web"];
2758
				$checkResult=fileAccess::checkMultiFileExist($conf["fileAccess"]["checkMutiFileExist"]);
2759
				unset($conf["fileAccess"]["checkMutiFileExist"]);
226 liveuser 2760
 
3 liveuser 2761
				#如果檢查檔案是否存在失敗
2762
				if($checkResult["status"]=="false"){
226 liveuser 2763
 
3 liveuser 2764
					#設置執行失敗
2765
					$result["status"]="false";
226 liveuser 2766
 
3 liveuser 2767
					#設置錯誤訊息
2768
					$result["error"]=$checkResult;
226 liveuser 2769
 
3 liveuser 2770
					#回傳結果
2771
					return $result;
226 liveuser 2772
 
2773
					}#if end
2774
 
3 liveuser 2775
				#如果 $checkResult["varExist"][0] 等於 "true"
226 liveuser 2776
				if($checkResult["varExist"][0]=="true"){
2777
 
3 liveuser 2778
					#取得要建立的檔案名稱
2779
					$createdFileName=$validatePath["fileName"];
226 liveuser 2780
 
3 liveuser 2781
					#跳到下個迴圈
2782
					continue;
226 liveuser 2783
 
3 liveuser 2784
					}#if end
226 liveuser 2785
 
3 liveuser 2786
				#反之代表 $createFilePath.$createdFileName."(".$i.")" 檔檔案不存在
2787
				else{
226 liveuser 2788
 
3 liveuser 2789
					#嘗試建立該檔案
2790
					#函式說明:
2791
					#將字串寫入到檔案
2792
					#回傳結果:
2793
					#$result["status"],true表示檔案寫入成功,false表示檔案寫入失敗.
2794
					#$result["error"],錯誤訊息陣列.
2795
					#必填參數:
2796
					$conf["fileAccess"]["writeTextIntoFile"]["fileName"]=$createdFilePath."/".$createdFileName;#爲要編輯的檔案名稱
2797
					$conf["fileAccess"]["writeTextIntoFile"]["inputString"]="";#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
2798
					$conf["fileAccess"]["writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
2799
					#可省略參數:
2800
					$conf["fileAccess"]["writeTextIntoFile"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
2801
					$conf["fileAccess"]["writeTextIntoFile"]["web"]=$conf["web"];
2802
					$fileCreateResult=fileAccess::writeTextIntoFile($conf["fileAccess"]["writeTextIntoFile"]);
2803
					unset($conf["fileAccess"]["writeTextIntoFile"]);
226 liveuser 2804
 
3 liveuser 2805
					#如果 $fileCreateResult["status"] 等於 "true"
2806
					if($fileCreateResult["status"]=="true"){
226 liveuser 2807
 
3 liveuser 2808
						#代表檔案建立成功
226 liveuser 2809
 
3 liveuser 2810
						#更新建立的檔案名稱
2811
						$result["createdFileName"]=$createdFileName;
226 liveuser 2812
 
3 liveuser 2813
						#跳出迴圈
2814
						break;
226 liveuser 2815
 
3 liveuser 2816
						}#if end
226 liveuser 2817
 
3 liveuser 2818
					#反之代表檔案建立失敗
2819
					else{
226 liveuser 2820
 
3 liveuser 2821
						#設置錯誤識別
2822
						$result["status"]="false";
226 liveuser 2823
 
3 liveuser 2824
						#設置錯誤訊息
2825
						$result["error"]=$fileCreateResult;
226 liveuser 2826
 
3 liveuser 2827
						#回傳結果
2828
						return $result;
226 liveuser 2829
 
3 liveuser 2830
						}#else end
226 liveuser 2831
 
3 liveuser 2832
					}#else end
226 liveuser 2833
 
3 liveuser 2834
				}#else end
226 liveuser 2835
 
3 liveuser 2836
			}#for end
226 liveuser 2837
 
3 liveuser 2838
		#如果不存在建立的檔案名稱
2839
		if(!isset($result["createdFileName"])){
226 liveuser 2840
 
3 liveuser 2841
			#設置錯誤識別
2842
			$result["status"]="false";
226 liveuser 2843
 
3 liveuser 2844
			#設置錯誤訊息
2845
			$result["error"][]="建立的檔案名稱不存在";
226 liveuser 2846
 
3 liveuser 2847
			#回傳結果
2848
			return $result;
226 liveuser 2849
 
2850
			}#if end
2851
 
3 liveuser 2852
		#執行到這邊代表執行成功
2853
		$result["status"]="true";
226 liveuser 2854
 
3 liveuser 2855
		#設置新建立的檔案名稱與路徑
2856
		$result["createdFilePathAndName"]=$createdFilePath."/".$result["createdFileName"];
226 liveuser 2857
 
3 liveuser 2858
		#設置新建立的檔與路徑
2859
		$result["createdFilePath"]=$createdFilePath;
226 liveuser 2860
 
3 liveuser 2861
		#回傳結果
2862
		return $result;
226 liveuser 2863
 
3 liveuser 2864
		}#fucntion createFileAfterCheck end
2865
 
2866
	/*
2867
	#函式說明:
2868
	#將檔案內容清空
2869
	#回傳結果:
2870
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
2871
	#$result["error"],錯誤訊息陣列
2872
	#必填參數:
2873
	#$conf["fileAddr"],字串,要清空的檔案位置與名稱.
2874
	$conf["fileAddr"]="";
2875
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2876
	$conf["fileArgu"]=__FILE__;
2877
	#可省略參數:
2878
	#$conf["web"],"true"代表為網頁系統,"false"代表檔案系統,預設為"false".
2879
	#$conf["web"]="false";
2880
	#參考資料:
2881
	#無.
2882
	#備註:
2883
	#無.
2884
	*/
2885
	public static function emptyFile(&$conf){
226 liveuser 2886
 
3 liveuser 2887
		#初始化要回傳的結果
2888
		$result=array();
226 liveuser 2889
 
3 liveuser 2890
		#設置當前執行的涵式
2891
		$result["function"]=__FUNCTION__;
226 liveuser 2892
 
3 liveuser 2893
		#如果 $conf 不為陣列
2894
		if(gettype($conf)!="array"){
226 liveuser 2895
 
3 liveuser 2896
			#設置執行失敗
2897
			$result["status"]="false";
226 liveuser 2898
 
3 liveuser 2899
			#設置執行錯誤訊息
2900
			$result["error"][]="\$conf變數須為陣列形態";
2901
 
2902
			#如果傳入的參數為 null
2903
			if($conf==null){
226 liveuser 2904
 
3 liveuser 2905
				#設置執行錯誤訊息
2906
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 2907
 
3 liveuser 2908
				}#if end
2909
 
2910
			#回傳結果
2911
			return $result;
226 liveuser 2912
 
3 liveuser 2913
			}#if end
226 liveuser 2914
 
3 liveuser 2915
		#取得參數
2916
		$result["argu"]=$conf;
226 liveuser 2917
 
3 liveuser 2918
		#檢查參數
2919
		#函式說明:
2920
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2921
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2922
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2923
		#$result["function"],當前執行的函式名稱.
2924
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2925
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2926
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2927
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
2928
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
2929
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
2930
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
2931
		#必填寫的參數:
2932
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2933
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2934
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2935
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","fileAddr");
226 liveuser 2936
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 2937
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
2938
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2939
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2940
		#可以省略的參數:
2941
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
2942
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2943
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2944
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
226 liveuser 2945
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 2946
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
2947
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2948
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
2949
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2950
		#$conf["arrayCountEqualCheck"][]=array();
2951
		#參考資料來源:
2952
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2953
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2954
		unset($conf["variableCheck::checkArguments"]);
2955
 
2956
		#如果 $checkArguments["status"] 等於 "false"
2957
		if($checkArguments["status"]=="false"){
226 liveuser 2958
 
3 liveuser 2959
			#設置錯誤識別
2960
			$result["status"]="false";
226 liveuser 2961
 
3 liveuser 2962
			#設置錯誤訊息
2963
			$result["error"]=$checkArguments;
226 liveuser 2964
 
3 liveuser 2965
			#回傳結果
226 liveuser 2966
			return $result;
2967
 
3 liveuser 2968
			}#if end
226 liveuser 2969
 
3 liveuser 2970
		#如果 $checkArguments["passed"] 等於 "false"
2971
		if($checkArguments["passed"]=="false"){
226 liveuser 2972
 
3 liveuser 2973
			#設置錯誤識別
2974
			$result["status"]="false";
226 liveuser 2975
 
3 liveuser 2976
			#設置錯誤訊息
2977
			$result["error"]=$checkArguments;
226 liveuser 2978
 
3 liveuser 2979
			#回傳結果
226 liveuser 2980
			return $result;
2981
 
2982
			}#if end
2983
 
3 liveuser 2984
		#函式說明:
2985
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
2986
		#回傳結果:
2987
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
2988
		#$result["error"],錯誤訊息陣列.
226 liveuser 2989
		#$result["function"],函數名稱.
3 liveuser 2990
		#$result["argu"],使用的參數.
2991
		#$result["content"],網址,若是在命令列執行,則為"null".
2992
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
2993
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
2994
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
2995
		#必填參數:
2996
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
2997
		$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["fileAddr"];
2998
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
2999
		$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
3000
		#可省略參數:
3001
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
3002
		$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
3003
		#備註:
3004
		#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
3005
		$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
3006
		unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 3007
 
3 liveuser 3008
		#如果確保路徑失敗
3009
		if($getInternetAddressV2["status"]==="false"){
226 liveuser 3010
 
3 liveuser 3011
			#設置錯誤識別
3012
			$result["status"]="false";
226 liveuser 3013
 
3 liveuser 3014
			#設置錯誤訊息
3015
			$result["error"]=$getInternetAddressV2;
226 liveuser 3016
 
3 liveuser 3017
			#回傳結果
3018
			return $result;
226 liveuser 3019
 
3 liveuser 3020
			}#if end
226 liveuser 3021
 
3 liveuser 3022
		#更新檔案路徑
3023
		$conf["fileAddr"]=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 3024
 
3 liveuser 3025
		#確保要建立檔案的路徑
3026
		#函式說明:
3027
		#確保路徑存在.
3028
		#回傳結果:
3029
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
3030
		#$result["error"],錯誤訊息陣列.
3031
		#$resutl["function"],當前執行的涵式名稱.
3032
		#$result["path"],建立好的路徑字串.
3033
		#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
3034
		#必填參數:
3035
		#$conf["path"],要檢查的路徑
226 liveuser 3036
		$conf["fileAccess::validatePath"]["path"]=$conf["fileAddr"];
3 liveuser 3037
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3038
		$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
3039
		#可省略參數:
3040
		#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
3041
		$conf["fileAccess::validatePath"]["haveFileName"]="true";
3042
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
3043
		#$conf["dirPermission"]="";
3044
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
3045
		$conf["fileAccess::validatePath"]["web"]="false";
3046
		$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
226 liveuser 3047
		unset($conf["fileAccess::validatePath"]);
3048
 
3 liveuser 3049
		#如果確保路徑失敗
3050
		if($validatePath["status"]==="false"){
226 liveuser 3051
 
3 liveuser 3052
			#設置錯誤識別
3053
			$result["status"]="false";
226 liveuser 3054
 
3 liveuser 3055
			#設置錯誤訊息
3056
			$result["error"]=$validatePath;
226 liveuser 3057
 
3 liveuser 3058
			#回傳結果
3059
			return $result;
226 liveuser 3060
 
3 liveuser 3061
			}#if end
226 liveuser 3062
 
3 liveuser 3063
		#清空檔案
3064
		#函式說明:
3065
		#將字串寫入到檔案
3066
		#回傳結果:
3067
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
3068
		#$result["error"],錯誤訊息陣列.
3069
		#$result["function"],當前執行的函數名稱.
3070
		#$result["fileInfo"],實際上寫入的檔案資訊陣列.
3071
		#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
3072
		#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
3073
		#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
3074
		#$result["argu"],使用的參數.
3075
		#必填參數:
3076
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3077
		$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
3078
		#可省略參數:
3079
		#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
3080
		#$conf["fileAccess::writeTextIntoFile"]["fileName"]=$validatePath["path"]."/".$validatePath["fileName"];
3081
		$conf["fileAccess::writeTextIntoFile"]["fileName"]=$validatePath["path"]."/".$validatePath["fileName"];;
3082
		#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
3083
		#$conf["inputString"]="";
3084
		#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
3085
		#$conf["writeMethod"]="a";
3086
		#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
3087
		#$conf["checkRepeat"]="";
3088
		#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
3089
		#$conf["filenameExtensionStartPoint"]="";
3090
		#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
3091
		#$conf["repeatNameRule"]="";
3092
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
3093
		$conf["fileAccess::writeTextIntoFile"]["web"]="false";
3094
		$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
3095
		unset($conf["fileAccess::writeTextIntoFile"]);
226 liveuser 3096
 
3 liveuser 3097
		#如果確保路徑失敗
3098
		if($writeTextIntoFile["status"]==="false"){
226 liveuser 3099
 
3 liveuser 3100
			#設置錯誤識別
3101
			$result["status"]="false";
226 liveuser 3102
 
3 liveuser 3103
			#設置錯誤訊息
3104
			$result["error"]=$writeTextIntoFile;
226 liveuser 3105
 
3 liveuser 3106
			#回傳結果
3107
			return $result;
226 liveuser 3108
 
3 liveuser 3109
			}#if end
226 liveuser 3110
 
3 liveuser 3111
		#設置執行正常
3112
		$result["status"]="true";
226 liveuser 3113
 
3 liveuser 3114
		#儲存建立的結果
3115
		$result["content"]=$writeTextIntoFile;
226 liveuser 3116
 
3 liveuser 3117
		#回傳結果
3118
		return $result;
226 liveuser 3119
 
3 liveuser 3120
		}#function emptyFile end
3121
 
3122
	/*
3123
	#函式說明:
3124
	#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
3125
	#回傳結果:
3126
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
3127
	#$result["error"],錯誤訊息陣列
3128
	#$result["warning"],警告訊息陣列
3129
	#必填參數:
3130
	#$conf["dirPositionAndName"]="";#新建的位置與名稱
3131
	$conf["dirPositionAndName"]="";
3132
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3133
	$conf["fileArgu"]=__FILE__;
3134
	#可省略參數:
3135
	#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
3136
	#$conf["dirPermission"]="";
3137
	#參考資料:
3138
	#mkdir=>http://php.net/manual/en/function.mkdir.php
3139
	#chmod=>http://php.net/manual/en/function.chmod.php
3140
	#參考資料:
3141
	#無.
3142
	#備註:
3143
	#同 function createFolderAfterCheck.
3144
	*/
3145
	public static function createNewFolder(&$conf){
3146
 
3147
		/*
3148
		#函式說明:
3149
		#檢查要建立的檔案路徑是否存在,若不存在則建立新檔案,若檔案已存在則會在原檔名後面加上從(1)開始的編號,再度嘗試建立檔案,以避免資料異常.
3150
		#回傳的結果:
3151
		#$result["status"],執行狀態,"true"代表執行正常,"false"代表執行失敗.
3152
		#$result["error"],錯誤訊息陣列.
3153
		#$result["function"],當前執行的函數名稱.
3154
		#$result["createdFileName"],建立好的檔案名稱.
3155
		#$result["createdFilePath"],檔案建立的路徑.
3156
		#$result["createdFilePathAndName"].建立好的檔案名稱與路徑.
3157
		#必填參數:
3158
		#$conf["checkedFileAndPath"],字串陣列,要建立的檔案路徑
3159
		$conf["checkedFileAndPath"]="";
3160
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3161
		$conf["fileArgu"]=__FILE__;
3162
		*/
3163
		return fileAccess::createFolderAfterCheck($conf);
3164
		unset($conf);
3165
 
3166
		}#function createNewFolder end
226 liveuser 3167
 
3 liveuser 3168
	/*
3169
	#函式說明:
3170
	#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
3171
	#回傳結果:
3172
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
3173
	#$result["error"],錯誤訊息陣列
3174
	#$result["warning"],警告訊息陣列
3175
	#$result["argu"],使用的參數.
3176
	#$result["content"],建立的目錄路徑.
3177
	#必填參數:
3178
	#$conf["dirPositionAndName"]="";#新建的位置與名稱
3179
	$conf["dirPositionAndName"]="";
3180
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3181
	$conf["fileArgu"]=__FILE__;
3182
	#可省略參數:
3183
	#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
3184
	#$conf["dirPermission"]="";
3185
	#$conf["web"],"false"代表在檔案系統環境,"true"代表在網頁稀系統環境.
3186
	#$conf["web"]="false";
3187
	#參考資料:
3188
	#mkdir=>http://php.net/manual/en/function.mkdir.php
3189
	#chmod=>http://php.net/manual/en/function.chmod.php
3190
	#備註:
3191
	#無.
3192
	*/
3193
	public static function createFolderAfterCheck(&$conf){
226 liveuser 3194
 
3 liveuser 3195
		#初始化要回傳的結果
3196
		$result=array();
226 liveuser 3197
 
3 liveuser 3198
		#初始化警告訊息陣列
3199
		$result["warning"]=array();
226 liveuser 3200
 
3 liveuser 3201
		#記錄當前執行的函數名稱
3202
		$result["function"]=__FUNCTION__;
226 liveuser 3203
 
3 liveuser 3204
		#如果 $conf 不為陣列
3205
		if(gettype($conf)!="array"){
226 liveuser 3206
 
3 liveuser 3207
			#設置執行失敗
3208
			$result["status"]="false";
226 liveuser 3209
 
3 liveuser 3210
			#設置執行錯誤訊息
3211
			$result["error"][]="\$conf變數須為陣列形態";
3212
 
3213
			#如果傳入的參數為 null
3214
			if($conf==null){
226 liveuser 3215
 
3 liveuser 3216
				#設置執行錯誤訊息
3217
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 3218
 
3 liveuser 3219
				}#if end
3220
 
3221
			#回傳結果
3222
			return $result;
226 liveuser 3223
 
3 liveuser 3224
			}#if end
226 liveuser 3225
 
3 liveuser 3226
		#取得參數
3227
		$result["argu"]=$conf;
226 liveuser 3228
 
3 liveuser 3229
		#檢查參數
3230
		#函式說明:
3231
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3232
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3233
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3234
		#$result["function"],當前執行的函式名稱.
3235
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3236
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3237
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3238
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
3239
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3240
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3241
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3242
		#必填寫的參數:
3243
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3244
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3245
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3246
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","dirPositionAndName");
226 liveuser 3247
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 3248
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
3249
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3250
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3251
		#可以省略的參數:
3252
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
3253
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3254
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3255
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dirPermission","web");
226 liveuser 3256
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 3257
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
3258
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3259
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("0770","false");
3260
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3261
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
3262
		#參考資料來源:
3263
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3264
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3265
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 3266
 
3 liveuser 3267
		#如果 $checkArguments["status"] 等於 "false"
3268
		if($checkArguments["status"]==="false"){
226 liveuser 3269
 
3 liveuser 3270
			#設置 $result["status"] 為 "false"
3271
			$result["status"]="false";
226 liveuser 3272
 
3 liveuser 3273
			#設置 $result["error"]
3274
			$result["error"]=$checkArguments;
226 liveuser 3275
 
3 liveuser 3276
			#回傳結果
3277
			return $result;
226 liveuser 3278
 
3 liveuser 3279
			}#if end
226 liveuser 3280
 
3 liveuser 3281
		#如果 $checkArguments["passed"] 等於 "false"
3282
		if($checkArguments["passed"]==="false"){
226 liveuser 3283
 
3 liveuser 3284
			#設置 $result["status"] 為 "false"
3285
			$result["status"]="false";
226 liveuser 3286
 
3 liveuser 3287
			#設置 $result["error"]
3288
			$result["error"]=$checkArguments;
226 liveuser 3289
 
3 liveuser 3290
			#回傳結果
3291
			return $result;
226 liveuser 3292
 
3293
			}#if end
3294
 
3 liveuser 3295
		#函式說明:
3296
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
3297
		#回傳結果:
3298
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
3299
		#$result["error"],錯誤訊息陣列.
226 liveuser 3300
		#$result["function"],函數名稱.
3 liveuser 3301
		#$result["argu"],使用的參數.
3302
		#$result["content"],網址,若是在命令列執行,則為"null".
3303
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
3304
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
3305
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
3306
		#必填參數:
3307
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
3308
		$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["dirPositionAndName"];
3309
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
3310
		$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
3311
		#可省略參數:
3312
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
3313
		$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
3314
		#備註:
3315
		#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
3316
		$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
3317
		unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 3318
 
3 liveuser 3319
		#如果 $getInternetAddressV2["status"] 等於 "false"
3320
		if($getInternetAddressV2["status"]==="false"){
226 liveuser 3321
 
3 liveuser 3322
			#設置 $result["status"] 為 "false"
3323
			$result["status"]="false";
226 liveuser 3324
 
3 liveuser 3325
			#設置 $result["error"]
3326
			$result["error"]=$getInternetAddressV2;
226 liveuser 3327
 
3 liveuser 3328
			#回傳結果
3329
			return $result;
226 liveuser 3330
 
3 liveuser 3331
			}#if end
226 liveuser 3332
 
3 liveuser 3333
		#取得絕對位置
3334
		$conf["dirPositionAndName"]=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 3335
 
3 liveuser 3336
		#用「/」分割要建立的路徑
3337
		#函式說明:
3338
		#將固定格式的字串分開,並回傳分開的結果。
3339
		#回傳結果:
3340
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3341
		#$result["error"],錯誤訊息陣列
3342
		#$result["function"],當前執行的函數名稱.
3343
		#$result["oriStr"],要分割的原始字串內容
3344
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
3345
		#$result["dataCounts"],爲總共分成幾段
3346
		#必填參數:
3347
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["dirPositionAndName"];
3348
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
3349
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 3350
		unset($conf["stringProcess::spiltString"]);
3351
 
3 liveuser 3352
		#如果分割失敗
3353
		if($spiltString["status"]=="false"){
226 liveuser 3354
 
3 liveuser 3355
			#設置 $result["status"] 為 "false"
3356
			$result["status"]="false";
226 liveuser 3357
 
3 liveuser 3358
			#設置 $result["error"]
3359
			$result["error"]=$spiltString;
226 liveuser 3360
 
3 liveuser 3361
			#回傳結果
3362
			return $result;
226 liveuser 3363
 
3 liveuser 3364
			}#if end
226 liveuser 3365
 
3 liveuser 3366
		$checkedPath="";
226 liveuser 3367
 
3 liveuser 3368
		#依據切割成的路徑片段數目
3369
		for($i=0;$i<$spiltString["dataCounts"];$i++){
226 liveuser 3370
 
3 liveuser 3371
			$checkedPath=$checkedPath."/".$spiltString["dataArray"][$i];
226 liveuser 3372
 
3 liveuser 3373
			#檢查路徑是否存在
3374
			#函式說明:
3375
			#檢查多個檔案與資料夾是否存在.
3376
			#回傳的結果:
3377
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
3378
			#$result["error"],錯誤訊息陣列.
3379
			#$resutl["function"],當前執行的涵式名稱.
3380
			#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
3381
			#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
3382
			#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
3383
			#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
3384
			#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
3385
			#必填參數:
3386
			#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
3387
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($checkedPath);
3388
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3389
			$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
3390
			#可省略參數
3391
			#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
3392
			#$conf["disableWebSearch"]="false";
3393
			#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
3394
			#$conf["userDir"]="true";
3395
			#參考資料來源:
3396
			#http://php.net/manual/en/function.file-exists.php
3397
			#http://php.net/manual/en/control-structures.foreach.php
3398
			#備註:
3399
			#函數file_exists檢查的路徑為檔案系統的路徑
3400
			$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 3401
 
3 liveuser 3402
			#如果檢查資料夾路徑失敗
3403
			if($checkMultiFileExist["status"]=="false"){
226 liveuser 3404
 
3 liveuser 3405
				#設置 $result["status"] 為 "false"
3406
				$result["status"]="false";
226 liveuser 3407
 
3 liveuser 3408
				#設置 $result["error"]
3409
				$result["error"]=$spiltString;
226 liveuser 3410
 
3 liveuser 3411
				#回傳結果
3412
				return $result;
226 liveuser 3413
 
3 liveuser 3414
				}#if end
226 liveuser 3415
 
3 liveuser 3416
			#如果目錄不存在
3417
			if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 3418
 
3 liveuser 3419
				#如果有這個名稱的東西存在
3420
				if(file_exists($checkedPath)){
226 liveuser 3421
 
3 liveuser 3422
					#如果目錄存在
3423
					if(is_dir($checkedPath)){
226 liveuser 3424
 
3 liveuser 3425
						#目錄已經存在換下一層
3426
						continue;
226 liveuser 3427
 
3 liveuser 3428
						}#if end
226 liveuser 3429
 
3 liveuser 3430
					}#if end
226 liveuser 3431
 
3 liveuser 3432
				#建立目錄
3433
				$mkdir=@mkdir($checkedPath,0770);
226 liveuser 3434
 
3 liveuser 3435
				#如果建立目錄失敗
3436
				#參考資料:
3437
				#http://php.net/manual/en/function.mkdir.php
3438
				if($mkdir===false){
226 liveuser 3439
 
3 liveuser 3440
					#設置 $result["status"] 為 "false"
3441
					$result["status"]="false";
226 liveuser 3442
 
3 liveuser 3443
					#設置 $result["error"]
3444
					$result["error"][]="建立目錄「".$checkedPath."」失敗";
226 liveuser 3445
 
3 liveuser 3446
					#回傳結果
3447
					return $result;
226 liveuser 3448
 
3 liveuser 3449
					}#if end
226 liveuser 3450
 
3 liveuser 3451
				#更改目錄的權限為 0770
3452
				chmod($checkedPath,0770);
226 liveuser 3453
 
3 liveuser 3454
				}#if end
226 liveuser 3455
 
3 liveuser 3456
			}#for end
226 liveuser 3457
 
3 liveuser 3458
		#取得建立好的目錄
226 liveuser 3459
		$result["content"]=$checkedPath;
3460
 
3 liveuser 3461
		#執行到這邊代表執行成功
3462
		$result["status"]="true";
226 liveuser 3463
 
3 liveuser 3464
		#回傳結果
3465
		return $result;
226 liveuser 3466
 
3 liveuser 3467
		}#function createFolderAfterCheck end
3468
 
3469
	/*
3470
	#函式說明:
3471
	#移除檔案
3472
	#回傳結果:
3473
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
3474
	#$result["error"],錯誤訊息陣列.
3475
	#$result["warning"],警告訊息陣列.
3476
	#$result["function"],當前執行的函數名稱.
3477
	#$result["argu"],當前函式使用的參數.
3478
	#必填參數:
3479
	#$conf["fileAddress"],字串,要移除檔案的位置.
3480
	$conf["fileAddress"]="";
3481
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
3482
	$conf["fileArgu"]=__FILE__;
3483
	#可省略參數:
3484
	#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
3485
	#$conf["commentsArray"]=array("");
3486
	#$conf["allowDelSymlink"],字串,預設為"false",不移除軟連結;"true"代表要移除軟連結.
3487
	#$conf["allowDelSymlink"]="true";
3488
	#$conf["allowDelFolder"],字串,預設為"false",不移除目錄;"true"代表要移除目錄.
3489
	#$conf["allowDelFolder"]="true";
3490
	#參考資料:
3491
	#無.
3492
	#備註:
3493
	#無.
220 liveuser 3494
	*/
3 liveuser 3495
	public static function delFile(&$conf){
3496
 
3497
		#初始化要回傳的結果
3498
		$result=array();
226 liveuser 3499
 
3 liveuser 3500
		#設置當其函數名稱
3501
		$result["function"]=__FUNCTION__;
226 liveuser 3502
 
3 liveuser 3503
		#如果 $conf 不為陣列
3504
		if(gettype($conf)!="array"){
226 liveuser 3505
 
3 liveuser 3506
			#設置執行失敗
3507
			$result["status"]="false";
226 liveuser 3508
 
3 liveuser 3509
			#設置執行錯誤訊息
3510
			$result["error"][]="\$conf變數須為陣列形態";
3511
 
3512
			#如果傳入的參數為 null
3513
			if($conf==null){
226 liveuser 3514
 
3 liveuser 3515
				#設置執行錯誤訊息
3516
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 3517
 
3 liveuser 3518
				}#if end
3519
 
3520
			#回傳結果
3521
			return $result;
226 liveuser 3522
 
3 liveuser 3523
			}#if end
226 liveuser 3524
 
3 liveuser 3525
		#取得參數
3526
		$result["argu"]=$conf;
226 liveuser 3527
 
3 liveuser 3528
		#檢查參數
3529
		#函式說明:
3530
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3531
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3532
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3533
		#$result["function"],當前執行的函式名稱.
3534
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3535
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3536
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3537
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
3538
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3539
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3540
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3541
		#必填寫的參數:
3542
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3543
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3544
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3545
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","fileAddress");
226 liveuser 3546
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 3547
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
3548
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3549
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3550
		#可以省略的參數:
3551
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
3552
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3553
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3554
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray","allowDelSymlink","allowDelFolder");
226 liveuser 3555
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 3556
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string");
3557
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3558
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false","false");
3559
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3560
		#$conf["arrayCountEqualCheck"][]=array();
3561
		#參考資料來源:
3562
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3563
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3564
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 3565
 
3 liveuser 3566
		#如果檢查失敗
3567
		if($checkResult["status"]=="false"){
226 liveuser 3568
 
3 liveuser 3569
			#設置錯誤識別
3570
			$result["status"]="false";
226 liveuser 3571
 
3 liveuser 3572
			#設置錯誤訊息
3573
			$result["error"]=$checkResult;
226 liveuser 3574
 
3 liveuser 3575
			#回傳結果
3576
			return $result;
226 liveuser 3577
 
3 liveuser 3578
			}#if end
226 liveuser 3579
 
3 liveuser 3580
		#如果檢查不通過
3581
		if($checkResult["passed"]=="false"){
226 liveuser 3582
 
3 liveuser 3583
			#設置錯誤識別
3584
			$result["status"]="false";
226 liveuser 3585
 
3 liveuser 3586
			#設置錯誤訊息
3587
			$result["error"]=$checkResult;
226 liveuser 3588
 
3 liveuser 3589
			#回傳結果
3590
			return $result;
226 liveuser 3591
 
3 liveuser 3592
			}#if end
3593
 
3594
		#如果 $conf["commentsArray"] 有設定
3595
		if(isset($conf["commentsArray"])){
226 liveuser 3596
 
3 liveuser 3597
			#印出提示文字
3598
			#函式說明:
3599
			#印出多行文字,結尾自動換行.
3600
			#回傳的結果:
3601
			#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
3602
			#$result["function"],當前執行的函數名稱.
3603
			#$result["error"],錯誤訊息陣列.
3604
			#必填參數:
3605
			#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
3606
			$conf["cmd::echoMultiLine"]["outputStringArray"]=$conf["commentsArray"];
3607
			$echoMultiLine=cmd::echoMultiLine($conf["cmd::echoMultiLine"]);
3608
			unset($conf["cmd::echoMultiLine"]);
226 liveuser 3609
 
3 liveuser 3610
			#如果印出提示文字失敗
3611
			if($echoMultiLine["status"]=="false"){
226 liveuser 3612
 
3 liveuser 3613
				#設置執行失敗
3614
				$result["status"]="false";
226 liveuser 3615
 
3 liveuser 3616
				#設置執行錯誤訊息
3617
				$result["error"]=$echoMultiLine;
226 liveuser 3618
 
3 liveuser 3619
				#回傳結果
3620
				return $result;
226 liveuser 3621
 
3 liveuser 3622
				}#if end
226 liveuser 3623
 
3 liveuser 3624
			}#if end
3625
 
3626
		#檢查要移除的檔案是否存在
3627
		#函式說明:
3628
		#檢查多個檔案與資料夾是否存在.
3629
		#回傳的結果:
3630
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
3631
		#$result["error"],錯誤訊息陣列.
3632
		#$resutl["function"],當前執行的涵式名稱.
3633
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
3634
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
3635
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
3636
		#必填參數:
3637
		$conf["fileAccess.checkMultiFileExist"]["fileArray"]=array($conf["fileAddress"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
3638
		#$conf["fileAccess.checkMultiFileExist"]["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3639
		$conf["fileAccess.checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
3640
		#可省略參數:
3641
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
3642
		#$conf["disableWebSearch"]="false";
3643
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
3644
		#$conf["userDir"]="true";
3645
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
3646
		$conf["fileAccess.checkMultiFileExist"]["web"]="false";
3647
		#參考資料來源:
3648
		#http://php.net/manual/en/function.file-exists.php
3649
		#http://php.net/manual/en/control-structures.foreach.php
3650
		$checkResult=fileAccess::checkMultiFileExist($conf["fileAccess.checkMultiFileExist"]);
3651
		unset($conf["fileAccess.checkMultiFileExist"]);
3652
 
3653
		#var_dump($checkResult);
3654
 
3655
		#如果檢查檔案是否存在失敗
3656
		if($checkResult["status"]==="false"){
226 liveuser 3657
 
3 liveuser 3658
			#設置執行失敗
3659
			$result["status"]="false";
3660
 
3661
			#回傳錯誤訊息
3662
			$result["error"]=$checkResult;
3663
 
3664
			#回傳結果
3665
			return $result;
226 liveuser 3666
 
3 liveuser 3667
			}#if end
3668
 
3669
		#如果目標檔案不存在
3670
		if($checkResult["varExist"][0]==="false"){
226 liveuser 3671
 
3 liveuser 3672
			#設置錯誤識別
3673
			$result["status"]="true";
3674
 
3675
			#回傳錯誤訊息
3676
			$result["warning"][]="要移除的檔案不存在";
3677
 
3678
			#回傳結果
3679
			return $result;
226 liveuser 3680
 
3 liveuser 3681
			}#if end
3682
 
3683
		#如果要移除的目標是檔案
3684
		if(is_file($conf["fileAddress"])){
226 liveuser 3685
 
3 liveuser 3686
			#移除檔案,並回傳移除的結果
3687
			$eraseResult=(@unlink($conf["fileAddress"]));
3688
 
3689
			#如果 $eraseResult 等於 false
3690
			if($eraseResult===false){
226 liveuser 3691
 
3 liveuser 3692
				#設置錯誤識別
3693
				$result["status"]="false";
3694
 
3695
				#回傳錯誤訊息
3696
				$result["error"][]="檔案移除失敗";
3697
 
3698
				#回傳結果
3699
				return $result;
226 liveuser 3700
 
3 liveuser 3701
				}#if end
226 liveuser 3702
 
3 liveuser 3703
			}#if end
3704
 
3705
		#反之要移除的目標是目錄
3706
		else if(is_dir($conf["fileAddress"])){
226 liveuser 3707
 
3 liveuser 3708
			#如果允許移除目錄
3709
			if($conf["allowDelFolder"]==="true"){
226 liveuser 3710
 
3 liveuser 3711
				#移除目錄跟底下的內容
3712
				w函式說明:
3713
				#呼叫shell執行系統命令,並取得回傳的內容.
3714
				#回傳結果:
3715
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3716
				#$result["error"],錯誤訊息陣列.
3717
				#$result["function"],當前執行的函數名稱.
3718
				#$result["argu"],使用的參數.
3719
				#$result["cmd"],執行的指令內容.
3720
				#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
3721
				#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
3722
				#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
3723
				#$result["running"],是否還在執行.
3724
				#$result["pid"],pid.
3725
				#$result["statusCode"],執行結束後的代碼.
3726
				#必填參數:
3727
				#$conf["command"],字串,要執行的指令.
3728
				$conf["external::callShell"]["command"]="rm";
3729
				#$conf["fileArgu"],字串,變數__FILE__的內容.
3730
				$conf["external::callShell"]["fileArgu"]=__FILE__;
3731
				#可省略參數:
3732
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3733
				$conf["external::callShell"]["argu"]=array("-rf",$conf["fileAddress"]);
3734
				#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
3735
				#$conf["arguIsAddr"]=array();
3736
				#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
3737
				#$conf["plainArgu"]=array();
3738
				#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
3739
				#$conf["useApostrophe"]=array();
3740
				#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
3741
				#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
3742
				#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
3743
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
3744
				#$conf["enablePrintDescription"]="true";
3745
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
3746
				#$conf["printDescription"]="";
3747
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
3748
				$conf["external::callShell"]["escapeshellarg"]="true";
3749
				#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
3750
				#$conf["thereIsShellVar"]=array();
3751
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
3752
				#$conf["username"]="";
3753
				#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
3754
				#$conf["password"]="";
3755
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
3756
				#$conf["useScript"]="";
3757
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
3758
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
3759
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
3760
				#$conf["inBackGround"]="";
3761
				#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
3762
				#$conf["getErr"]="false";
3763
				#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
3764
				#$conf["doNotRun"]="false";
3765
				#參考資料:
3766
				#exec=>http://php.net/manual/en/function.exec.php
3767
				#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
3768
				#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
3769
				#備註:
3770
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
3771
				#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
3772
				$callShell=external::callShell($conf["external::callShell"]);
3773
				unset($conf["external::callShell"]);
226 liveuser 3774
 
3 liveuser 3775
				#如果執行失敗
3776
				if($callShell["status"]==="false"){
226 liveuser 3777
 
3 liveuser 3778
					#設置錯誤識別
3779
					$result["status"]="false";
3780
 
3781
					#回傳錯誤訊息
3782
					$result["error"]=$callShell;
3783
 
3784
					#回傳結果
3785
					return $result;
226 liveuser 3786
 
3 liveuser 3787
					}#if end
226 liveuser 3788
 
3789
				}#if end
3790
 
3 liveuser 3791
			#反之不允許
3792
			else{
226 liveuser 3793
 
3 liveuser 3794
				#設置錯誤識別
3795
				$result["status"]="false";
3796
 
3797
				#回傳錯誤訊息
3798
				$result["error"][]="不允許移除目錄";
226 liveuser 3799
 
3 liveuser 3800
				#回傳結果
3801
				return $result;
226 liveuser 3802
 
3 liveuser 3803
				}#else end
226 liveuser 3804
 
3 liveuser 3805
			}#if end
226 liveuser 3806
 
3 liveuser 3807
		#反之
3808
		else{
226 liveuser 3809
 
3 liveuser 3810
			#可能為 軟連結
226 liveuser 3811
 
3 liveuser 3812
			#如果允許移除
3813
			if($conf["allowDelSymlink"]==="true"){
226 liveuser 3814
 
3 liveuser 3815
				#移除檔案,並回傳移除的結果
3816
				$eraseResult=(@unlink($conf["fileAddress"]));
3817
 
3818
				#如果 $eraseResult 等於 false
3819
				if($eraseResult===false){
226 liveuser 3820
 
3 liveuser 3821
					#設置錯誤識別
3822
					$result["status"]="false";
3823
 
3824
					#回傳錯誤訊息
3825
					$result["error"][]="檔案移除失敗";
3826
 
3827
					#回傳結果
3828
					return $result;
226 liveuser 3829
 
3 liveuser 3830
					}#if end
226 liveuser 3831
 
3 liveuser 3832
				}#if end
226 liveuser 3833
 
3 liveuser 3834
			#反之
3835
			else{
226 liveuser 3836
 
3 liveuser 3837
				#設置錯誤識別
3838
				$result["status"]="false";
226 liveuser 3839
 
3 liveuser 3840
				#設置錯誤訊息
3841
				$result["error"][]="不允許移除 檔案、目錄 以外類型的目標";
3842
 
3843
				#回傳結果
3844
				return $result;
226 liveuser 3845
 
3 liveuser 3846
				}#else end
226 liveuser 3847
 
3 liveuser 3848
			}#else end
226 liveuser 3849
 
3 liveuser 3850
		#執行到這邊代表執行正常.
3851
		$result["status"]="true";
226 liveuser 3852
 
3 liveuser 3853
		#回傳結果
3854
		return $result;
3855
 
3856
		}#function delFile end
226 liveuser 3857
 
3 liveuser 3858
	/*
3859
	#函式說明:
3860
	#移除多個檔案
3861
	#回傳結果:
3862
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
3863
	#$result["error"],錯誤訊息陣列
3864
	#$result["function"],當前執行的函數名稱.
3865
	#$result["argu"],使用的參數.
3866
	#$result["content"],陣列,移除各個檔案的結果.
3867
	#必填參數:
3868
	#$conf["fileAddress"],字串陣列,要移除檔案的位置.
3869
	$conf["fileAddress"]=array("");
3870
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
3871
	$conf["fileArgu"]=__FILE__;
3872
	#可省略參數:
3873
	#無.
3874
	#參考資料:
3875
	#無.
3876
	#備註:
3877
	#無.
220 liveuser 3878
	*/
3 liveuser 3879
	public static function delMultiFile(&$conf){
226 liveuser 3880
 
3 liveuser 3881
		#初始化要回傳的結果
3882
		$result=array();
226 liveuser 3883
 
3 liveuser 3884
		#設置當其函數名稱
3885
		$result["function"]=__FUNCTION__;
226 liveuser 3886
 
3 liveuser 3887
		#如果 $conf 不為陣列
3888
		if(gettype($conf)!="array"){
226 liveuser 3889
 
3 liveuser 3890
			#設置執行失敗
3891
			$result["status"]="false";
226 liveuser 3892
 
3 liveuser 3893
			#設置執行錯誤訊息
3894
			$result["error"][]="\$conf變數須為陣列形態";
3895
 
3896
			#如果傳入的參數為 null
3897
			if($conf==null){
226 liveuser 3898
 
3 liveuser 3899
				#設置執行錯誤訊息
3900
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 3901
 
3 liveuser 3902
				}#if end
3903
 
3904
			#回傳結果
3905
			return $result;
226 liveuser 3906
 
3 liveuser 3907
			}#if end
226 liveuser 3908
 
3 liveuser 3909
		#取得使用的參數.
3910
		$result["argu"]=$conf;
226 liveuser 3911
 
3 liveuser 3912
		#檢查參數
3913
		#函式說明:
3914
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3915
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3916
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3917
		#$result["function"],當前執行的函式名稱.
3918
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3919
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3920
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3921
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
3922
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3923
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3924
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3925
		#必填寫的參數:
3926
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3927
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3928
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3929
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","fileAddress");
226 liveuser 3930
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 3931
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array");
3932
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3933
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3934
		#可以省略的參數:
3935
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
3936
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3937
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3938
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray");
226 liveuser 3939
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 3940
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
3941
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3942
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
3943
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3944
		#$conf["arrayCountEqualCheck"][]=array();
3945
		#參考資料來源:
3946
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3947
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3948
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 3949
 
3 liveuser 3950
		#如果檢查失敗
3951
		if($checkResult["status"]=="false"){
226 liveuser 3952
 
3 liveuser 3953
			#設置錯誤識別
3954
			$result["status"]="false";
226 liveuser 3955
 
3 liveuser 3956
			#設置錯誤訊息
3957
			$result["error"]=$checkResult;
226 liveuser 3958
 
3 liveuser 3959
			#回傳結果
3960
			return $result;
226 liveuser 3961
 
3 liveuser 3962
			}#if end
226 liveuser 3963
 
3 liveuser 3964
		#如果檢查不通過
3965
		if($checkResult["passed"]=="false"){
226 liveuser 3966
 
3 liveuser 3967
			#設置錯誤識別
3968
			$result["status"]="false";
226 liveuser 3969
 
3 liveuser 3970
			#設置錯誤訊息
3971
			$result["error"]=$checkResult;
226 liveuser 3972
 
3 liveuser 3973
			#回傳結果
3974
			return $result;
226 liveuser 3975
 
3 liveuser 3976
			}#if end
226 liveuser 3977
 
3 liveuser 3978
		#針對每個要移除的檔案
3979
		foreach($conf["fileAddress"] as $fileAddr){
226 liveuser 3980
 
3 liveuser 3981
			#函式說明:
3982
			#移除檔案
3983
			#回傳結果:
3984
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
3985
			#$result["error"],錯誤訊息陣列
3986
			#$result["warning"],警告訊息陣列
3987
			#$result["function"],當前執行的函數名稱
3988
			#必填參數:
3989
			#$conf["fileAddress"],字串,要移除檔案的位置.
3990
			$conf["fileAccess::delFile"]["fileAddress"]=$fileAddr;
3991
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
3992
			$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
3993
			#可省略參數:
3994
			#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
3995
			#$conf["commentsArray"]=array("");
3996
			#備註:
3997
			#無.
3998
			$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
3999
			unset($conf["fileAccess::delFile"]);
226 liveuser 4000
 
3 liveuser 4001
			#如果檢查失敗
4002
			if($delFile["status"]==="false"){
226 liveuser 4003
 
3 liveuser 4004
				#設置錯誤識別
4005
				$result["status"]="false";
226 liveuser 4006
 
3 liveuser 4007
				#設置錯誤訊息
4008
				$result["error"]=$delFile;
226 liveuser 4009
 
3 liveuser 4010
				#回傳結果
4011
				return $result;
226 liveuser 4012
 
3 liveuser 4013
				}#if end
226 liveuser 4014
 
3 liveuser 4015
			#取得移除檔案的結果
4016
			$result["content"][]=$delFile;
226 liveuser 4017
 
3 liveuser 4018
			}#foreach end
226 liveuser 4019
 
3 liveuser 4020
		#設置執行正常
4021
		$result["status"]="true";
226 liveuser 4022
 
3 liveuser 4023
		#回傳結果
4024
		return $result;
226 liveuser 4025
 
3 liveuser 4026
		}#function delMultiFile end
226 liveuser 4027
 
3 liveuser 4028
	/*
4029
	#函式說明:
4030
	#確保路徑存在.
4031
	#回傳結果:
4032
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4033
	#$result["error"],錯誤訊息陣列.
4034
	#$resutl["function"],當前執行的涵式名稱.
4035
	#$result["path"],建立好的路徑字串.
4036
	#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
4037
	#$result["argu"],使用的參數.
4038
	#必填參數:
4039
	#$conf["path"],要檢查的路徑
226 liveuser 4040
	$conf["path"]="";
3 liveuser 4041
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4042
	$conf["fileArgu"]=__FILE__;
4043
	#可省略參數:
4044
	#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
4045
	#$conf["haveFileName"]="false";
4046
	#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人無法使用.
4047
	#$conf["dirPermission"]="";
4048
	#$conf["web"],是否為檔案系統,"true"為網頁路徑,"false"為網頁系統,預設為"false".
4049
	#$conf["web"]="";
4050
	#參考資料:
4051
	#無.
4052
	#備註:
4053
	#無.
226 liveuser 4054
	*/
3 liveuser 4055
	public static function validatePath(&$conf){
226 liveuser 4056
 
3 liveuser 4057
		#初始化要回傳的結果
4058
		$result=array();
226 liveuser 4059
 
3 liveuser 4060
		#設置當其函數名稱
4061
		$result["function"]=__FUNCTION__;
226 liveuser 4062
 
3 liveuser 4063
		#如果 $conf 不為陣列
4064
		if(gettype($conf)!="array"){
226 liveuser 4065
 
3 liveuser 4066
			#設置執行失敗
4067
			$result["status"]="false";
226 liveuser 4068
 
3 liveuser 4069
			#設置執行錯誤訊息
4070
			$result["error"][]="\$conf變數須為陣列形態";
4071
 
4072
			#如果傳入的參數為 null
4073
			if($conf==null){
226 liveuser 4074
 
3 liveuser 4075
				#設置執行錯誤訊息
4076
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 4077
 
3 liveuser 4078
				}#if end
226 liveuser 4079
 
3 liveuser 4080
			#回傳結果
4081
			return $result;
226 liveuser 4082
 
3 liveuser 4083
			}#if end
226 liveuser 4084
 
3 liveuser 4085
		#取得使用的參數
226 liveuser 4086
		$result["argu"]=$conf;
4087
 
3 liveuser 4088
		#檢查參數
4089
		#函式說明:
4090
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4091
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4092
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4093
		#$result["function"],當前執行的函式名稱.
4094
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4095
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4096
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4097
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
4098
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
4099
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4100
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4101
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4102
		#必填寫的參數:
4103
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4104
		$conf["variableCheck::checkArgument"]["varInput"]=&$conf;
4105
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4106
		$conf["variableCheck::checkArgument"]["mustBeFilledVariableName"]=array("path","fileArgu");
4107
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
4108
		$conf["variableCheck::checkArgument"]["mustBeFilledVariableType"]=array("string","string");
4109
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4110
		$conf["variableCheck::checkArgument"]["referenceVarKey"]="variableCheck::checkArgument";
4111
		#可以省略的參數:
4112
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
4113
		$conf["variableCheck::checkArgument"]["canBeEmptyString"]="false";
4114
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
4115
		$conf["variableCheck::checkArgument"]["skipableVariableCanNotBeEmpty"]=array("haveFileName","dirPermission","web");
4116
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4117
		$conf["variableCheck::checkArgument"]["skipableVariableName"]=array("haveFileName","dirPermission","web");
226 liveuser 4118
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 4119
		$conf["variableCheck::checkArgument"]["skipableVariableType"]=array("string","string","string");
4120
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4121
		$conf["variableCheck::checkArgument"]["skipableVarDefaultValue"]=array("false","0770","false");
4122
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4123
		#$conf["arrayCountEqualCheck"][]=array();
4124
		#參考資料來源:
4125
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4126
		$checkArgument=variableCheck::checkArguments($conf["variableCheck::checkArgument"]);
4127
		unset($conf["variableCheck::checkArgument"]);
226 liveuser 4128
 
3 liveuser 4129
		#如果檢查過程出錯
4130
		if($checkArgument["status"]==="false"){
226 liveuser 4131
 
3 liveuser 4132
			#設置執行失敗
4133
			$result["status"]="false";
226 liveuser 4134
 
3 liveuser 4135
			#設置執行錯誤訊息
4136
			$result["error"]=$checkArgument;
4137
 
4138
			#回傳結果
4139
			return $result;
226 liveuser 4140
 
3 liveuser 4141
			}#if end
226 liveuser 4142
 
3 liveuser 4143
		#如果檢查不通過
4144
		if($checkArgument["passed"]==="false"){
226 liveuser 4145
 
3 liveuser 4146
			#設置執行失敗
4147
			$result["status"]="false";
226 liveuser 4148
 
3 liveuser 4149
			#設置執行錯誤訊息
4150
			$result["error"]=$checkArgument;
4151
 
4152
			#回傳結果
4153
			return $result;
226 liveuser 4154
 
3 liveuser 4155
			}#if end
226 liveuser 4156
 
3 liveuser 4157
		#函式說明:
4158
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
4159
		#回傳結果:
4160
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
4161
		#$result["error"],錯誤訊息陣列.
226 liveuser 4162
		#$result["function"],函數名稱.
3 liveuser 4163
		#$result["argu"],使用的參數.
4164
		#$result["content"],網址,若是在命令列執行,則為"null".
4165
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
4166
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
4167
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
4168
		#必填參數:
4169
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
4170
		$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["path"];
4171
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
4172
		$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
4173
		#可省略參數:
4174
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
4175
		$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
4176
		#備註:
4177
		#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
4178
		$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 4179
		unset($conf["fileAccess::getInternetAddressV2"]);
4180
 
3 liveuser 4181
		#如果檢查過程出錯
4182
		if($getInternetAddressV2["status"]=="false"){
226 liveuser 4183
 
3 liveuser 4184
			#設置執行失敗
4185
			$result["status"]="false";
226 liveuser 4186
 
3 liveuser 4187
			#設置執行錯誤訊息
4188
			$result["error"]=$getInternetAddressV2;
4189
 
4190
			#回傳結果
4191
			return $result;
226 liveuser 4192
 
4193
			}#if end
4194
 
3 liveuser 4195
		#取得轉換好的絕對路徑
4196
		$result["path"]=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 4197
 
3 liveuser 4198
		#debug
4199
		#var_dump($getInternetAddressV2);exit;
226 liveuser 4200
 
3 liveuser 4201
		#如果 路徑 含有檔案名稱
4202
		if($conf["haveFileName"]==="true"){
226 liveuser 4203
 
3 liveuser 4204
			#預設要加回去的結束字串為空字串
4205
			$endStr="";
226 liveuser 4206
 
3 liveuser 4207
			#如果開頭跟結尾都是 "'"
4208
			if( strpos($result["path"],"'")===0 && strpos($result["path"],"'")===(strlen($result["path"])-1) ){
226 liveuser 4209
 
3 liveuser 4210
				#設置要加回去的結束字串
4211
				$endStr="'";
226 liveuser 4212
 
3 liveuser 4213
				}#if end
226 liveuser 4214
 
3 liveuser 4215
			#函式說明:
4216
			#將固定格式的字串分開,並回傳分開的結果。
4217
			#回傳結果:
4218
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4219
			#$result["error"],錯誤訊息陣列
4220
			#$result["function"],當前執行的函數名稱.
4221
			#$result["argu"],使用的參數.
4222
			#$result["oriStr"],要分割的原始字串內容
4223
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4224
			#$result["dataCounts"],爲總共分成幾段
4225
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
4226
			#必填參數:
4227
			#$conf["stringIn"],字串,要處理的字串.
4228
			$conf["stringProcess::spiltString"]["stringIn"]=$result["path"];
4229
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
4230
			$conf["stringProcess::spiltString"]["spiltSymbol"]="/";
4231
			#可省略參數:
4232
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
4233
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
4234
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
4235
			unset($conf["stringProcess::spiltString"]);
226 liveuser 4236
 
3 liveuser 4237
			#如果檢查過程出錯
4238
			if($spiltString["status"]==="false"){
226 liveuser 4239
 
3 liveuser 4240
				#設置執行失敗
4241
				$result["status"]="false";
226 liveuser 4242
 
3 liveuser 4243
				#設置執行錯誤訊息
4244
				$result["error"]=$spiltString;
4245
 
4246
				#回傳結果
4247
				return $result;
226 liveuser 4248
 
3 liveuser 4249
				}#if end
226 liveuser 4250
 
3 liveuser 4251
			#初始化儲存 path
4252
			$path="";
226 liveuser 4253
 
3 liveuser 4254
			#針對n-1段的內容
4255
			for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 4256
 
3 liveuser 4257
				#串接路徑
4258
				$path=$path."/".$spiltString["dataArray"][$i];
226 liveuser 4259
 
3 liveuser 4260
				}#for end
226 liveuser 4261
 
3 liveuser 4262
			#如果路徑為空
4263
			if($path===""){
226 liveuser 4264
 
3 liveuser 4265
				#則與設為根目錄
4266
				$path="/";
226 liveuser 4267
 
3 liveuser 4268
				}#if end
226 liveuser 4269
 
3 liveuser 4270
			#設置檔案名稱
4271
			$result["fileName"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
226 liveuser 4272
 
3 liveuser 4273
			#取得不含檔案名稱的路徑
4274
			$conf["path"]=$path.$endStr;
226 liveuser 4275
 
3 liveuser 4276
			#取得不含檔案名稱的路徑
4277
			$result["path"]=$path.$endStr;
226 liveuser 4278
 
3 liveuser 4279
			}#if end
226 liveuser 4280
 
3 liveuser 4281
		#函式說明:
4282
		#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
4283
		#回傳結果:
4284
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
4285
		#$result["error"],錯誤訊息陣列
4286
		#必填參數:
4287
		$conf["fileAccess::createFolderAfterCheck"]["dirPositionAndName"]=$conf["path"];#新建的位置與名稱
4288
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4289
		$conf["fileAccess::createFolderAfterCheck"]["fileArgu"]=$conf["fileArgu"];
4290
		#可省略參數:
4291
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
4292
		$conf["fileAccess::createFolderAfterCheck"]["dirPermission"]=$conf["dirPermission"];
4293
		$conf["fileAccess::createFolderAfterCheck"]["web"]="false";
4294
		#參考資料:
4295
		#mkdir=>http://php.net/manual/en/function.mkdir.php
4296
		#chmod=>http://php.net/manual/en/function.chmod.php
4297
		$createFolderAfterCheck=fileAccess::createFolderAfterCheck($conf["fileAccess::createFolderAfterCheck"]);
4298
		unset($conf["fileAccess::createFolderAfterCheck"]);
226 liveuser 4299
 
3 liveuser 4300
		#如果建立路徑過程出錯
4301
		if($createFolderAfterCheck["status"]==="false"){
226 liveuser 4302
 
3 liveuser 4303
			#設置執行失敗
4304
			$result["status"]="false";
226 liveuser 4305
 
3 liveuser 4306
			#設置執行錯誤訊息
4307
			$result["error"]=$createFolderAfterCheck;
4308
 
4309
			#回傳結果
4310
			return $result;
226 liveuser 4311
 
3 liveuser 4312
			}#if end
226 liveuser 4313
 
3 liveuser 4314
		#如果有警告訊息
4315
		if(count($createFolderAfterCheck["warning"])>0){
226 liveuser 4316
 
3 liveuser 4317
			#取得警告訊息
4318
			$result["error"]=$createFolderAfterCheck["warning"];
226 liveuser 4319
 
3 liveuser 4320
			#設置執行失敗
4321
			$result["status"]="false";
226 liveuser 4322
 
3 liveuser 4323
			#回傳結果
4324
			return $result;
226 liveuser 4325
 
3 liveuser 4326
			}#if end
226 liveuser 4327
 
3 liveuser 4328
		#執行到這邊代表成功
4329
		$result["status"]="true";
226 liveuser 4330
 
3 liveuser 4331
		#回傳結果
4332
		return $result;
226 liveuser 4333
 
3 liveuser 4334
		}#function validatePath end
226 liveuser 4335
 
3 liveuser 4336
	/*
4337
	#函式說明:
4338
	#解析路徑的每個層級.
4339
	#回傳結果:
4340
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4341
	#$result["error"],錯誤訊息陣列.
4342
	#$resutl["function"],當前執行的涵式名稱.
4343
	#$result["argu"],使用的參數.
4344
	#$result["content"],解析出來的路徑階層.
4345
	#必填參數:
4346
	#$conf["path"],要檢查的路徑
4347
	$conf["path"]="";
4348
	#可省略參數:
4349
	#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
4350
	#$conf["haveFileName"]="false";
4351
	#參考資料:
4352
	#無.
4353
	#備註:
4354
	#無.
4355
	*/
4356
	public static function parsePath(&$conf){
226 liveuser 4357
 
3 liveuser 4358
		#初始化要回傳的內容
4359
		$result=array();
4360
 
4361
		#取得當前執行的函數名稱
4362
		$result["function"]=__FUNCTION__;
4363
 
4364
		#如果 $conf 不為陣列
4365
		if(gettype($conf)!="array"){
226 liveuser 4366
 
3 liveuser 4367
			#設置執行失敗
4368
			$result["status"]="false";
226 liveuser 4369
 
3 liveuser 4370
			#設置執行錯誤訊息
4371
			$result["error"][]="\$conf變數須為陣列形態";
4372
 
4373
			#如果傳入的參數為 null
4374
			if($conf==null){
226 liveuser 4375
 
3 liveuser 4376
				#設置執行錯誤訊息
4377
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 4378
 
3 liveuser 4379
				}#if end
4380
 
4381
			#回傳結果
4382
			return $result;
226 liveuser 4383
 
3 liveuser 4384
			}#if end
4385
 
4386
		#記錄使用的參數
4387
		$result["argu"]=$conf;
4388
 
4389
		#檢查參數
4390
		#函式說明:
4391
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4392
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4393
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4394
		#$result["function"],當前執行的函式名稱.
4395
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4396
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4397
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4398
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
4399
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4400
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4401
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4402
		#必填寫的參數:
4403
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4404
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
4405
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4406
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path");
226 liveuser 4407
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 4408
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
4409
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4410
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
4411
		#可以省略的參數:
4412
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
4413
		#$conf["canBeEmptyString"]="false";
4414
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4415
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("haveFileName");
226 liveuser 4416
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 4417
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
4418
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4419
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
4420
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4421
		#$conf["arrayCountEqualCheck"][]=array();
4422
		#參考資料來源:
4423
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4424
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4425
		unset($conf["variableCheck::checkArguments"]);
4426
 
4427
		#如果檢查有誤
4428
		if($checkResult["status"]=="false"){
226 liveuser 4429
 
3 liveuser 4430
			#設置錯誤識別
4431
			$result["status"]="false";
226 liveuser 4432
 
3 liveuser 4433
			#設置錯誤訊息
4434
			$result["error"]=$checkResult;
226 liveuser 4435
 
3 liveuser 4436
			#回傳結果
4437
			return $result;
226 liveuser 4438
 
3 liveuser 4439
			}#if end
226 liveuser 4440
 
3 liveuser 4441
		#如果檢查不通過
4442
		if($checkResult["passed"]=="false"){
226 liveuser 4443
 
3 liveuser 4444
			#設置錯誤識別
4445
			$result["status"]="false";
226 liveuser 4446
 
3 liveuser 4447
			#設置錯誤訊息
4448
			$result["error"]=$checkResult;
226 liveuser 4449
 
3 liveuser 4450
			#回傳結果
4451
			return $result;
226 liveuser 4452
 
3 liveuser 4453
			}#if end
226 liveuser 4454
 
3 liveuser 4455
		#函式說明:
4456
		#將固定格式的字串分開,並回傳分開的結果.
4457
		#回傳結果:
4458
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4459
		#$result["error"],錯誤訊息陣列
4460
		#$result["function"],當前執行的函數名稱.
4461
		#$result["argu"],使用的參數.
4462
		#$result["oriStr"],要分割的原始字串內容
4463
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4464
		#$result["dataCounts"],爲總共分成幾段
4465
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
4466
		#必填參數:
4467
		#$conf["stringIn"],字串,要處理的字串.
4468
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["path"];
4469
		#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
4470
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";
4471
		#可省略參數:
4472
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
4473
		#$conf["allowEmptyStr"]="false";
4474
		#參考資料:
4475
		#無.
4476
		#備註:
4477
		#無.
4478
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
4479
		unset($conf["stringProcess::spiltString"]);
226 liveuser 4480
 
3 liveuser 4481
		#如果檢查有誤
4482
		if($spiltString["status"]==="false"){
226 liveuser 4483
 
3 liveuser 4484
			#設置錯誤識別
4485
			$result["status"]="false";
226 liveuser 4486
 
3 liveuser 4487
			#設置錯誤訊息
4488
			$result["error"]=$spiltString;
226 liveuser 4489
 
3 liveuser 4490
			#回傳結果
4491
			return $result;
226 liveuser 4492
 
3 liveuser 4493
			}#if end
226 liveuser 4494
 
3 liveuser 4495
		#確認是否為絕對路徑
4496
		#函式說明:
4497
		#取得符合特定字首與字尾的字串
4498
		#回傳結果:
4499
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
4500
		#$result["function"],當前執行的函數名稱.
4501
		#$result["error"],錯誤訊息陣列.
4502
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
4503
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
4504
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
4505
		#$result["argu"],使用的參數.
4506
		#必填參數:
4507
		#$conf["checkString"],字串,要檢查的字串.
4508
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["path"];
4509
		#可省略參數:
4510
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
4511
		$conf["search::getMeetConditionsString"]["frontWord"]="/";
4512
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
4513
		#$conf["search::getMeetConditionsString"]["tailWord"]="";
4514
		#參考資料:
4515
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
4516
		#備註:
4517
		#無.
4518
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
4519
		unset($conf["search::getMeetConditionsString"]);
226 liveuser 4520
 
3 liveuser 4521
		#如果檢查有誤
4522
		if($getMeetConditionsString["status"]==="false"){
226 liveuser 4523
 
3 liveuser 4524
			#設置錯誤識別
4525
			$result["status"]="false";
226 liveuser 4526
 
3 liveuser 4527
			#設置錯誤訊息
4528
			$result["error"]=$getMeetConditionsString;
226 liveuser 4529
 
3 liveuser 4530
			#回傳結果
4531
			return $result;
226 liveuser 4532
 
3 liveuser 4533
			}#if end
226 liveuser 4534
 
3 liveuser 4535
		#如果是絕對路徑
4536
		if($getMeetConditionsString["founded"]==="true"){
226 liveuser 4537
 
3 liveuser 4538
			#初始化路徑為 "/"
4539
			$result["content"][]="/";
226 liveuser 4540
 
3 liveuser 4541
			}#if end
226 liveuser 4542
 
3 liveuser 4543
		#針對每個切割出來的路徑階層
4544
		foreach($spiltString["dataArray"] as $index => $dir){
226 liveuser 4545
 
3 liveuser 4546
			#如果路徑結尾含有檔案名稱
4547
			if($conf["haveFileName"]==="true"){
226 liveuser 4548
 
3 liveuser 4549
				#如果是最後一段
4550
				if($index===$spiltString["dataCounts"]-1){
226 liveuser 4551
 
3 liveuser 4552
					#忽略
4553
					continue;
226 liveuser 4554
 
3 liveuser 4555
					}#if end
226 liveuser 4556
 
3 liveuser 4557
				}#if end
226 liveuser 4558
 
3 liveuser 4559
			#後面加上 資料夾名稱 跟 "/"
4560
			$newPath=$dir."/";
226 liveuser 4561
 
3 liveuser 4562
			#如果有 content
4563
			if(isset($result["content"])){
226 liveuser 4564
 
3 liveuser 4565
				#如果有上個資料夾
4566
				if(isset($result["content"][count($result["content"])-1])){
226 liveuser 4567
 
3 liveuser 4568
					#後面加上 上個資料夾名稱 加上資料夾名稱 跟 "/"
4569
					$newPath=$result["content"][count($result["content"])-1].$dir."/";
226 liveuser 4570
 
3 liveuser 4571
					}#if end
226 liveuser 4572
 
3 liveuser 4573
				}#if end
226 liveuser 4574
 
3 liveuser 4575
			#並新增置結果
4576
			$result["content"][]=$newPath;
226 liveuser 4577
 
3 liveuser 4578
			}#foreach end
226 liveuser 4579
 
3 liveuser 4580
		#var_dump($result["content"]);
226 liveuser 4581
 
3 liveuser 4582
		#設置執行正常
4583
		$result["status"]="true";
226 liveuser 4584
 
3 liveuser 4585
		#回傳結果
4586
		return $result;
226 liveuser 4587
 
3 liveuser 4588
		}#function parsePath end
226 liveuser 4589
 
3 liveuser 4590
	/*
4591
	#函式說明:
4592
	#檢查路徑是否存在.
4593
	#回傳結果:
4594
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4595
	#$result["error"],錯誤訊息陣列.
4596
	#$resutl["function"],當前執行的涵式名稱.
4597
	#$result["argu"],使用的參數.
4598
	#$result["found"],路徑是否存在,"true"代表存在,"false"代表不存在.
4599
	#$result["content"],每個階層路徑的檢查結果,每個元素有檢查的路徑"path"跟是否有存在或可存取的識別"found".
4600
	#必填參數:
4601
	#$conf["path"],要檢查的路徑
4602
	$conf["path"]="";
4603
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4604
	$conf["fileArgu"]=__FILE__;
4605
	#可省略參數:
4606
	#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
4607
	#$conf["haveFileName"]="false";
4608
	#參考資料:
4609
	#無.
4610
	#備註:
4611
	#無.
4612
	*/
4613
	public static function checkPathExist(&$conf){
226 liveuser 4614
 
3 liveuser 4615
		#初始化要回傳的內容
4616
		$result=array();
4617
 
4618
		#取得當前執行的函數名稱
4619
		$result["function"]=__FUNCTION__;
4620
 
4621
		#如果 $conf 不為陣列
4622
		if(gettype($conf)!="array"){
226 liveuser 4623
 
3 liveuser 4624
			#設置執行失敗
4625
			$result["status"]="false";
226 liveuser 4626
 
3 liveuser 4627
			#設置執行錯誤訊息
4628
			$result["error"][]="\$conf變數須為陣列形態";
4629
 
4630
			#如果傳入的參數為 null
4631
			if($conf==null){
226 liveuser 4632
 
3 liveuser 4633
				#設置執行錯誤訊息
4634
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 4635
 
3 liveuser 4636
				}#if end
4637
 
4638
			#回傳結果
4639
			return $result;
226 liveuser 4640
 
3 liveuser 4641
			}#if end
4642
 
4643
		#記錄使用的參數
4644
		$result["argu"]=$conf;
4645
 
4646
		#檢查參數
4647
		#函式說明:
4648
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4649
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4650
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4651
		#$result["function"],當前執行的函式名稱.
4652
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4653
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4654
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4655
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
4656
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4657
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4658
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4659
		#必填寫的參數:
4660
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4661
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
4662
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4663
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","fileArgu");
226 liveuser 4664
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 4665
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
4666
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4667
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
4668
		#可以省略的參數:
4669
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
4670
		#$conf["canBeEmptyString"]="false";
4671
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4672
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("haveFileName");
226 liveuser 4673
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 4674
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
4675
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4676
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
4677
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4678
		#$conf["arrayCountEqualCheck"][]=array();
4679
		#參考資料來源:
4680
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4681
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4682
		unset($conf["variableCheck::checkArguments"]);
4683
 
4684
		#如果檢查有誤
4685
		if($checkResult["status"]=="false"){
226 liveuser 4686
 
3 liveuser 4687
			#設置錯誤識別
4688
			$result["status"]="false";
226 liveuser 4689
 
3 liveuser 4690
			#設置錯誤訊息
4691
			$result["error"]=$checkResult;
226 liveuser 4692
 
3 liveuser 4693
			#回傳結果
4694
			return $result;
226 liveuser 4695
 
3 liveuser 4696
			}#if end
226 liveuser 4697
 
3 liveuser 4698
		#如果檢查不通過
4699
		if($checkResult["passed"]=="false"){
226 liveuser 4700
 
3 liveuser 4701
			#設置錯誤識別
4702
			$result["status"]="false";
226 liveuser 4703
 
3 liveuser 4704
			#設置錯誤訊息
4705
			$result["error"]=$checkResult;
226 liveuser 4706
 
3 liveuser 4707
			#回傳結果
4708
			return $result;
226 liveuser 4709
 
3 liveuser 4710
			}#if end
226 liveuser 4711
 
3 liveuser 4712
		#函式說明:
4713
		#解析路徑的每個層級.
4714
		#回傳結果:
4715
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4716
		#$result["error"],錯誤訊息陣列.
4717
		#$resutl["function"],當前執行的涵式名稱.
4718
		#$result["argu"],使用的參數.
4719
		#$result["content"],解析出來的路徑階層.
4720
		#必填參數:
4721
		#$conf["path"],要檢查的路徑
4722
		$conf["fileAccess::parsePath"]["path"]=$conf["path"];
4723
		#可省略參數:
4724
		#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
4725
		$conf["fileAccess::parsePath"]["haveFileName"]=$conf["haveFileName"];
4726
		#參考資料:
4727
		#無.
4728
		#備註:
4729
		#無.
4730
		$parsePath=fileAccess::parsePath($conf["fileAccess::parsePath"]);
4731
		unset($conf["fileAccess::parsePath"]);
226 liveuser 4732
 
3 liveuser 4733
		#如果檢查有誤
4734
		if($parsePath["status"]==="false"){
226 liveuser 4735
 
3 liveuser 4736
			#設置錯誤識別
4737
			$result["status"]="false";
226 liveuser 4738
 
3 liveuser 4739
			#設置錯誤訊息
4740
			$result["error"]=$parsePath;
226 liveuser 4741
 
3 liveuser 4742
			#回傳結果
4743
			return $result;
226 liveuser 4744
 
3 liveuser 4745
			}#if end
226 liveuser 4746
 
3 liveuser 4747
		#函式說明:
4748
		#檢查多個檔案與資料夾是否存在.
4749
		#回傳的結果:
4750
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
4751
		#$result["error"],錯誤訊息陣列.
4752
		#$resutl["function"],當前執行的涵式名稱.
4753
		#$result["argu"],使用的參數.
4754
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
4755
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
4756
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
4757
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
4758
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
4759
		#必填參數:
4760
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
4761
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=$parsePath["content"];
4762
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
4763
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
4764
		#可省略參數:
4765
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
4766
		$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="true";
4767
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
4768
		$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
4769
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
4770
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
4771
		#參考資料:
4772
		#http://php.net/manual/en/function.file-exists.php
4773
		#http://php.net/manual/en/control-structures.foreach.php
4774
		#備註:
4775
		#函數file_exists檢查的路徑為檔案系統的路徑
4776
		#$result["varName"][$i]結果未實作
4777
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
4778
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 4779
 
3 liveuser 4780
		#如果執行異常
4781
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 4782
 
3 liveuser 4783
			#設置錯誤識別
4784
			$result["status"]="false";
226 liveuser 4785
 
3 liveuser 4786
			#設置錯誤訊息
4787
			$result["error"]=$checkMultiFileExist;
226 liveuser 4788
 
3 liveuser 4789
			#回傳結果
4790
			return $result;
226 liveuser 4791
 
3 liveuser 4792
			}#if end
226 liveuser 4793
 
3 liveuser 4794
		#如果有路徑無法存取
4795
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 4796
 
3 liveuser 4797
			#設置執行正常識別
4798
			$result["status"]="true";
226 liveuser 4799
 
3 liveuser 4800
			#設置路徑找不到
4801
			$result["found"]="false";
226 liveuser 4802
 
3 liveuser 4803
			#針對每個路徑的搜尋結果
4804
			foreach($checkMultiFileExist["varExist"] as $index => $found){
226 liveuser 4805
 
3 liveuser 4806
				#設置路徑尋找結果
4807
				$result["content"][]=array("found"=>$found,"path"=>$checkMultiFileExist["varNameFullPath"][$index]);
226 liveuser 4808
 
3 liveuser 4809
				}#foreach end
226 liveuser 4810
 
3 liveuser 4811
			#回傳結果
4812
			return $result;
226 liveuser 4813
 
3 liveuser 4814
			}#if end
226 liveuser 4815
 
3 liveuser 4816
		#設置路徑有找到
4817
		$result["found"]="true";
226 liveuser 4818
 
3 liveuser 4819
		#設置執行正常識別
4820
		$result["status"]="true";
226 liveuser 4821
 
3 liveuser 4822
		#回傳結果
4823
		return $result;
226 liveuser 4824
 
3 liveuser 4825
		}#function checkPathExist end
226 liveuser 4826
 
4827
	/*
3 liveuser 4828
	#函式說明:
4829
	#demo建立pdf檔
4830
	#必填參數:
4831
	#無
4832
	#可省略參數:
4833
	#無
4834
	#參考資料:
4835
	#tcpdf=>http://www.tcpdf.org/examples.php
4836
	#備註:
4837
	#開發中,需要安裝 php-tcpdf 套件.
4838
	*/
4839
	public static function demoCreateTcPdfFile(){
226 liveuser 4840
 
3 liveuser 4841
		#避免 TCPDF ERROR: Some data has already been output, can't send PDF file 錯誤產生
4842
		ob_end_clean();
226 liveuser 4843
 
3 liveuser 4844
		#create new PDF document
4845
		$pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
226 liveuser 4846
 
3 liveuser 4847
		#set document information
4848
		$pdf->SetCreator(PDF_CREATOR);
4849
		$pdf->SetAuthor('qbpwc');
4850
		$pdf->SetTitle('pdf sample title');
4851
		$pdf->SetSubject('pdf sample subject');
4852
		$pdf->SetKeywords('pdf, sample, tcpdf, qbpwc');
226 liveuser 4853
 
3 liveuser 4854
		#set default header data
4855
		$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
4856
		$pdf->setFooterData(array(0,64,0), array(0,64,128));
226 liveuser 4857
 
3 liveuser 4858
		#set header and footer fonts
4859
		$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
4860
		$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
226 liveuser 4861
 
3 liveuser 4862
		#set default monospaced font
4863
		$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
226 liveuser 4864
 
3 liveuser 4865
		#set margins
4866
		$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
4867
		$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
4868
		$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
4869
 
4870
		#set auto page breaks
4871
		$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
4872
 
4873
		#set image scale factor
4874
		$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
4875
 
4876
		#set some language-dependent strings (optional)
4877
		if (@file_exists(dirname(__FILE__).'/lang/eng.php')){
226 liveuser 4878
 
3 liveuser 4879
			require_once(dirname(__FILE__).'/lang/eng.php');
226 liveuser 4880
 
3 liveuser 4881
			$pdf->setLanguageArray($l);
226 liveuser 4882
 
3 liveuser 4883
			}#if end
226 liveuser 4884
 
3 liveuser 4885
		#set default font subsetting mode
4886
		$pdf->setFontSubsetting(true);
226 liveuser 4887
 
3 liveuser 4888
		#Set font
4889
		#dejavusans is a UTF-8 Unicode font, if you only need to
4890
		#print standard ASCII chars, you can use core fonts like
4891
		#helvetica or times to reduce file size.
4892
		$pdf->SetFont('dejavusans', '', 14, '', true);
226 liveuser 4893
 
3 liveuser 4894
		#Add a page
4895
		#This method has several options, check the source code documentation for more information.
4896
		$pdf->AddPage();
226 liveuser 4897
 
3 liveuser 4898
		#set text shadow effect
4899
		$pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));
226 liveuser 4900
 
3 liveuser 4901
		#Set some content to print
4902
		$html="<h5>Hello World!</h5>";
226 liveuser 4903
 
3 liveuser 4904
		// Print text using writeHTMLCell()
4905
		$pdf->writeHTMLCell(0,0,'','',$html,0,1,0,true,'',true);
4906
 
4907
		// Close and output PDF document
4908
		// This method has several options, check the source code documentation for more information.
4909
		$pdf->Output('fileAccessT/example_001.pdf','I');
226 liveuser 4910
 
3 liveuser 4911
		}#function demoCreateTcPdfFile end
226 liveuser 4912
 
3 liveuser 4913
	/*
4914
	#函式說明:
4915
	#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
4916
	#回傳的結果:
4917
	#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
4918
	#$result["error"],錯誤訊息.
4919
	#$result["function"],當前執行的函式名稱.
4920
	#$result["filePath"],路徑字串.
4921
	#$result["fileName"],檔案名稱字串.
4922
	#$result["fileExtention"],檔案的副檔名.
4923
	#$result["fullFileName"],含副檔名的檔案名稱.
4924
	#$result["fullFilePathAndName"],完整的檔案路徑(含副檔名).
4925
	#必填參數:
4926
	#$conf["fileAddressAndName"],字串,檔案名稱與其路徑.
4927
	$conf["fileAddressAndName"]="";
4928
	#可省略參數:
4929
	#無.
4930
	#參考資料:
4931
	#無.
4932
	#備註:
4933
	#無.
4934
	*/
4935
	public static function getFileAddressAndNameAndFileExtention(&$conf){
226 liveuser 4936
 
3 liveuser 4937
		#初始化要回傳的參數
4938
		$result=array();
226 liveuser 4939
 
3 liveuser 4940
		#取得當前執行函數名稱
4941
		$result["function"]=__FUNCTION__;
4942
 
4943
		#如果 $conf 不為陣列
4944
		if(gettype($conf)!="array"){
226 liveuser 4945
 
3 liveuser 4946
			#設置執行失敗
4947
			$result["status"]="false";
226 liveuser 4948
 
3 liveuser 4949
			#設置執行錯誤訊息
4950
			$result["error"][]="\$conf變數須為陣列形態";
4951
 
4952
			#如果傳入的參數為 null
4953
			if($conf==null){
226 liveuser 4954
 
3 liveuser 4955
				#設置執行錯誤訊息
4956
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 4957
 
3 liveuser 4958
				}#if end
4959
 
4960
			#回傳結果
4961
			return $result;
226 liveuser 4962
 
3 liveuser 4963
			}#if end
4964
 
4965
		#檢查參數
4966
		#函式說明:
4967
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4968
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4969
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4970
		#$result["function"],當前執行的函式名稱.
4971
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4972
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4973
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4974
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
4975
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4976
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4977
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4978
		#必填寫的參數:
4979
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4980
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
4981
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4982
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileAddressAndName");
226 liveuser 4983
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 4984
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
4985
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4986
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
4987
		#可以省略的參數:
4988
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
4989
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
4990
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4991
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("outputAddress","noDownload");
226 liveuser 4992
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 4993
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
4994
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4995
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(".bin/".$conf["cppAddress"].".bin","true");
4996
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4997
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
4998
		#參考資料來源:
4999
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5000
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5001
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 5002
 
3 liveuser 5003
		#如果 $checkArguments["status"] 等於 "false"
5004
		if($checkArguments["status"]=="false"){
226 liveuser 5005
 
3 liveuser 5006
			#設置 $result["status"] 為 "false"
5007
			$result["status"]="false";
226 liveuser 5008
 
3 liveuser 5009
			#設置 $result["error"]
5010
			$result["error"]=$checkArguments;
226 liveuser 5011
 
3 liveuser 5012
			#回傳結果
5013
			return $result;
226 liveuser 5014
 
3 liveuser 5015
			}#if end
226 liveuser 5016
 
3 liveuser 5017
		#如果 $checkArguments["passed"] 等於 "false"
5018
		if($checkArguments["passed"]=="false"){
226 liveuser 5019
 
3 liveuser 5020
			#設置 $result["status"] 為 "false"
5021
			$result["status"]="false";
226 liveuser 5022
 
3 liveuser 5023
			#設置 $result["error"]
5024
			$result["error"]=$checkArguments;
226 liveuser 5025
 
3 liveuser 5026
			#回傳結果
5027
			return $result;
226 liveuser 5028
 
3 liveuser 5029
			}#if end
226 liveuser 5030
 
3 liveuser 5031
		#確認路徑是否為絕對路徑
5032
		#函式說明:
5033
		#取得符合特定字首與字尾的字串
5034
		#回傳結果:
5035
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
5036
		#$result["function"],當前執行的函數名稱.
5037
		#$result["error"],錯誤訊息陣列.
5038
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
5039
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
5040
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
5041
		#$result["argu"],使用的參數.
5042
		#必填參數:
5043
		#$conf["checkString"],字串,要檢查的字串.
5044
		$conf["fileAccess::getMeetConditionsString"]["checkString"]=$conf["fileAddressAndName"];
5045
		#可省略參數:
5046
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
5047
		$conf["fileAccess::getMeetConditionsString"]["frontWord"]="/";
5048
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
5049
		#$conf["tailWord"]="";
5050
		#參考資料:
5051
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
5052
		#備註:
5053
		#無.
5054
		$getMeetConditionsString=search::getMeetConditionsString($conf["fileAccess::getMeetConditionsString"]);
5055
		unset($conf["fileAccess::getMeetConditionsString"]);
226 liveuser 5056
 
3 liveuser 5057
		#如果執行出錯
5058
		if($getMeetConditionsString["status"]==="false"){
226 liveuser 5059
 
3 liveuser 5060
			#設置錯誤識別
5061
			$result["status"]="false";
226 liveuser 5062
 
3 liveuser 5063
			#設置錯誤訊息
5064
			$result["error"]=$getMeetConditionsString;
226 liveuser 5065
 
3 liveuser 5066
			#回傳結果
5067
			return $result;
226 liveuser 5068
 
3 liveuser 5069
			}#if end
226 liveuser 5070
 
3 liveuser 5071
		#預設參數 $conf["fileAddressAndName"] 不為 "/" 開始
5072
		$fileAddressAndNameStarFromRoot="true";
226 liveuser 5073
 
3 liveuser 5074
		#如果是 "/" 開頭
5075
		if($getMeetConditionsString["founded"]==="false"){
226 liveuser 5076
 
3 liveuser 5077
			#設置參數 $conf["fileAddressAndName"] 為 "/" 開始
5078
			$fileAddressAndNameStarFromRoot="true";
226 liveuser 5079
 
3 liveuser 5080
			}#if end
226 liveuser 5081
 
5082
		#檢查是否有路徑資訊
3 liveuser 5083
		#函式說明:
5084
		#將固定格式的字串分開,並回傳分開的結果。
5085
		#回傳的參數:
5086
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5087
		#$result["error"],錯誤訊息陣列
5088
		#$result["oriStr"],要分割的原始字串內容
5089
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5090
		#$result["dataCounts"],爲總共分成幾段
5091
		#必填參數:
5092
		$conf["stringProcess"]["spiltString"]["stringIn"]=$conf["fileAddressAndName"];#要處理的字串。
5093
		$conf["stringProcess"]["spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
5094
		$spiledResult=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5095
		unset($conf["stringProcess"]["spiltString"]);
226 liveuser 5096
 
3 liveuser 5097
		#如果 $spiledResult["status"] 等於 "false"
5098
		if($spiledResult["status"]==="false"){
226 liveuser 5099
 
3 liveuser 5100
			#設置錯誤識別
5101
			$result["status"]="false";
226 liveuser 5102
 
3 liveuser 5103
			#設置錯誤訊息
5104
			$result["error"]=$spiledResult;
226 liveuser 5105
 
3 liveuser 5106
			#回傳結果
5107
			return $result;
226 liveuser 5108
 
3 liveuser 5109
			}#if end
226 liveuser 5110
 
3 liveuser 5111
		#如果 $spiledResult["dataCounts"] 大於 1
5112
		if($spiledResult["dataCounts"]>1){
226 liveuser 5113
 
3 liveuser 5114
			#代表有路徑字串
226 liveuser 5115
 
3 liveuser 5116
			#初始化路徑字串暫存變數
5117
			$tempPathStr="";
226 liveuser 5118
 
3 liveuser 5119
			#如果是絕對路徑
5120
			if($fileAddressAndNameStarFromRoot==="true"){
226 liveuser 5121
 
3 liveuser 5122
				#加上根目錄
5123
				$tempPathStr=$tempPathStr."/";
226 liveuser 5124
 
3 liveuser 5125
				}#if end
226 liveuser 5126
 
3 liveuser 5127
			#取得路徑字串
5128
			for($i=0;$i<$spiledResult["dataCounts"]-1;$i++){
226 liveuser 5129
 
3 liveuser 5130
				#串連片段路徑字串
5131
				$tempPathStr=$tempPathStr.$spiledResult["dataArray"][$i]."/";
226 liveuser 5132
 
3 liveuser 5133
				}#for end
226 liveuser 5134
 
3 liveuser 5135
			#取得檔案的路徑
5136
			$result["filePath"]=$tempPathStr;
226 liveuser 5137
 
3 liveuser 5138
			}#if end
226 liveuser 5139
 
3 liveuser 5140
		#反之 $spiledResult["dataCounts"] 等於 1
5141
		else{
226 liveuser 5142
 
3 liveuser 5143
			#檔案的路徑設為""
5144
			$result["filePath"]="";
226 liveuser 5145
 
3 liveuser 5146
			}#else end
226 liveuser 5147
 
3 liveuser 5148
		#取得檔案名稱(含副檔名)
5149
		$result["fullFileName"]=$spiledResult["dataArray"][$spiledResult["dataCounts"]-1];
226 liveuser 5150
 
3 liveuser 5151
		#取得副檔名
5152
		#函式說明:
5153
		#將固定格式的字串分開,並回傳分開的結果。
5154
		#回傳的參數:
5155
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5156
		#$result["error"],錯誤訊息陣列
5157
		#$result["oriStr"],要分割的原始字串內容
5158
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5159
		#$result["dataCounts"],爲總共分成幾段
5160
		#必填參數:
5161
		$conf["stringProcess"]["spiltString"]["stringIn"]=$result["fullFileName"];#要處理的字串。
5162
		$conf["stringProcess"]["spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
5163
		$spiledResult=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5164
		unset($conf["stringProcess"]["spiltString"]);
226 liveuser 5165
 
3 liveuser 5166
		#如果 $spiledResult["status"] 等於 "false"
5167
		if($spiledResult["status"]=="false"){
226 liveuser 5168
 
3 liveuser 5169
			#設置錯誤識別
5170
			$result["status"]="false";
226 liveuser 5171
 
3 liveuser 5172
			#設置錯誤訊息
5173
			$result["error"]=$spiledResult;
226 liveuser 5174
 
3 liveuser 5175
			#回傳結果
5176
			return $result;
226 liveuser 5177
 
3 liveuser 5178
			}#if end
226 liveuser 5179
 
3 liveuser 5180
		#如果 $spiledResult["dataCounts"] 大於 1
5181
		if($spiledResult["dataCounts"]>1){
226 liveuser 5182
 
3 liveuser 5183
			#代表有副檔名
226 liveuser 5184
 
3 liveuser 5185
			#初始化檔名字串暫存變數
5186
			$tempFileNameStr="";
226 liveuser 5187
 
3 liveuser 5188
			#取得路徑字串
5189
			for($i=0;$i<$spiledResult["dataCounts"]-1;$i++){
226 liveuser 5190
 
3 liveuser 5191
				#如果是最後一個小黑點前面的字串片段
5192
				if($i==$spiledResult["dataCounts"]-2){
226 liveuser 5193
 
3 liveuser 5194
					#串連片段路徑字串
5195
					$tempFileNameStr=$tempFileNameStr.$spiledResult["dataArray"][$i];
226 liveuser 5196
 
3 liveuser 5197
					}#if end
226 liveuser 5198
 
3 liveuser 5199
				#反之不是最後一個小黑點前面的字串片段
5200
				else{
226 liveuser 5201
 
3 liveuser 5202
					#串連片段路徑字串(含小黑點)
5203
					$tempFileNameStr=$tempFileNameStr.$spiledResult["dataArray"][$i].".";
226 liveuser 5204
 
3 liveuser 5205
					}#else end
226 liveuser 5206
 
3 liveuser 5207
				}#for end
226 liveuser 5208
 
3 liveuser 5209
			#取得檔名
5210
			$result["fileName"]=$tempFileNameStr;
226 liveuser 5211
 
3 liveuser 5212
			#取得副檔名
5213
			$result["fileExtention"]=$spiledResult["dataArray"][$spiledResult["dataCounts"]-1];
226 liveuser 5214
 
3 liveuser 5215
			}#if end
226 liveuser 5216
 
3 liveuser 5217
		#反之 $spiledResult["dataCounts"] 等於 1
5218
		else{
226 liveuser 5219
 
3 liveuser 5220
			#檔案的副檔名設為""
5221
			$result["fileExtention"]="";
226 liveuser 5222
 
3 liveuser 5223
			#取得檔案的名稱
5224
			$result["fileName"]=$spiledResult["dataArray"][0];
226 liveuser 5225
 
3 liveuser 5226
			}#else end
226 liveuser 5227
 
3 liveuser 5228
		#如果 $result["fileExtention"] 不等於 ""
5229
		if($result["fileExtention"]!=""){
226 liveuser 5230
 
3 liveuser 5231
			#將副檔名用小黑點跟檔案名稱連在一塊
5232
			$result["fullFileName"]=$result["fileName"].".".$result["fileExtention"];
226 liveuser 5233
 
3 liveuser 5234
			}#if end
226 liveuser 5235
 
3 liveuser 5236
		#反之代表沒有副檔名
5237
		else{
226 liveuser 5238
 
3 liveuser 5239
			#取得含副檔名的檔案名稱
5240
			$result["fullFileName"]=$result["fileName"].$result["fileExtention"];
226 liveuser 5241
 
3 liveuser 5242
			}#else end
226 liveuser 5243
 
3 liveuser 5244
		#完整的檔案路徑(含副檔名).
5245
		$result["fullFilePathAndName"]=$result["filePath"].$result["fullFileName"];
226 liveuser 5246
 
3 liveuser 5247
		#設置執行正常的識別
5248
		$result["status"]="true";
226 liveuser 5249
 
3 liveuser 5250
		#回傳結果
5251
		return $result;
226 liveuser 5252
 
3 liveuser 5253
		}#funciton getFileAddressAndNameAndFileExtention end
5254
 
5255
	/*
5256
	#函式說明:
5257
	#將資料夾或檔案打包成tar檔案
5258
	#回傳結果:
5259
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5260
	#$result["function"],當前執行的函數名稱
5261
	#$result["error"],錯誤訊息.
5262
	#$result["content"],檔案輸出後的位置與名稱.
5263
	#必填參數:
5264
	#$conf["packetTarget"],陣列,要打包的每個資料夾與檔案位置
5265
	$conf["packetTarget"]=array("");
5266
	#$conf["createdTarFile"],字串,打包好的檔案要放在哪裡,副檔名.tar會自動加上.
5267
	$conf["createdTarFile"]="";
5268
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5269
	$conf["fileArgu"]=__FILE__;
5270
	#可省略參數:
5271
	#無.
5272
	#參考資料:
5273
	#無.
5274
	#備註:
5275
	#無.
5276
	*/
5277
	public static function makeTarFile(&$conf){
226 liveuser 5278
 
3 liveuser 5279
		#初始化要回傳的內容
5280
		$result=array();
226 liveuser 5281
 
3 liveuser 5282
		#記錄當前執行的函數名稱
5283
		$result["function"]=__FUNCTION__;
226 liveuser 5284
 
3 liveuser 5285
		#如果 $conf 不為陣列
5286
		if(gettype($conf)!="array"){
226 liveuser 5287
 
3 liveuser 5288
			#設置執行失敗
5289
			$result["status"]="false";
226 liveuser 5290
 
3 liveuser 5291
			#設置執行錯誤訊息
5292
			$result["error"][]="\$conf變數須為陣列形態";
5293
 
5294
			#如果傳入的參數為 null
5295
			if($conf==null){
226 liveuser 5296
 
3 liveuser 5297
				#設置執行錯誤訊息
5298
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 5299
 
3 liveuser 5300
				}#if end
5301
 
5302
			#回傳結果
5303
			return $result;
226 liveuser 5304
 
3 liveuser 5305
			}#if end
226 liveuser 5306
 
3 liveuser 5307
		#檢查參數
5308
		#函式說明:
5309
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5310
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5311
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5312
		#$result["function"],當前執行的函式名稱.
5313
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5314
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5315
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5316
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
5317
		#必填寫的參數:
5318
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5319
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5320
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5321
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","packetTarget","createdTarFile");
226 liveuser 5322
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 5323
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","string");
5324
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5325
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5326
		#可以省略的參數:
5327
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
5328
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5329
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5330
		#$conf["skipableVariableName"]=array();
226 liveuser 5331
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 5332
		#$conf["skipableVariableType"]=array();
5333
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5334
		#$conf["skipableVarDefaultValue"]=array("");
5335
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5336
		#$conf["arrayCountEqualCheck"][]=array();
5337
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5338
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 5339
 
3 liveuser 5340
		#若檢查失敗
5341
		if($checkResult["status"]=="false"){
226 liveuser 5342
 
3 liveuser 5343
			#設置執行失敗
5344
			$result["status"]="false";
226 liveuser 5345
 
3 liveuser 5346
			#設置執行錯誤訊息
5347
			$result["error"]=$checkResult;
226 liveuser 5348
 
3 liveuser 5349
			#回傳結果
5350
			return $result;
226 liveuser 5351
 
3 liveuser 5352
			}#if end
226 liveuser 5353
 
3 liveuser 5354
		#若檢查不通過
5355
		if($checkResult["passed"]=="false"){
226 liveuser 5356
 
3 liveuser 5357
			#設置執行失敗
5358
			$result["status"]="false";
226 liveuser 5359
 
3 liveuser 5360
			#設置執行錯誤訊息
5361
			$result["error"]=$checkResult;
226 liveuser 5362
 
3 liveuser 5363
			#回傳結果
5364
			return $result;
226 liveuser 5365
 
3 liveuser 5366
			}#if end
226 liveuser 5367
 
3 liveuser 5368
		#初始化打包要用的tar指令參數
5369
		$paramsArray=array("-cvf",$conf["createdTarFile"].".tar");
226 liveuser 5370
 
3 liveuser 5371
		#檢查要打包的檔案是否存在
5372
		#函式說明:
5373
		#檢查多個檔案與資料夾是否存在.
5374
		#回傳的結果:
5375
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
5376
		#$result["error"],錯誤訊息陣列.
5377
		#$resutl["function"],當前執行的涵式名稱.
5378
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
5379
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
5380
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
5381
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
5382
		#必填參數:
5383
		#$conf["fileArray"],陣列字串,要檢查書否存在的檔案有哪些,須爲一維陣列數值。
5384
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=$conf["packetTarget"];
5385
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5386
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
5387
		#可省略參數
5388
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
5389
		#$conf["disableWebSearch"]="false";
5390
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
5391
		#$conf["userDir"]="true";
5392
		#參考資料來源:
5393
		#http://php.net/manual/en/function.file-exists.php
5394
		#http://php.net/manual/en/control-structures.foreach.php
5395
		#備註:
5396
		#函數file_exists檢查的路徑為檔案系統的路徑
5397
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
5398
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 5399
 
3 liveuser 5400
		#如果檢查要打包的檔案失敗
5401
		if($checkMultiFileExist["status"]=="false"){
226 liveuser 5402
 
3 liveuser 5403
			#設置執行失敗
5404
			$result["status"]="false";
226 liveuser 5405
 
3 liveuser 5406
			#設置執行錯誤訊息
5407
			$result["error"]=$checkMultiFileExist;
226 liveuser 5408
 
3 liveuser 5409
			#回傳結果
5410
			return $result;
226 liveuser 5411
 
3 liveuser 5412
			}#if end
226 liveuser 5413
 
3 liveuser 5414
		#如果要打包的檔案有缺
5415
		if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 5416
 
3 liveuser 5417
			#設置執行失敗
5418
			$result["status"]="false";
226 liveuser 5419
 
3 liveuser 5420
			#設置執行錯誤訊息
5421
			$result["error"]=$checkMultiFileExist;
226 liveuser 5422
 
3 liveuser 5423
			#回傳結果
5424
			return $result;
226 liveuser 5425
 
3 liveuser 5426
			}#if end
226 liveuser 5427
 
3 liveuser 5428
		#有幾個要打包的目標就執行幾次
5429
		for($i=0;$i<count($conf["packetTarget"]);$i++){
226 liveuser 5430
 
3 liveuser 5431
			#串接上要打包的檔案或資料夾
5432
			$paramsArray[]=$conf["packetTarget"][$i];
226 liveuser 5433
 
3 liveuser 5434
			}#for end
226 liveuser 5435
 
3 liveuser 5436
		#函式說明:
5437
		#呼叫shell執行系統命令,並取得回傳的內容.
5438
		#回傳結果:
5439
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5440
		#$result["error"],錯誤訊息陣列.
5441
		#$result["function"],當前執行的函數名稱.
5442
		#$result["argu"],使用的參數.
5443
		#$result["cmd"],執行的指令內容.
5444
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
5445
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
5446
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
5447
		#$result["running"],是否還在執行.
5448
		#$result["pid"],pid.
5449
		#$result["statusCode"],執行結束後的代碼.
5450
		#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
5451
		#必填參數:
5452
		#$conf["command"],字串,要執行的指令.
5453
		$conf["external::callShell"]["command"]="tar";
5454
		#$conf["fileArgu"],字串,變數__FILE__的內容.
5455
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
5456
		#可省略參數:
5457
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
5458
		$conf["external::callShell"]["argu"]=$paramsArray;
5459
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
5460
		#$conf["arguIsAddr"]=array();
5461
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
5462
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
5463
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
5464
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
5465
		#$conf["enablePrintDescription"]="true";
5466
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
5467
		#$conf["printDescription"]="";
5468
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
5469
		$conf["external::callShell"]["escapeshellarg"]="true";
5470
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
5471
		#$conf["thereIsShellVar"]=array();
5472
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
5473
		#$conf["username"]="";
5474
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
5475
		#$conf["password"]="";
5476
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
5477
		#$conf["useScript"]="";
5478
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
5479
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
5480
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
5481
		#$conf["inBackGround"]="";
5482
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
5483
		#$conf["getErr"]="false";
5484
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
5485
		#$conf["doNotRun"]="false";
5486
		#參考資料:
5487
		#exec=>http://php.net/manual/en/function.exec.php
5488
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
5489
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
5490
		#備註:
5491
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
5492
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
5493
		$conf["external::callShell"]=external::callShell($conf["external::callShell"]);
5494
		unset($conf["external::callShell"]);
226 liveuser 5495
 
3 liveuser 5496
		#如果執行shell失敗
5497
		if($callShell["status"]=="false"){
226 liveuser 5498
 
3 liveuser 5499
			#設置執行失敗
5500
			$result["status"]="false";
226 liveuser 5501
 
3 liveuser 5502
			#設置執行錯誤訊息
5503
			$result["error"]=$callShell;
226 liveuser 5504
 
3 liveuser 5505
			#回傳結果
5506
			return $result;
226 liveuser 5507
 
3 liveuser 5508
			}#if end
226 liveuser 5509
 
3 liveuser 5510
		#打包好的檔案位置與名稱
5511
		$result["content"]=$conf["createdTarFile"].".tar";
226 liveuser 5512
 
3 liveuser 5513
		#執行到這邊代表執行正常
5514
		$result["status"]="true";
226 liveuser 5515
 
3 liveuser 5516
		#回傳結果
5517
		return $result;
226 liveuser 5518
 
3 liveuser 5519
		}#function makeTarFile end
226 liveuser 5520
 
3 liveuser 5521
	/*
5522
	#函式說明:
5523
	#將一個檔案壓縮成xz檔案
5524
	#回傳結果:
5525
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5526
	#$result["function"],當前執行的函數名稱
5527
	#$result["error"],錯誤訊息.
5528
	#$result["content"],檔案輸出後的位置與名稱.
5529
	#必填參數:
5530
	#$conf["compressTarget"],字串,要打包的每個資料夾與檔案位置
5531
	$conf["compressTarget"]="";
5532
	#$conf["createdXzFile"],字串,打包好的檔案要放在哪裡,副檔名.xz會自動加上.
5533
	$conf["createdXzFile"]="";
5534
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5535
	$conf["fileArgu"]=__FILE__;
5536
	#可省略參數:
5537
	#無.
5538
	#參考資料:
5539
	#無.
5540
	#備註:
5541
	#無.
5542
	*/
5543
	public static function makeXzFile(&$conf){
5544
 
5545
		#初始化要回傳的內容
5546
		$result=array();
226 liveuser 5547
 
3 liveuser 5548
		#記錄當前執行的函數名稱
5549
		$result["function"]=__FUNCTION__;
226 liveuser 5550
 
3 liveuser 5551
		#如果 $conf 不為陣列
5552
		if(gettype($conf)!="array"){
226 liveuser 5553
 
3 liveuser 5554
			#設置執行失敗
5555
			$result["status"]="false";
226 liveuser 5556
 
3 liveuser 5557
			#設置執行錯誤訊息
5558
			$result["error"][]="\$conf變數須為陣列形態";
5559
 
5560
			#如果傳入的參數為 null
5561
			if($conf==null){
226 liveuser 5562
 
3 liveuser 5563
				#設置執行錯誤訊息
5564
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 5565
 
3 liveuser 5566
				}#if end
5567
 
5568
			#回傳結果
5569
			return $result;
226 liveuser 5570
 
3 liveuser 5571
			}#if end
226 liveuser 5572
 
3 liveuser 5573
		#檢查參數
5574
		#函式說明:
5575
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5576
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5577
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5578
		#$result["function"],當前執行的函式名稱.
5579
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5580
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5581
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5582
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
5583
		#必填寫的參數:
5584
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5585
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5586
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5587
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","compressTarget","createdXzFile");
226 liveuser 5588
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 5589
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
5590
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5591
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5592
		#可以省略的參數:
5593
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
5594
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5595
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5596
		#$conf["skipableVariableName"]=array();
226 liveuser 5597
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 5598
		#$conf["skipableVariableType"]=array();
5599
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5600
		#$conf["skipableVarDefaultValue"]=array("");
5601
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5602
		#$conf["arrayCountEqualCheck"][]=array();
5603
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5604
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 5605
 
3 liveuser 5606
		#若檢查失敗
5607
		if($checkResult["status"]=="false"){
226 liveuser 5608
 
3 liveuser 5609
			#設置執行失敗
5610
			$result["status"]="false";
226 liveuser 5611
 
3 liveuser 5612
			#設置執行錯誤訊息
5613
			$result["error"]=$checkResult;
226 liveuser 5614
 
3 liveuser 5615
			#回傳結果
5616
			return $result;
226 liveuser 5617
 
3 liveuser 5618
			}#if end
226 liveuser 5619
 
3 liveuser 5620
		#若檢查不通過
5621
		if($checkResult["passed"]=="false"){
226 liveuser 5622
 
3 liveuser 5623
			#設置執行失敗
5624
			$result["status"]="false";
226 liveuser 5625
 
3 liveuser 5626
			#設置執行錯誤訊息
5627
			$result["error"]=$checkResult;
226 liveuser 5628
 
3 liveuser 5629
			#回傳結果
5630
			return $result;
226 liveuser 5631
 
3 liveuser 5632
			}#if end
226 liveuser 5633
 
3 liveuser 5634
		#檢查要用xz壓縮的檔案是否存在
5635
		#函式說明:
5636
		#檢查多個檔案與資料夾是否存在.
5637
		#回傳的結果:
5638
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
5639
		#$result["error"],錯誤訊息陣列.
5640
		#$resutl["function"],當前執行的涵式名稱.
5641
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
5642
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
5643
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
5644
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
5645
		#必填參數:
5646
		#$conf["fileArray"],陣列字串,要檢查書否存在的檔案有哪些,須爲一維陣列數值。
5647
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["compressTarget"]);
5648
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5649
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
5650
		#可省略參數
5651
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
5652
		#$conf["disableWebSearch"]="false";
5653
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
5654
		#$conf["userDir"]="true";
5655
		#參考資料來源:
5656
		#http://php.net/manual/en/function.file-exists.php
5657
		#http://php.net/manual/en/control-structures.foreach.php
5658
		#備註:
5659
		#函數file_exists檢查的路徑為檔案系統的路徑
5660
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
5661
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 5662
 
3 liveuser 5663
		#如果檢查要用xz壓縮的檔案失敗
5664
		if($checkMultiFileExist["status"]=="false"){
226 liveuser 5665
 
3 liveuser 5666
			#設置執行失敗
5667
			$result["status"]="false";
226 liveuser 5668
 
3 liveuser 5669
			#設置執行錯誤訊息
5670
			$result["error"]=$checkMultiFileExist;
226 liveuser 5671
 
3 liveuser 5672
			#回傳結果
5673
			return $result;
226 liveuser 5674
 
3 liveuser 5675
			}#if end
226 liveuser 5676
 
3 liveuser 5677
		#如果要用xz壓縮的檔案有缺
5678
		if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 5679
 
3 liveuser 5680
			#設置執行失敗
5681
			$result["status"]="false";
226 liveuser 5682
 
3 liveuser 5683
			#設置執行錯誤訊息
5684
			$result["error"]=$checkMultiFileExist;
226 liveuser 5685
 
3 liveuser 5686
			#回傳結果
5687
			return $result;
226 liveuser 5688
 
3 liveuser 5689
			}#if end
226 liveuser 5690
 
3 liveuser 5691
		#壓縮要用的xz語法
5692
		#函式說明:
5693
		#呼叫shell執行系統命令,並取得回傳的內容.
5694
		#回傳的結果:
5695
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5696
		#$result["error"],錯誤訊息陣列
5697
		#$result["output"],爲執行完二元碼後的輸出陣列
5698
		#必填的參數
5699
		$conf["external::callShell"]["command"]="xz";#要執行的指令與參數
5700
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5701
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
5702
		#可省略參數:
5703
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
5704
		$conf["external::callShell"]["argu"]=array("-v","-v","-z","-c",$conf["compressTarget"],">",$conf["createdXzFile"].".xz ");
5705
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
5706
		#$conf["enablePrintDescription"]="true";
5707
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
5708
		#$conf["printDescription"]="";
5709
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"true".
5710
		$conf["external::callShell"]["escapeshellarg"]="true";
5711
		#參考資料:
5712
		#http://php.net/manual/en/function.exec.php
5713
		$callShell=external::callShell($conf["external::callShell"]);
5714
		unset($conf["external::callShell"]);
226 liveuser 5715
 
3 liveuser 5716
		#如果執行shell失敗
5717
		if($callShell["status"]=="false"){
226 liveuser 5718
 
3 liveuser 5719
			#設置執行失敗
5720
			$result["status"]="false";
226 liveuser 5721
 
3 liveuser 5722
			#設置執行錯誤訊息
5723
			$result["error"]=$callShell;
226 liveuser 5724
 
3 liveuser 5725
			#回傳結果
5726
			return $result;
226 liveuser 5727
 
3 liveuser 5728
			}#if end
226 liveuser 5729
 
3 liveuser 5730
		#壓縮好的檔案位置與名稱
5731
		$result["content"]=$conf["createdXzFile"].".xz";
226 liveuser 5732
 
3 liveuser 5733
		#執行到這邊代表執行正常
5734
		$result["status"]="status";
226 liveuser 5735
 
3 liveuser 5736
		#回傳結果
5737
		return $result;
5738
 
5739
		}#function makeXzFile end
226 liveuser 5740
 
3 liveuser 5741
	/*
5742
	#函式說明:
5743
	#將資料夾或檔案打包壓縮成tar.xz檔案
5744
	#回傳結果:
5745
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5746
	#$result["function"],當前執行的函數名稱
5747
	#$result["error"],錯誤訊息.
5748
	#$result["content"],檔案輸出後的位置與名稱.
5749
	#必填參數:
5750
	#$conf["compressTarget"],陣列,要打包壓縮的每個資料夾與檔案位置
5751
	$conf["compressTarget"]=array();
5752
	#$conf["createdTarXzFile"],字串,打包壓縮好的檔案要放在哪裡,副檔名.tar.xz會自動加上.
5753
	$conf["createdTarXzFile"]="";
5754
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5755
	$conf["fileArgu"]=__FILE__;
5756
	#可省略參數:
5757
	#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
5758
	#$conf["commentsArray"]=array("");
5759
	#$conf["includeDotStart"],字串,當參數$conf["commentsArray"]含有星號時是否要包含「.」開頭的檔案目錄,預設為"false",不包含,"true"為要包含.
5760
	#$conf["includeDotStart"]="false";
5761
	#$conf["includeWaveEnd"],字串,當參數$conf["commentsArray"]含有星號時是否要包含「~」結尾的檔案.預設為"false",不包含,"true"為要包含.
5762
	#$conf["includeWaveEnd"]="false";
5763
	#參考資料:
5764
	#無.
5765
	#備註:
226 liveuser 5766
	#建議加上 --exclude-backups, --exclude-caches-all
3 liveuser 5767
	*/
5768
	public static function makeTarXzFile(&$conf){
226 liveuser 5769
 
3 liveuser 5770
		#初始化要回傳的內容
5771
		$result=array();
226 liveuser 5772
 
3 liveuser 5773
		#記錄當前執行的函數名稱
5774
		$result["function"]=__FUNCTION__;
226 liveuser 5775
 
3 liveuser 5776
		#如果 $conf 不為陣列
5777
		if(gettype($conf)!="array"){
226 liveuser 5778
 
3 liveuser 5779
			#設置執行失敗
5780
			$result["status"]="false";
226 liveuser 5781
 
3 liveuser 5782
			#設置執行錯誤訊息
5783
			$result["error"][]="\$conf變數須為陣列形態";
5784
 
5785
			#如果傳入的參數為 null
5786
			if($conf==null){
226 liveuser 5787
 
3 liveuser 5788
				#設置執行錯誤訊息
5789
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 5790
 
3 liveuser 5791
				}#if end
5792
 
5793
			#回傳結果
5794
			return $result;
226 liveuser 5795
 
3 liveuser 5796
			}#if end
226 liveuser 5797
 
3 liveuser 5798
		#檢查參數
5799
		#函式說明:
5800
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
5801
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5802
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5803
		#$result["function"],當前執行的函式名稱.
5804
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5805
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5806
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5807
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
5808
		#必填寫的參數:
5809
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5810
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5811
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5812
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","compressTarget","createdTarXzFile");
226 liveuser 5813
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 5814
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","string");
5815
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5816
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5817
		#可以省略的參數:
5818
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
5819
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5820
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5821
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray","includeDotStart","includeWaveEnd");
226 liveuser 5822
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 5823
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string");
5824
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5825
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false","false");
5826
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5827
		#$conf["arrayCountEqualCheck"][]=array();
5828
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5829
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 5830
 
3 liveuser 5831
		#若檢查失敗
5832
		if($checkResult["status"]=="false"){
226 liveuser 5833
 
3 liveuser 5834
			#設置執行失敗
5835
			$result["status"]="false";
226 liveuser 5836
 
3 liveuser 5837
			#設置執行錯誤訊息
5838
			$result["error"]=$checkResult;
226 liveuser 5839
 
3 liveuser 5840
			#回傳結果
5841
			return $result;
226 liveuser 5842
 
3 liveuser 5843
			}#if end
226 liveuser 5844
 
3 liveuser 5845
		#若檢查不通過
5846
		if($checkResult["passed"]=="false"){
226 liveuser 5847
 
3 liveuser 5848
			#設置執行失敗
5849
			$result["status"]="false";
226 liveuser 5850
 
3 liveuser 5851
			#設置執行錯誤訊息
5852
			$result["error"]=$checkResult;
226 liveuser 5853
 
3 liveuser 5854
			#回傳結果
5855
			return $result;
226 liveuser 5856
 
3 liveuser 5857
			}#if end
226 liveuser 5858
 
3 liveuser 5859
		#如果 $conf["commentsArray"] 有設定
5860
		if(isset($conf["commentsArray"])){
226 liveuser 5861
 
3 liveuser 5862
			#印出提示文字
5863
			#函式說明:
5864
			#印出多行文字,結尾自動換行.
5865
			#回傳的結果:
5866
			#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
5867
			#$result["function"],當前執行的函數名稱.
5868
			#$result["error"],錯誤訊息陣列.
5869
			#必填參數:
5870
			#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
5871
			$conf["cmd::echoMultiLine"]["outputStringArray"]=$conf["commentsArray"];
5872
			$echoMultiLine=cmd::echoMultiLine($conf["cmd::echoMultiLine"]);
5873
			unset($conf["cmd::echoMultiLine"]);
226 liveuser 5874
 
3 liveuser 5875
			#如果印出提示文字失敗
5876
			if($echoMultiLine["status"]=="false"){
226 liveuser 5877
 
3 liveuser 5878
				#設置執行失敗
5879
				$result["status"]="false";
226 liveuser 5880
 
3 liveuser 5881
				#設置執行錯誤訊息
5882
				$result["error"]=$echoMultiLine;
226 liveuser 5883
 
3 liveuser 5884
				#回傳結果
5885
				return $result;
226 liveuser 5886
 
3 liveuser 5887
				}#if end
226 liveuser 5888
 
5889
			}#if end
5890
 
3 liveuser 5891
		#解析要處理的檔案路徑
5892
		#函式說明:
5893
		#將含有「*」的多個檔案路徑名稱,變成多個符合條件的路徑檔案.
5894
		#回傳結果:
5895
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
5896
		#$result["error"],錯誤訊息陣列.
226 liveuser 5897
		#$result["function"],函數名稱.
3 liveuser 5898
		#$result["content"],字串陣列,多個解析回來的檔案路徑字串.
5899
		#$result["pathCount"],整數,有幾個路徑.
5900
		#必填參數:
5901
		#$conf["path"],字串陣列,要解析含有「*」的檔案路徑字串.
5902
		$conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]["path"]=$conf["compressTarget"];
5903
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
5904
		$conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]["fileArgu"]=$conf["fileArgu"];
5905
		#可省略參數:
5906
		#$conf["noDotStart"],字串,"true"代表不包含「.」開頭的名稱,預設為"false"代表包含「.」開頭的名稱.
5907
		$conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]["noDotStart"]=$conf["includeDotStart"]==="true"?"false":"true";
5908
		#$conf["noWaveEnd"],字串,預設為"true"代表不包含「~」結尾的名稱,"false"代表包含結尾為「~」的名稱.
5909
		$conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]["noWaveEnd"]=$conf["includeWaveEnd"]==="true"?"false":"true";
5910
		$realPathArray=fileAccess::resolveMultiPostionStringWhichContainStarSymbol($conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]);
5911
		unset($conf["fileAccess::resolveMultiPostionStringWhichContainStarSymbol"]);
226 liveuser 5912
 
3 liveuser 5913
		#如果解析路徑失敗
5914
		if($realPathArray["status"]=="false"){
226 liveuser 5915
 
3 liveuser 5916
			#設置執行失敗
5917
			$result["status"]="false";
226 liveuser 5918
 
3 liveuser 5919
			#設置執行錯誤訊息
5920
			$result["error"]=$realPathArray;
226 liveuser 5921
 
3 liveuser 5922
			#回傳結果
5923
			return $result;
226 liveuser 5924
 
3 liveuser 5925
			}#if end
226 liveuser 5926
 
3 liveuser 5927
		#取得解析好的檔案路徑陣列
226 liveuser 5928
		$conf["compressTarget"]=$realPathArray["content"];
5929
 
3 liveuser 5930
		#將路徑轉換成相對路徑
5931
		#函式說明:
5932
		#將多個路徑字串變成相對於當前路徑的相對路徑字串
5933
		#回傳結果:
5934
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
5935
		#$result["error"],錯誤訊息陣列.
226 liveuser 5936
		#$result["function"],函數名稱.
3 liveuser 5937
		#$result["content"],字串陣列,多個轉換好的相對路徑字串.
5938
		#必填參數:
5939
		#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
5940
		$conf["fileAccess::getRelativePath"]["path"]=$conf["compressTarget"];
5941
		#$conf["fileArgu"],字串,當前路徑.
5942
		$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
5943
		$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
5944
		unset($conf["fileAccess::getRelativePath"]);
226 liveuser 5945
 
3 liveuser 5946
		#如果轉換失敗
5947
		if($getRelativePath["status"]=="false"){
226 liveuser 5948
 
3 liveuser 5949
			#設置執行失敗
5950
			$result["status"]="false";
226 liveuser 5951
 
3 liveuser 5952
			#設置執行錯誤訊息
5953
			$result["error"]=$getRelativePat;
226 liveuser 5954
 
3 liveuser 5955
			#回傳結果
5956
			return $result;
226 liveuser 5957
 
5958
			}#if end
5959
 
3 liveuser 5960
		#打包成tar檔
5961
		#函式說明:
5962
		#將資料夾或檔案打包成tar檔案
5963
		#回傳的結果:
5964
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5965
		#$result["function"],當前執行的函數名稱
5966
		#$result["error"],錯誤訊息.
5967
		#$result["content"],檔案輸出後的位置與名稱.
5968
		#必填參數:
5969
		#$conf["fileAccess::makeTarFile"]["packetTarget"],陣列,要打包的每個資料夾與檔案位置
5970
		$conf["fileAccess::makeTarFile"]["packetTarget"]=$getRelativePath["content"];
5971
		#$conf["fileAccess::makeTarFile"]["createdTarFile"],字串,打包好的檔案要放在哪裡,副檔名.tar會自動加上.
5972
		$conf["fileAccess::makeTarFile"]["createdTarFile"]=$conf["createdTarXzFile"];
5973
		#$conf["fileAccess::makeTarFile"]["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5974
		$conf["fileAccess::makeTarFile"]["fileArgu"]=$conf["fileArgu"];
5975
		$makeTarFile=fileAccess::makeTarFile($conf["fileAccess::makeTarFile"]);
5976
		unset($conf["fileAccess::makeTarFile"]);
226 liveuser 5977
 
3 liveuser 5978
		#如果打包失敗
5979
		if($makeTarFile["status"]=="false"){
226 liveuser 5980
 
3 liveuser 5981
			#設置執行不正常
5982
			$result["status"]="false";
226 liveuser 5983
 
3 liveuser 5984
			#設置錯誤訊息
5985
			$result["error"]=$makeTarFile;
226 liveuser 5986
 
3 liveuser 5987
			#回傳結果
5988
			return $result;
226 liveuser 5989
 
3 liveuser 5990
			}#if end
226 liveuser 5991
 
3 liveuser 5992
		#壓縮成xz檔
5993
		#函式說明:
5994
		#將一個檔案壓縮成xz檔案
5995
		#回傳的結果:
5996
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5997
		#$result["function"],當前執行的函數名稱
5998
		#$result["error"],錯誤訊息.
5999
		#$result["content"],檔案輸出後的位置與名稱.
6000
		#必填參數:
6001
		#$conf["fileAccess::makeXzFile"]["compressTarget"],字串,要打包的每個資料夾與檔案位置
6002
		$conf["fileAccess::makeXzFile"]["compressTarget"]=$makeTarFile["content"];
6003
		#$conf["fileAccess::makeXzFile"]["createdXzFile"],字串,打包好的檔案要放在哪裡,副檔名.xz會自動加上.
6004
		$conf["fileAccess::makeXzFile"]["createdXzFile"]=$makeTarFile["content"];
6005
		#$conf["fileAccess::makeXzFile"]["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6006
		$conf["fileAccess::makeXzFile"]["fileArgu"]=$conf["fileArgu"];
6007
		$makeXzFile=fileAccess::makeXzFile($conf["fileAccess::makeXzFile"]);
6008
		unset($conf["fileAccess::makeXzFile"]);
226 liveuser 6009
 
3 liveuser 6010
		#如果壓縮失敗
6011
		if($makeXzFile["status"]=="false"){
226 liveuser 6012
 
3 liveuser 6013
			#設置執行不正常
6014
			$result["status"]="false";
226 liveuser 6015
 
3 liveuser 6016
			#設置錯誤訊息
6017
			$result["error"]=$makeXzFile;
226 liveuser 6018
 
3 liveuser 6019
			#回傳結果
6020
			return $result;
226 liveuser 6021
 
3 liveuser 6022
			}#if end
226 liveuser 6023
 
3 liveuser 6024
		#移除tar檔案
6025
		#函式說明:
6026
		#移除檔案
6027
		#回傳結果:
6028
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
6029
		#$result["error"],錯誤訊息陣列
6030
		#$result["warning"],警告訊息陣列
6031
		#$result["function"],當前執行的函數名稱
6032
		#必填參數:
6033
		$conf["fileAccess::delFile"]["fileAddress"]=$makeTarFile["content"];#要移除檔案的位置
6034
		#$conf["fileAccess::delFile"]["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
6035
		$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
6036
		$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
6037
		unset($conf["fileAccess::delFile"]);
226 liveuser 6038
 
3 liveuser 6039
		#如果移除tar檔案失敗
6040
		if($delFile["status"]=="false"){
226 liveuser 6041
 
3 liveuser 6042
			#設置執行不正常
6043
			$result["status"]="false";
226 liveuser 6044
 
3 liveuser 6045
			#設置錯誤訊息
6046
			$result["error"]=$delFile;
226 liveuser 6047
 
3 liveuser 6048
			#回傳結果
6049
			return $result;
226 liveuser 6050
 
3 liveuser 6051
			}#if end
226 liveuser 6052
 
3 liveuser 6053
		#取得壓縮好的檔案位置與名稱
6054
		$result["content"]=$makeXzFile["content"];
226 liveuser 6055
 
3 liveuser 6056
		#執行到這邊代表執行正常
6057
		$result["status"]="true";
226 liveuser 6058
 
3 liveuser 6059
		#回傳結果
6060
		return $result;
226 liveuser 6061
 
3 liveuser 6062
		}#function makeTarXzFile end
226 liveuser 6063
 
3 liveuser 6064
	/*
6065
	#函式說明:
6066
	#移動檔案
6067
	#回傳結果:
6068
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6069
	#$result["function"],當前執行的函數名稱
6070
	#$result["error"],錯誤訊息.
6071
	#$result["content"],檔案輸出後的位置與名稱.
6072
	#必填參數:
6073
	#$conf["from"],字串,要移動的檔案名稱與位置.
6074
	$conf["from"]="";
6075
	#$conf["to"],字串,要移動到的位置與名稱
6076
	$conf["to"]="";
6077
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6078
	$conf["fileArgu"]=__FILE__;
6079
	#可省略參數:
6080
	#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
6081
	#$conf["commentsArray"]=array("");
6082
	#參考資料:
6083
	#無.
6084
	#備註:
6085
	#無.
6086
	*/
6087
	public static function mv(&$conf){
226 liveuser 6088
 
3 liveuser 6089
		#初始化要回傳的結果
6090
		$result=array();
226 liveuser 6091
 
3 liveuser 6092
		#取得當前執行的函數名稱
6093
		$result["function"]=__FUNCTION__;
226 liveuser 6094
 
3 liveuser 6095
		#如果 $conf 不為陣列
6096
		if(gettype($conf)!="array"){
226 liveuser 6097
 
3 liveuser 6098
			#設置執行失敗
6099
			$result["status"]="false";
226 liveuser 6100
 
3 liveuser 6101
			#設置執行錯誤訊息
6102
			$result["error"][]="\$conf變數須為陣列形態";
6103
 
6104
			#如果傳入的參數為 null
6105
			if($conf==null){
226 liveuser 6106
 
3 liveuser 6107
				#設置執行錯誤訊息
6108
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 6109
 
3 liveuser 6110
				}#if end
6111
 
6112
			#回傳結果
6113
			return $result;
226 liveuser 6114
 
3 liveuser 6115
			}#if end
226 liveuser 6116
 
3 liveuser 6117
		#檢查參數
6118
		#函式說明:
6119
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
6120
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6121
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6122
		#$result["function"],當前執行的函式名稱.
6123
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6124
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6125
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6126
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
6127
		#必填寫的參數:
6128
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6129
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6130
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6131
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("from","to","fileArgu");
226 liveuser 6132
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 6133
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
6134
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6135
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6136
		#可以省略的參數:
6137
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
6138
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6139
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6140
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray");
226 liveuser 6141
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 6142
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
6143
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6144
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
6145
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6146
		#$conf["arrayCountEqualCheck"][]=array();
6147
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6148
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 6149
 
3 liveuser 6150
		#若檢查失敗
6151
		if($checkResult["status"]=="false"){
226 liveuser 6152
 
3 liveuser 6153
			#設置執行失敗
6154
			$result["status"]="false";
226 liveuser 6155
 
3 liveuser 6156
			#設置執行錯誤訊息
6157
			$result["error"]=$checkResult;
226 liveuser 6158
 
3 liveuser 6159
			#回傳結果
6160
			return $result;
226 liveuser 6161
 
3 liveuser 6162
			}#if end
226 liveuser 6163
 
3 liveuser 6164
		#若檢查不通過
6165
		if($checkResult["passed"]=="false"){
226 liveuser 6166
 
3 liveuser 6167
			#設置執行失敗
6168
			$result["status"]="false";
226 liveuser 6169
 
3 liveuser 6170
			#設置執行錯誤訊息
6171
			$result["error"]=$checkResult;
226 liveuser 6172
 
3 liveuser 6173
			#回傳結果
6174
			return $result;
226 liveuser 6175
 
3 liveuser 6176
			}#if end
226 liveuser 6177
 
3 liveuser 6178
		#如果 $conf["commentsArray"] 有設定
6179
		if(isset($conf["commentsArray"])){
226 liveuser 6180
 
3 liveuser 6181
			#印出提示文字
6182
			#函式說明:
6183
			#印出多行文字,結尾自動換行.
6184
			#回傳的結果:
6185
			#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
6186
			#$result["function"],當前執行的函數名稱.
6187
			#$result["error"],錯誤訊息陣列.
6188
			#必填參數:
6189
			#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
6190
			$conf["cmd::echoMultiLine"]["outputStringArray"]=$conf["commentsArray"];
6191
			$echoMultiLine=cmd::echoMultiLine($conf["cmd::echoMultiLine"]);
6192
			unset($conf["cmd::echoMultiLine"]);
226 liveuser 6193
 
3 liveuser 6194
			#如果印出提示文字失敗
6195
			if($echoMultiLine["status"]=="false"){
226 liveuser 6196
 
3 liveuser 6197
				#設置執行失敗
6198
				$result["status"]="false";
226 liveuser 6199
 
3 liveuser 6200
				#設置執行錯誤訊息
6201
				$result["error"]=$echoMultiLine;
226 liveuser 6202
 
3 liveuser 6203
				#回傳結果
6204
				return $result;
226 liveuser 6205
 
3 liveuser 6206
				}#if end
226 liveuser 6207
 
6208
			}#if end
6209
 
3 liveuser 6210
		#檢查要移動的檔案是否存在
6211
		#函式說明:
6212
		#檢查多個檔案與資料夾是否存在.
6213
		#回傳的結果:
6214
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
6215
		#$result["error"],錯誤訊息陣列.
6216
		#$resutl["function"],當前執行的涵式名稱.
6217
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
6218
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
6219
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
6220
		#必填參數:
6221
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["from"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
6222
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
6223
		#參考資料來源:
6224
		#http://php.net/manual/en/function.file-exists.php
6225
		#http://php.net/manual/en/control-structures.foreach.php
6226
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
6227
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 6228
 
3 liveuser 6229
		#如果檢查失敗
6230
		if($checkMultiFileExist["status"]=="false"){
226 liveuser 6231
 
3 liveuser 6232
			#設置執行失敗
6233
			$result["status"]="false";
226 liveuser 6234
 
3 liveuser 6235
			#設置執行錯誤訊息
6236
			$result["error"]=$checkMultiFileExist;
226 liveuser 6237
 
3 liveuser 6238
			#回傳結果
6239
			return $result;
226 liveuser 6240
 
6241
			}#if end
6242
 
3 liveuser 6243
		#如果來源檔案不存在
6244
		if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 6245
 
3 liveuser 6246
			#設置執行失敗
6247
			$result["status"]="false";
226 liveuser 6248
 
3 liveuser 6249
			#設置執行錯誤訊息
6250
			$result["error"][]="檔案「".$conf["from"]."」不存在";
226 liveuser 6251
 
3 liveuser 6252
			#回傳結果
6253
			return $result;
226 liveuser 6254
 
3 liveuser 6255
			}#if end
226 liveuser 6256
 
3 liveuser 6257
		#函式說明:
6258
		#呼叫shell執行系統命令,並取得回傳的內容.
6259
		#回傳的結果:
6260
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6261
		#$result["error"],錯誤訊息陣列
6262
		#$result["output"],爲執行完二元碼後的輸出陣列
6263
		#必填的參數
6264
		$conf["external::callShell"]["command"]="mv";#要執行的指令與參數
6265
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"]; #__FILE__的內容
6266
		#可省略參數:
6267
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
6268
		$conf["external::callShell"]["argu"]=array("-v",$conf["from"],$conf["to"]);
6269
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
6270
		#$conf["external::callShell"]["enablePrintDescription"]="true";
6271
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
6272
		#$conf["printDescription"]="";
6273
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"true".
6274
		$conf["external::callShell"]["escapeshellarg"]="true";
6275
		#參考資料:
6276
		#http://php.net/manual/en/function.exec.php
6277
		$callShell=external::callShell($conf["external::callShell"]);
6278
		unset($conf["external::callShell"]);
226 liveuser 6279
 
3 liveuser 6280
		#如果移動檔案失敗
6281
		if($callShell["status"]=="false"){
226 liveuser 6282
 
3 liveuser 6283
			#設置執行失敗
6284
			$result["status"]="false";
226 liveuser 6285
 
3 liveuser 6286
			#設置執行錯誤訊息
6287
			$result["error"]=$callShell;
226 liveuser 6288
 
3 liveuser 6289
			#回傳結果
6290
			return $result;
226 liveuser 6291
 
3 liveuser 6292
			}#if end
226 liveuser 6293
 
3 liveuser 6294
		#執行到這邊代表正常
6295
		$result["status"]="true";
226 liveuser 6296
 
3 liveuser 6297
		#儲存移動後的位置與名稱
6298
		$result["content"]=$conf["to"];
226 liveuser 6299
 
3 liveuser 6300
		#回傳結果
6301
		return $result;
226 liveuser 6302
 
3 liveuser 6303
		}#function mv end
226 liveuser 6304
 
3 liveuser 6305
	/*
6306
	#函式說明:
6307
	#取得目錄底下所有目錄與檔案的樹狀結構.
6308
	#回傳結果:
6309
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6310
	#$result["error"],錯誤訊息陣列.
6311
	#$result["function"],函數名稱.
6312
	#$result["position"],根目錄位置.
6313
	#$result["content"],陣列,檔案目錄的樹狀結構.
6314
	#$result["content"][$i]["name"],根目錄底下第$i+1個檔案或目錄的名稱
6315
	#$result["content"][$i]["folder"],根目錄底下第$i+1個名稱是目錄("true")還是檔案("false").
6316
	#$result["content"][$i]["position"],根目錄底下第$i+1個名稱或目錄的位置.
6317
	#$result["content"][$i]["ownerPerm"],根目錄底下第$i+1個使用者的權限.
6318
	#$result["content"][$i]["groupPerm"],根目錄底下第$i+1個群組使用者的權限.
6319
	#$result["content"][$i]["otherPerm"],根目錄底下第$i+1個其他使用者的權限.
6320
	#$result["content"][$i]["ownerName"],根目錄底下第$i+1個擁有者賬戶.
6321
	#$result["content"][$i]["groupName"],根目錄底下第$i+1個群組擁有者賬戶.
6322
	#$result["content"][$i]["next"][$j]["name"],第$i+1個為目錄的名稱的目錄底下第$j+1個檔案或目錄的名稱
6323
	#$result["content"][$i]["next"][$j]["folder"],第$i+1個為目錄的名稱的目錄底下第$j+1個名稱是目錄("true")還是檔案("false").
6324
	#$result["content"][$i]["next"][$j]["position"],第$i+1個為目錄的名稱的目錄底下第$j+1個名稱或目錄的位置.
6325
	#$result["content"][$i]["next"][$j]["ownerPerm"],第$i+1個為目錄的名稱的目錄底下第$j+1個使用者的權限.
6326
	#$result["content"][$i]["next"][$j]["groupPerm"],第$i+1個為目錄的名稱的目錄底下第$j+1個群組使用者的權限.
6327
	#$result["content"][$i]["next"][$j]["otherPerm"],第$i+1個為目錄的名稱的目錄底下第$j+1個其他使用者的權限.
6328
	#$result["content"][$i]["next"][$j]["ownerName"],第$i+1個為目錄的名稱的目錄底下第$j+1個擁有者賬戶.
6329
	#$result["content"][$i]["next"][$j]["groupName"],第$i+1個為目錄的名稱的目錄底下第$j+1個群組擁有者賬戶.
226 liveuser 6330
	#以此類推...
3 liveuser 6331
	#必填參數:
6332
	#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6333
	$conf["position"]="";
6334
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6335
	$conf["fileArgu"]=__FILE__;
6336
	#可省略參數:
6337
	#無.
6338
	#參考資料:
6339
	#無.
6340
	#備註:
6341
	#無.
6342
	*/
6343
	public static function getListTree(&$conf){
226 liveuser 6344
 
3 liveuser 6345
		#初始化要回傳的結果
6346
		$result=array();
226 liveuser 6347
 
3 liveuser 6348
		#設置當其函數名稱
6349
		$result["function"]=__FUNCTION__;
226 liveuser 6350
 
3 liveuser 6351
		#如果 $conf 不為陣列
6352
		if(gettype($conf)!="array"){
226 liveuser 6353
 
3 liveuser 6354
			#設置執行失敗
6355
			$result["status"]="false";
226 liveuser 6356
 
3 liveuser 6357
			#設置執行錯誤訊息
6358
			$result["error"][]="\$conf變數須為陣列形態";
6359
 
6360
			#如果傳入的參數為 null
6361
			if($conf==null){
226 liveuser 6362
 
3 liveuser 6363
				#設置執行錯誤訊息
6364
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 6365
 
3 liveuser 6366
				}#if end
6367
 
6368
			#回傳結果
6369
			return $result;
226 liveuser 6370
 
3 liveuser 6371
			}#if end
226 liveuser 6372
 
3 liveuser 6373
		#檢查必填參數
6374
		#函式說明:
6375
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
6376
		#回傳的結果:
6377
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6378
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6379
		#$result["function"],當前執行的函式名稱.
6380
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6381
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6382
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6383
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
6384
		#必填寫的參數:
6385
		$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
6386
		$conf["variableCheck.isexistMulti"]["variableCheck"]=array("fileArgu","position");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
6387
		#可以省略的參數:
226 liveuser 6388
		$conf["variableCheck.isexistMulti"]["variableType"]=array("string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
3 liveuser 6389
		$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
6390
		$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
6391
		unset($conf["variableCheck.isexistMulti"]);
226 liveuser 6392
 
3 liveuser 6393
		#如果檢查失敗
6394
		if($checkResult["status"]=="false"){
226 liveuser 6395
 
3 liveuser 6396
			#設置錯誤識別
6397
			$result["status"]="false";
226 liveuser 6398
 
3 liveuser 6399
			#設置錯誤訊息
6400
			$result["error"]=$checkResult;
226 liveuser 6401
 
3 liveuser 6402
			#回傳結果
6403
			return $result;
226 liveuser 6404
 
3 liveuser 6405
			}#if end
226 liveuser 6406
 
3 liveuser 6407
		#如果檢查不通過
6408
		if($checkResult["passed"]=="false"){
226 liveuser 6409
 
3 liveuser 6410
			#設置錯誤識別
6411
			$result["status"]="false";
226 liveuser 6412
 
3 liveuser 6413
			#設置錯誤訊息
6414
			$result["error"]=$checkResult;
226 liveuser 6415
 
3 liveuser 6416
			#回傳結果
6417
			return $result;
226 liveuser 6418
 
3 liveuser 6419
			}#if end
226 liveuser 6420
 
3 liveuser 6421
		#如果目錄不為 . 與 ..
6422
		if(basename($conf["position"])!="." && basename($conf["position"])!=".."){
226 liveuser 6423
 
3 liveuser 6424
			#檢查目錄是否存在
6425
			#函式說明:
6426
			#檢查多個檔案與資料夾是否存在.
6427
			#回傳的結果:
6428
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
6429
			#$result["error"],錯誤訊息陣列.
6430
			#$resutl["function"],當前執行的涵式名稱.
6431
			#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
6432
			#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
6433
			#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
6434
			#必填參數:
6435
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["position"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
6436
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6437
			$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
6438
			#參考資料來源:
6439
			#http://php.net/manual/en/function.file-exists.php
6440
			#http://php.net/manual/en/control-structures.foreach.php
6441
			$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
6442
			unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 6443
 
3 liveuser 6444
			#如果檢查目錄失敗
6445
			if($checkMultiFileExist["status"]=="false"){
226 liveuser 6446
 
3 liveuser 6447
				#設置錯誤識別
6448
				$result["status"]="false";
226 liveuser 6449
 
3 liveuser 6450
				#設置錯誤訊息
6451
				$result["error"]=$checkMultiFileExist;
226 liveuser 6452
 
3 liveuser 6453
				#回傳結果
6454
				return $result;
226 liveuser 6455
 
6456
				}#if end
6457
 
3 liveuser 6458
			#如果目錄不存在
6459
			if($checkMultiFileExist["varExist"][0]=="false"){
226 liveuser 6460
 
3 liveuser 6461
				#設置錯誤識別
6462
				$result["status"]="false";
226 liveuser 6463
 
3 liveuser 6464
				#設置錯誤訊息
6465
				$result["error"]=$checkMultiFileExist;
226 liveuser 6466
 
3 liveuser 6467
				#回傳結果
6468
				return $result;
226 liveuser 6469
 
6470
				}#if end
6471
 
3 liveuser 6472
			}#if end
226 liveuser 6473
 
3 liveuser 6474
		#取得根目錄的樹狀結構
6475
		#函式說明:
6476
		#取得目錄底下所有目錄與檔案清單.
6477
		#回傳結果:
6478
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6479
		#$result["error"],錯誤訊息陣列.
6480
		#$result["function"],函數名稱.
6481
		#$result["content"],陣列,目錄底下的檔案與子目錄.
6482
		#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
6483
		#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
6484
		#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
6485
		#$result["position"],目前的位置.
6486
		#必填參數:
6487
		#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6488
		$conf["fileAccess::getList"]["position"]=$conf["position"];
6489
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6490
		$conf["fileAccess::getList"]["fileArgu"]=$conf["fileArgu"];
6491
		#可省略參數:
6492
		#無
6493
		#參考資料來源:
6494
		#opendir=>http://php.net/manual/en/function.opendir.php
6495
		#is_dir=>http://php.net/manual/en/function.is-dir.php
6496
		$rootList=fileAccess::getList($conf["fileAccess::getList"]);
226 liveuser 6497
		unset($conf["fileAccess::getList"]);
6498
 
3 liveuser 6499
		#如果取得根目錄底下的資料失敗
6500
		if($rootList["status"]=="false"){
226 liveuser 6501
 
3 liveuser 6502
			#設置錯誤識別
6503
			$result["status"]="false";
226 liveuser 6504
 
3 liveuser 6505
			#設置錯誤訊息
6506
			$result["error"]=$rootList;
226 liveuser 6507
 
3 liveuser 6508
			#回傳結果
6509
			return $result;
226 liveuser 6510
 
3 liveuser 6511
			}#if end
226 liveuser 6512
 
6513
		#取得當前目錄
6514
		$result["position"]=$rootList["position"];
6515
 
3 liveuser 6516
		#取得根目錄層級可以看到的檔案與目錄
6517
		$result["content"]=$rootList["content"];
226 liveuser 6518
 
3 liveuser 6519
		#如果當前目錄有檔案與子目錄
6520
		if(isset($result["content"])){
226 liveuser 6521
 
3 liveuser 6522
			#當前層級有幾個檔案目錄就執行幾次
6523
			for($i=0;$i<count($result["content"]);$i++){
226 liveuser 6524
 
3 liveuser 6525
				#如果該單位是目錄
6526
				if($result["content"][$i]["folder"]=="true"){
226 liveuser 6527
 
3 liveuser 6528
					#呼叫當前函數,取得 $conf["position"]."/".$result["content"][$i]["name"] 目錄底下的檔案目錄資訊
6529
					#函式說明:
6530
					#取得目錄底下所有目錄與檔案的樹狀結構.
6531
					#回傳結果:
6532
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6533
					#$result["error"],錯誤訊息陣列.
6534
					#$result["function"],函數名稱.
6535
					#$result["content"],陣列,檔案目錄的樹狀結構.
6536
					#$result["total"],根目錄底下有多少目錄與檔案
6537
					#必填參數:
6538
					#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6539
					$conf["fileAccess::getListTree"]["position"]=$conf["position"]."/".$result["content"][$i]["name"];
6540
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6541
					$conf["fileAccess::getListTree"]["fileArgu"]=$conf["fileArgu"];
6542
					#可省略參數:
6543
					#無
6544
					$getListTree=fileAccess::getListTree($conf["fileAccess::getListTree"]);
6545
					unset($conf["fileAccess::getListTree"]);
226 liveuser 6546
 
3 liveuser 6547
					#如果取得 $conf["position"]."/".$result["content"][$i]["name"] 目錄底下的檔案目錄資訊失敗
6548
					if($getListTree["status"]=="false"){
226 liveuser 6549
 
3 liveuser 6550
						#設置錯誤識別
6551
						$result["status"]="false";
226 liveuser 6552
 
3 liveuser 6553
						#設置錯誤訊息
6554
						$result["error"]=$getListTree;
226 liveuser 6555
 
3 liveuser 6556
						#回傳結果
6557
						return $result;
226 liveuser 6558
 
3 liveuser 6559
						}#if end
226 liveuser 6560
 
3 liveuser 6561
					#如果 $conf["position"]."/".$result["content"][$i]["name"] 目錄有檔案與子目錄
226 liveuser 6562
					if(isset($getListTree["content"])){
6563
 
3 liveuser 6564
						#取得 $conf["position"]."/".$result["content"][$i]["name"] 目錄底下的檔案目錄資訊
6565
						$result["content"][$i]["next"]=$getListTree["content"];
226 liveuser 6566
 
3 liveuser 6567
						}#if end
226 liveuser 6568
 
6569
					#取得當前目錄
6570
					$result["content"][$i]["position"]=$rootList["position"];
6571
 
3 liveuser 6572
					}#if end
226 liveuser 6573
 
3 liveuser 6574
				}#for end
226 liveuser 6575
 
3 liveuser 6576
			}#if end
226 liveuser 6577
 
3 liveuser 6578
		#執行到這邊代表執行正常
6579
		$result["status"]="true";
226 liveuser 6580
 
3 liveuser 6581
		#回傳結果
6582
		return $result;
226 liveuser 6583
 
3 liveuser 6584
		}#function getListTree end
226 liveuser 6585
 
3 liveuser 6586
	/*
6587
	#函式說明:
6588
	#取得目錄底下所有目錄與檔案清單.
6589
	#回傳結果:
6590
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6591
	#$result["error"],錯誤訊息陣列.
6592
	#$result["function"],函數名稱.
6593
	#$result["content"],陣列,目錄底下的檔案與子目錄.
6594
	#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
6595
	#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
6596
	#$result["content"][$i]["ownerPerm"],字串,使用者的權限.
6597
	#$result["content"][$i]["groupPerm"],字串,群組使用者的權限.
6598
	#$result["content"][$i]["otherPerm"],字串,其他使用者的權限.
6599
	#$result["content"][$i]["ownerName"],字串,擁有者賬戶.
6600
	#$result["content"][$i]["groupName"],字串,群組擁有者賬戶.
6601
	#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
6602
	#$result["position"],目前的位置.
6603
	#必填參數:
6604
	#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6605
	$conf["position"]="";
6606
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6607
	$conf["fileArgu"]=__FILE__;
6608
	#可省略參數:
6609
	#無
6610
	#參考資料:
6611
	#opendir=>http://php.net/manual/en/function.opendir.php
6612
	#is_dir=>http://php.net/manual/en/function.is-dir.php
6613
	#備註:
6614
	#無.
6615
	*/
6616
	public static function getList(&$conf){
6617
 
6618
		#初始化要回傳的結果
6619
		$result=array();
226 liveuser 6620
 
3 liveuser 6621
		#設置當其函數名稱
6622
		$result["function"]=__FUNCTION__;
226 liveuser 6623
 
3 liveuser 6624
		#初始化記載檔案目錄名單的陣列
6625
		$result["content"]=array();
226 liveuser 6626
 
3 liveuser 6627
		#如果 $conf 不為陣列
6628
		if(gettype($conf)!="array"){
226 liveuser 6629
 
3 liveuser 6630
			#設置執行失敗
6631
			$result["status"]="false";
226 liveuser 6632
 
3 liveuser 6633
			#設置執行錯誤訊息
6634
			$result["error"][]="\$conf變數須為陣列形態";
6635
 
6636
			#如果傳入的參數為 null
6637
			if($conf==null){
226 liveuser 6638
 
3 liveuser 6639
				#設置執行錯誤訊息
6640
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 6641
 
3 liveuser 6642
				}#if end
6643
 
6644
			#回傳結果
6645
			return $result;
226 liveuser 6646
 
3 liveuser 6647
			}#if end
226 liveuser 6648
 
3 liveuser 6649
		#檢查必填參數
6650
		#函式說明:
6651
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
6652
		#回傳的結果:
6653
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6654
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6655
		#$result["function"],當前執行的函式名稱.
6656
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6657
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6658
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6659
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
6660
		#必填寫的參數:
6661
		$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
6662
		$conf["variableCheck.isexistMulti"]["variableCheck"]=array("fileArgu","position");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
6663
		#可以省略的參數:
226 liveuser 6664
		$conf["variableCheck.isexistMulti"]["variableType"]=array("string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
3 liveuser 6665
		$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
6666
		$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
6667
		unset($conf["variableCheck.isexistMulti"]);
226 liveuser 6668
 
3 liveuser 6669
		#如果檢查失敗
6670
		if($checkResult["status"]=="false"){
226 liveuser 6671
 
3 liveuser 6672
			#設置錯誤識別
6673
			$result["status"]="false";
226 liveuser 6674
 
3 liveuser 6675
			#設置錯誤訊息
6676
			$result["error"]=$checkResult;
226 liveuser 6677
 
3 liveuser 6678
			#回傳結果
6679
			return $result;
226 liveuser 6680
 
3 liveuser 6681
			}#if end
226 liveuser 6682
 
3 liveuser 6683
		#如果檢查不通過
6684
		if($checkResult["passed"]==="false"){
226 liveuser 6685
 
3 liveuser 6686
			#設置錯誤識別
6687
			$result["status"]="false";
226 liveuser 6688
 
3 liveuser 6689
			#設置錯誤訊息
6690
			$result["error"]=$checkResult;
226 liveuser 6691
 
3 liveuser 6692
			#回傳結果
6693
			return $result;
226 liveuser 6694
 
3 liveuser 6695
			}#if end
226 liveuser 6696
 
3 liveuser 6697
		#檢查目標路徑是否為「/」開頭的路徑
6698
		#函式說明:
6699
		#取得符合特定字首與字尾的字串
6700
		#回傳結果:
6701
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
6702
		#$result["function"],當前執行的函數名稱.
6703
		#$result["error"],錯誤訊息陣列.
6704
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
6705
		#$result["returnString"],爲符合字首條件的字串內容。
6706
		#必填參數:
6707
		#$conf["checkString"],字串,要檢查的字串.
6708
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["position"];
6709
		#可省略參數:
6710
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
6711
		$conf["search::getMeetConditionsString"]["frontWord"]="/";
6712
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
6713
		#$conf["tailWord"]="";
6714
		#參考資料:
6715
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
6716
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
6717
		unset($conf["search::getMeetConditionsString"]);
226 liveuser 6718
 
3 liveuser 6719
		#如果檢查關鍵字失敗
6720
		if($getMeetConditionsString["status"]=="false"){
226 liveuser 6721
 
3 liveuser 6722
			#設置錯誤識別
6723
			$result["status"]="false";
226 liveuser 6724
 
3 liveuser 6725
			#設置錯誤訊息
6726
			$result["error"]=$getMeetConditionsString;
226 liveuser 6727
 
3 liveuser 6728
			#回傳結果
6729
			return $result;
226 liveuser 6730
 
6731
			}#if end
6732
 
3 liveuser 6733
		#如果目標路徑不為「/」開頭的路徑,則為相對路徑
6734
		if($getMeetConditionsString["founded"]=="false"){
226 liveuser 6735
 
3 liveuser 6736
			#取得目標位置的路徑
6737
			#函式說明:
6738
			#將檔案的位置名稱變成網址
6739
			#回傳結果:
6740
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6741
			#$result["error"],錯誤訊息陣列.
226 liveuser 6742
			#$result["function"],函數名稱.
3 liveuser 6743
			#$result["content"],網址.
6744
			#$result["localAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
6745
			#$result["fileSystemAbsoulutePosition"],針對伺服器檔案系統的絕對位置.
6746
			#必填參數:
6747
			#$conf["address"],字串,檔案的相對位置.
6748
			$conf["fileAccess::getInternetAddress"]["address"]=$conf["position"];
6749
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
6750
			$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
6751
			#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是.
6752
			#$conf["fileAccess::getInternetAddress"]["userDir"]="true";
6753
			$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
226 liveuser 6754
			unset($conf["fileAccess::getInternetAddress"]);
6755
 
3 liveuser 6756
			#如果將檔案的位置名稱變成網址失敗
6757
			if($getInternetAddress["status"]=="false"){
226 liveuser 6758
 
3 liveuser 6759
				#設置錯誤識別
6760
				$result["status"]="false";
226 liveuser 6761
 
3 liveuser 6762
				#設置錯誤訊息
6763
				$result["error"]=$getInternetAddress;
226 liveuser 6764
 
3 liveuser 6765
				#回傳結果
6766
				return $result;
226 liveuser 6767
 
6768
				}#if end
6769
 
3 liveuser 6770
			#置換目標位置為檔案系統路徑的絕對位置
6771
			$conf["position"]=$getInternetAddress["fileSystemAbsoulutePosition"];
226 liveuser 6772
 
6773
			}#if end
6774
 
6775
		#如果目標是資料夾
3 liveuser 6776
		if(is_dir($conf["position"])) {
226 liveuser 6777
 
3 liveuser 6778
			#設置為資料夾
6779
			$result["folder"]="true";
226 liveuser 6780
 
3 liveuser 6781
			#如果開啟資料夾成功
6782
			if($dh=opendir($conf["position"])){
226 liveuser 6783
 
3 liveuser 6784
				#初始化計數變數
6785
				$count=0;
226 liveuser 6786
 
3 liveuser 6787
				#如果資料夾裡面有檔案
6788
				while(($fileName=readdir($dh))!==false){
226 liveuser 6789
 
3 liveuser 6790
					#debug
6791
					#echo "有檔案";
226 liveuser 6792
 
3 liveuser 6793
					#如果名稱是「.」或「..」
6794
					if($fileName=="." || $fileName==".."){
226 liveuser 6795
 
3 liveuser 6796
						#則跳過
6797
						continue;
226 liveuser 6798
 
3 liveuser 6799
						}#if end
226 liveuser 6800
 
3 liveuser 6801
					#取得檔案或子目錄名稱
226 liveuser 6802
					$result["content"][$count]["name"]=$fileName;
6803
 
3 liveuser 6804
					#取得詳細資訊
6805
					#函式說明:
6806
					#取得節點的資訊.
6807
					#回傳結果:
6808
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6809
					#$result["error"],錯誤訊息陣列.
226 liveuser 6810
					#$result["function"],函數名稱.
3 liveuser 6811
					#$result["content"],檔案資訊陣列.
226 liveuser 6812
					#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
3 liveuser 6813
					#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
6814
					#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
6815
					#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
6816
					#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
6817
					#$result["content"]["ownerName"],檔案擁有着資訊.
6818
					#$result["content"]["groupName"],檔案所屬擁有着資訊.
6819
					#$result["content"]["size"],檔案大小.
6820
					#$result["content"]["modifyDate"],檔案變更年月日.
6821
					#$result["content"]["modifyTime"],檔案變更時分秒.
6822
					#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
6823
					#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
6824
					#必填參數:
6825
					#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
6826
					$conf["fileAccess::fileInfo"]["fileArgu"]=$conf["fileArgu"];
6827
					#$conf["file"],字串,要查看擁有者資訊的檔案.
6828
					$conf["fileAccess::fileInfo"]["file"]=$conf["position"]."/".$fileName;
6829
					#可省略參數:
6830
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
6831
					$conf["fileAccess::fileInfo"]["web"]="false";
6832
					#參考資料:
6833
					#fileowner=>http://php.net/manual/en/function.fileowner.php
6834
					#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
6835
					#備註:
6836
					#無.
6837
					$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
6838
					unset($conf["fileAccess::fileInfo"]);
226 liveuser 6839
 
3 liveuser 6840
					#如果執行失敗
6841
					if($fileInfo["status"]=="false"){
226 liveuser 6842
 
3 liveuser 6843
						#設置錯誤識別
6844
						$result["status"]="false";
226 liveuser 6845
 
3 liveuser 6846
						#設置錯誤訊息
6847
						$result["error"]=$fileInfo;
226 liveuser 6848
 
3 liveuser 6849
						#回傳結果
6850
						return $result;
226 liveuser 6851
 
3 liveuser 6852
						}#if end
226 liveuser 6853
 
3 liveuser 6854
					#設置是否為資料夾
6855
					$result["content"][$count]["folder"]=$fileInfo["content"]["is_folder"];
226 liveuser 6856
 
3 liveuser 6857
					#設置使用者的權限
6858
					$result["content"][$count]["ownerPerm"]=$fileInfo["content"]["ownerPerm"];
226 liveuser 6859
 
3 liveuser 6860
					#設置群組的權限
6861
					$result["content"][$count]["groupPerm"]=$fileInfo["content"]["groupPerm"];
226 liveuser 6862
 
3 liveuser 6863
					#設置其他使用者的權限
6864
					$result["content"][$count]["otherPerm"]=$fileInfo["content"]["otherPerm"];
226 liveuser 6865
 
3 liveuser 6866
					#設置其擁有者賬戶
6867
					$result["content"][$count]["ownerName"]=$fileInfo["content"]["ownerName"];
226 liveuser 6868
 
3 liveuser 6869
					#設置其群組擁有者賬戶
6870
					$result["content"][$count]["groupName"]=$fileInfo["content"]["groupName"];
226 liveuser 6871
 
3 liveuser 6872
					#計數加1
6873
					$count++;
226 liveuser 6874
 
3 liveuser 6875
					}#while
226 liveuser 6876
 
3 liveuser 6877
				#關閉資料夾
6878
				closedir($dh);
226 liveuser 6879
 
3 liveuser 6880
				}#if end
226 liveuser 6881
 
6882
			#開啟資料夾失敗
3 liveuser 6883
			else{
226 liveuser 6884
 
3 liveuser 6885
				#設置執行失敗
6886
				$result["status"]="false";
226 liveuser 6887
 
3 liveuser 6888
				#設置執行錯誤訊息
6889
				$result["error"][]="開啟資料夾「".$conf["position"]."」失敗";
6890
 
6891
				#回傳結果
6892
				return $result;
226 liveuser 6893
 
3 liveuser 6894
				}#else end
226 liveuser 6895
 
3 liveuser 6896
			}#if end
226 liveuser 6897
 
3 liveuser 6898
		#反之是檔案
6899
		else{
226 liveuser 6900
 
3 liveuser 6901
			#設置不為目錄
6902
			$result["folder"]="false";
226 liveuser 6903
 
3 liveuser 6904
			}#else end
226 liveuser 6905
 
3 liveuser 6906
		#取得目前位置
226 liveuser 6907
		$result["position"]=$conf["position"];
6908
 
3 liveuser 6909
		#執行到這邊代表執行正常
6910
		$result["status"]="true";
226 liveuser 6911
 
3 liveuser 6912
		#回傳結果
226 liveuser 6913
		return $result;
3 liveuser 6914
 
6915
		}#function getList end
226 liveuser 6916
 
3 liveuser 6917
	/*
6918
	#函式說明:
6919
	#取得目錄底下所有目錄與檔案的樹狀結構.
6920
	#回傳結果:
6921
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6922
	#$result["error"],錯誤訊息陣列.
6923
	#$result["function"],函數名稱.
6924
	#$result["content"],陣列,檔案目錄的樹狀結構.
6925
	#必填參數:
6926
	#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
6927
	$conf["position"]="";
6928
	#可省略參數:
6929
	#無.
6930
	#參考資料:
6931
	#無.
6932
	#備註:
6933
	#無.
6934
	*/
6935
	public static function exportListTree(&$conf){
226 liveuser 6936
 
3 liveuser 6937
		#初始化要回傳的結果
6938
		$result=array();
226 liveuser 6939
 
3 liveuser 6940
		#設置當其函數名稱
6941
		$result["function"]=__FUNCTION__;
226 liveuser 6942
 
3 liveuser 6943
		#如果 $conf 不為陣列
6944
		if(gettype($conf)!="array"){
226 liveuser 6945
 
3 liveuser 6946
			#設置執行失敗
6947
			$result["status"]="false";
226 liveuser 6948
 
3 liveuser 6949
			#設置執行錯誤訊息
6950
			$result["error"][]="\$conf變數須為陣列形態";
6951
 
6952
			#如果傳入的參數為 null
6953
			if($conf==null){
226 liveuser 6954
 
3 liveuser 6955
				#設置執行錯誤訊息
6956
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 6957
 
3 liveuser 6958
				}#if end
6959
 
6960
			#回傳結果
6961
			return $result;
226 liveuser 6962
 
3 liveuser 6963
			}#if end
226 liveuser 6964
 
3 liveuser 6965
		#檢查必填參數
6966
		#函式說明:
6967
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
6968
		#回傳的結果:
6969
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6970
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6971
		#$result["function"],當前執行的函式名稱.
6972
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6973
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6974
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6975
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
6976
		#必填寫的參數:
6977
		$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
6978
		$conf["variableCheck.isexistMulti"]["variableCheck"]=array("position");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
6979
		#可以省略的參數:
226 liveuser 6980
		$conf["variableCheck.isexistMulti"]["variableType"]=array("string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
3 liveuser 6981
		$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
6982
		$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
6983
		unset($conf["variableCheck.isexistMulti"]);
226 liveuser 6984
 
3 liveuser 6985
		#如果檢查失敗
6986
		if($checkResult["status"]=="false"){
226 liveuser 6987
 
3 liveuser 6988
			#設置錯誤識別
6989
			$result["status"]="false";
226 liveuser 6990
 
3 liveuser 6991
			#設置錯誤訊息
6992
			$result["error"]=$checkResult;
226 liveuser 6993
 
3 liveuser 6994
			#回傳結果
6995
			return $result;
226 liveuser 6996
 
3 liveuser 6997
			}#if end
226 liveuser 6998
 
3 liveuser 6999
		#如果檢查不通過
7000
		if($checkResult["passed"]=="false"){
226 liveuser 7001
 
3 liveuser 7002
			#設置錯誤識別
7003
			$result["status"]="false";
226 liveuser 7004
 
3 liveuser 7005
			#設置錯誤訊息
7006
			$result["error"]=$checkResult;
226 liveuser 7007
 
3 liveuser 7008
			#回傳結果
7009
			return $result;
226 liveuser 7010
 
3 liveuser 7011
			}#if end
226 liveuser 7012
 
3 liveuser 7013
		#函式說明:
7014
		#取得目錄底下所有目錄與檔案的樹狀結構.
7015
		#回傳結果:
7016
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
7017
		#$result["error"],錯誤訊息陣列.
7018
		#$result["function"],函數名稱.
7019
		#$result["content"],陣列,檔案目錄的樹狀結構.
7020
		#必填參數:
7021
		#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
7022
		$conf["fileAccess::getListTree"]["position"]=$conf["position"];
7023
		#可省略參數:
7024
		#無
7025
		#備註:
226 liveuser 7026
		#若檔案與目錄的名稱含有「[」與「]」與「(」與「)」將會無法取得其目錄底下的內容
3 liveuser 7027
		#若檔案與目錄的名稱含有「 」將會無法檢查檔案是否存在
7028
		#改用opendir()函數應該可以解決大部分的bug.
7029
		$getListTree=fileAccess::getListTree($conf["fileAccess::getListTree"]);
7030
		unset($conf["fileAccess::getListTree"]);
226 liveuser 7031
 
3 liveuser 7032
		#如果取得 目標目錄底下所有目錄與檔案的樹狀結構 失敗
7033
		if($getListTree["status"]==="false"){
226 liveuser 7034
 
3 liveuser 7035
			#設置錯誤識別
7036
			$result["status"]="false";
226 liveuser 7037
 
3 liveuser 7038
			#設置錯誤訊息
7039
			$result["error"]=$getListTree;
226 liveuser 7040
 
3 liveuser 7041
			#回傳結果
7042
			return $result;
226 liveuser 7043
 
3 liveuser 7044
			}#if end
226 liveuser 7045
 
3 liveuser 7046
		#目標目錄底下有幾個
226 liveuser 7047
 
3 liveuser 7048
		}#function exportListTree end
7049
 
7050
	/*
7051
	#函式說明:
7052
	#解壓縮tar.xz檔案,解壓縮完畢後,tar.xz檔案會被移除.
7053
	#回傳結果:
7054
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
7055
	#$result["error"],錯誤訊息陣列.
226 liveuser 7056
	#$result["function"],函數名稱.
3 liveuser 7057
	#必填參數:
7058
	#$conf["tarXzFile"],字串變數,壓縮檔的位置與名稱,副檔名".tar.xz"會自動補上.
7059
	$conf["tarXzFile"]="";
7060
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
7061
	$conf["fileArgu"]=__FILE__;
7062
	#可省略參數:
7063
	#$conf["extractTo"],字串,要解壓縮到哪邊,預設為當前路徑"."
7064
	#$conf["extractTo"]=".";
7065
	#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
7066
	#$conf["commentsArray"]=array("");
7067
	#參考資料:
7068
	#無.
7069
	#備註:
7070
	#無.
7071
	*/
7072
	public static function unpackTarXzFile(&$conf){
226 liveuser 7073
 
3 liveuser 7074
		#初始化要回傳的內容
7075
		$result=array();
226 liveuser 7076
 
3 liveuser 7077
		#記錄當前執行的函數名稱
7078
		$result["function"]=__FUNCTION__;
226 liveuser 7079
 
3 liveuser 7080
		#如果 $conf 不為陣列
7081
		if(gettype($conf)!="array"){
226 liveuser 7082
 
3 liveuser 7083
			#設置執行失敗
7084
			$result["status"]="false";
226 liveuser 7085
 
3 liveuser 7086
			#設置執行錯誤訊息
7087
			$result["error"][]="\$conf變數須為陣列形態";
7088
 
7089
			#如果傳入的參數為 null
7090
			if($conf==null){
226 liveuser 7091
 
3 liveuser 7092
				#設置執行錯誤訊息
7093
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 7094
 
3 liveuser 7095
				}#if end
7096
 
7097
			#回傳結果
7098
			return $result;
226 liveuser 7099
 
3 liveuser 7100
			}#if end
226 liveuser 7101
 
3 liveuser 7102
		#檢查參數
7103
		#函式說明:
7104
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7105
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7106
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7107
		#$result["function"],當前執行的函式名稱.
7108
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7109
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7110
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7111
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
7112
		#必填寫的參數:
7113
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7114
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7115
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7116
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","tarXzFile");
226 liveuser 7117
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 7118
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
7119
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7120
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7121
		#可以省略的參數:
7122
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
7123
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7124
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7125
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("commentsArray","extractTo");
226 liveuser 7126
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 7127
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string");
7128
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7129
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,".");
7130
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7131
		#$conf["arrayCountEqualCheck"][]=array();
7132
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7133
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 7134
 
3 liveuser 7135
		#若檢查失敗
7136
		if($checkResult["status"]=="false"){
226 liveuser 7137
 
3 liveuser 7138
			#設置執行失敗
7139
			$result["status"]="false";
226 liveuser 7140
 
3 liveuser 7141
			#設置執行錯誤訊息
7142
			$result["error"]=$checkResult;
226 liveuser 7143
 
3 liveuser 7144
			#回傳結果
7145
			return $result;
226 liveuser 7146
 
3 liveuser 7147
			}#if end
226 liveuser 7148
 
3 liveuser 7149
		#若檢查不通過
7150
		if($checkResult["passed"]=="false"){
226 liveuser 7151
 
3 liveuser 7152
			#設置執行失敗
7153
			$result["status"]="false";
226 liveuser 7154
 
3 liveuser 7155
			#設置執行錯誤訊息
7156
			$result["error"]=$checkResult;
226 liveuser 7157
 
3 liveuser 7158
			#回傳結果
7159
			return $result;
226 liveuser 7160
 
3 liveuser 7161
			}#if end
226 liveuser 7162
 
3 liveuser 7163
		#如果 $conf["commentsArray"] 有設定
7164
		if(isset($conf["commentsArray"])){
226 liveuser 7165
 
3 liveuser 7166
			#印出提示文字
7167
			#函式說明:
7168
			#印出多行文字,結尾自動換行.
7169
			#回傳的結果:
7170
			#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
7171
			#$result["function"],當前執行的函數名稱.
7172
			#$result["error"],錯誤訊息陣列.
7173
			#必填參數:
7174
			#$conf["outputStringArray"],字串陣列,每行要印出的文字內容.
7175
			$conf["cmd::echoMultiLine"]["outputStringArray"]=$conf["commentsArray"];
7176
			$echoMultiLine=cmd::echoMultiLine($conf["cmd::echoMultiLine"]);
7177
			unset($conf["cmd::echoMultiLine"]);
226 liveuser 7178
 
3 liveuser 7179
			#如果印出提示文字失敗
7180
			if($echoMultiLine["status"]=="false"){
226 liveuser 7181
 
3 liveuser 7182
				#設置執行失敗
7183
				$result["status"]="false";
226 liveuser 7184
 
3 liveuser 7185
				#設置執行錯誤訊息
7186
				$result["error"]=$echoMultiLine;
226 liveuser 7187
 
3 liveuser 7188
				#回傳結果
7189
				return $result;
226 liveuser 7190
 
3 liveuser 7191
				}#if end
226 liveuser 7192
 
3 liveuser 7193
			}#if end
226 liveuser 7194
 
3 liveuser 7195
		#檢查要移動的檔案是否存在
7196
		#函式說明:
7197
		#檢查多個檔案與資料夾是否存在.
7198
		#回傳的結果:
7199
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
7200
		#$result["error"],錯誤訊息陣列.
7201
		#$resutl["function"],當前執行的涵式名稱.
7202
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
7203
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
7204
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
7205
		#必填參數:
7206
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["tarXzFile"].".tar.xz");#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
7207
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
7208
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
7209
		#參考資料來源:
7210
		#http://php.net/manual/en/function.file-exists.php
7211
		#http://php.net/manual/en/control-structures.foreach.php
7212
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
7213
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 7214
 
3 liveuser 7215
		#如果檢查失敗
7216
		if($checkMultiFileExist["status"]=="false"){
226 liveuser 7217
 
3 liveuser 7218
			#設置執行失敗
7219
			$result["status"]="false";
226 liveuser 7220
 
3 liveuser 7221
			#設置執行錯誤訊息
7222
			$result["error"]=$checkMultiFileExist;
226 liveuser 7223
 
3 liveuser 7224
			#回傳結果
7225
			return $result;
226 liveuser 7226
 
7227
			}#if end
7228
 
3 liveuser 7229
		#如果來源檔案不存在
7230
		if($checkMultiFileExist["allExist"]=="false"){
226 liveuser 7231
 
3 liveuser 7232
			#設置執行失敗
7233
			$result["status"]="false";
226 liveuser 7234
 
3 liveuser 7235
			#設置執行錯誤訊息
7236
			$result["error"][]="檔案「".$conf["tarXzFile"].".tar.xz」不存在";
226 liveuser 7237
 
3 liveuser 7238
			#回傳結果
7239
			return $result;
226 liveuser 7240
 
3 liveuser 7241
			}#if end
226 liveuser 7242
 
3 liveuser 7243
		#進行解壓縮xz檔
7244
		#函式說明:
7245
		#呼叫shell執行系統命令,並取得回傳的內容.
7246
		#回傳的結果:
7247
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7248
		#$result["error"],錯誤訊息陣列.
7249
		#$result["function"],當前執行的函數名稱.
7250
		#$result["cmd"],執行的指令內容.
7251
		#$result["output"],爲執行完二元碼後的輸出陣列.
7252
		#必填的參數
7253
		#$conf["command"],字串,要執行的指令與.
7254
		$conf["fileAccess::callShell"]["command"]="xz -v -v -d -f ".$conf["tarXzFile"].".tar.xz";
7255
		#可省略參數:
7256
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
7257
		#$conf["fileAccess::callShell"]["argu"]=array();
7258
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
7259
		#$conf["enablePrintDescription"]="true";
7260
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
7261
		#$conf["printDescription"]="";
7262
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"true".
7263
		#$conf["escapeshellarg"]="true";
7264
		#備註:
7265
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
7266
		#參考資料:
7267
		#exec=>http://php.net/manual/en/function.exec.php
7268
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
7269
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
7270
		$callShell=external::callShell($conf["fileAccess::callShell"]);
7271
		unset($conf["fileAccess::callShell"]);
226 liveuser 7272
 
3 liveuser 7273
		#如果解壓縮xz檔案失敗
7274
		if($callShell["status"]=="false"){
226 liveuser 7275
 
3 liveuser 7276
			#設置執行失敗
7277
			$result["status"]="false";
226 liveuser 7278
 
3 liveuser 7279
			#設置執行錯誤訊息
7280
			$result["error"]=$callShell;
226 liveuser 7281
 
3 liveuser 7282
			#回傳結果
7283
			return $result;
226 liveuser 7284
 
3 liveuser 7285
			}#if end
226 liveuser 7286
 
3 liveuser 7287
		#解壓縮tar檔
7288
		#函式說明:
7289
		#呼叫shell執行系統命令,並取得回傳的內容.
7290
		#回傳的結果:
7291
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7292
		#$result["error"],錯誤訊息陣列.
7293
		#$result["function"],當前執行的函數名稱.
7294
		#$result["cmd"],執行的指令內容.
7295
		#$result["output"],爲執行完二元碼後的輸出陣列.
7296
		#必填的參數
7297
		#$conf["command"],字串,要執行的指令與.
7298
		$conf["fileAccess::callShell"]["command"]="tar";
7299
		#可省略參數:
7300
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
7301
		$conf["fileAccess::callShell"]["argu"]=array("-xvf",$conf["tarXzFile"]."tar",$conf["extractTo"]);
7302
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
7303
		#$conf["enablePrintDescription"]="true";
7304
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
7305
		#$conf["printDescription"]="";
7306
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"true".
7307
		$conf["fileAccess::callShell"]["escapeshellarg"]="true";
7308
		#備註:
7309
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
7310
		#參考資料:
7311
		#exec=>http://php.net/manual/en/function.exec.php
7312
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
7313
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
7314
		$callShell=external::callShell($conf["fileAccess::callShell"]);
7315
		unset($conf["fileAccess::callShell"]);
226 liveuser 7316
 
3 liveuser 7317
		#如果解壓縮xz檔案失敗
7318
		if($callShell["status"]=="false"){
226 liveuser 7319
 
3 liveuser 7320
			#設置執行失敗
7321
			$result["status"]="false";
226 liveuser 7322
 
3 liveuser 7323
			#設置執行錯誤訊息
7324
			$result["error"]=$callShell;
226 liveuser 7325
 
3 liveuser 7326
			#回傳結果
7327
			return $result;
226 liveuser 7328
 
3 liveuser 7329
			}#if end
226 liveuser 7330
 
3 liveuser 7331
		#移除tar檔
7332
		#函式說明:
7333
		#移除檔案
7334
		#回傳結果:
7335
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
7336
		#$result["error"],錯誤訊息陣列
7337
		#$result["warning"],警告訊息陣列
7338
		#$result["function"],當前執行的函數名稱
7339
		#必填參數:
7340
		$conf["fileAccess::delFile"]["fileAddress"]=$conf["tarXzFile"].".tar";#要移除檔案的位置
7341
		#可省略參數:
7342
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
7343
		$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
7344
		#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
7345
		#$conf["commentsArray"]=array("");
7346
		$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
226 liveuser 7347
		unset($conf["fileAccess::delFile"]);
7348
 
3 liveuser 7349
		#如果移除檔案失敗
7350
		if($delFile["status"]=="false"){
226 liveuser 7351
 
3 liveuser 7352
			#設置執行失敗
7353
			$result["status"]="false";
226 liveuser 7354
 
3 liveuser 7355
			#設置執行錯誤訊息
7356
			$result["error"]=$delFile;
226 liveuser 7357
 
3 liveuser 7358
			#回傳結果
7359
			return $result;
226 liveuser 7360
 
7361
			}#if end
7362
 
3 liveuser 7363
		#執行到這邊代表執行正常
7364
		$result["status"]="true";
226 liveuser 7365
 
3 liveuser 7366
		#回傳結果
7367
		return $result;
226 liveuser 7368
 
3 liveuser 7369
		}#function unpackTarXzFile end
7370
 
7371
	/*
7372
	#函式說明:
7373
	#用data:mimeType;base64,fileVar的形式來提供檔案的連結,亦即檔案儲存在變數裡面.
7374
	#回傳結果:
7375
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7376
	#$result["error"],錯誤訊息
7377
	#$result["content"],檔案變數的內容
7378
	#$result["fileTypeName"],副檔名,ex:「.tar.xz」.
226 liveuser 7379
	#$result["function"],當前執行的函數名稱
3 liveuser 7380
	#必填參數:
7381
	#$conf["filePosition"],要轉存成2元碼的檔案位置與名稱
7382
	$conf["filePosition"]="";
7383
	#$conf["mimeType"],2元碼的內容是什麼
7384
	$conf["mimeType"]="";
7385
	#可省略參數:
7386
	#$conf["compressType"],2元碼壓縮的方式,預設為"base64".
7387
	#$conf["compressType"]="base64";
7388
	#$conf["delFile"],讀取完檔案後,要移除檔案嗎?"true"代表要移除,"false"代表不要移除,預設為"false".
7389
	#$conf["delFile"]="false";
7390
	#參考資料:
7391
	#將檔案用字串變數儲存起來=>http://php.net/manual/en/function.file-get-contents.php
7392
	#壓縮2元碼=>http://php.net/manual/en/function.base64-encode.php
7393
	#備註:
7394
	#無.
7395
	*/
7396
	public static function data(&$conf){
226 liveuser 7397
 
3 liveuser 7398
		#初始化要回傳的內容
7399
		$result=array();
226 liveuser 7400
 
3 liveuser 7401
		#取得當前執行的函數名稱
7402
		$result["function"]=__FUNCTION__;
226 liveuser 7403
 
3 liveuser 7404
		#如果 $conf 不為陣列
7405
		if(gettype($conf)!="array"){
226 liveuser 7406
 
3 liveuser 7407
			#設置執行失敗
7408
			$result["status"]="false";
226 liveuser 7409
 
3 liveuser 7410
			#設置執行錯誤訊息
7411
			$result["error"][]="\$conf變數須為陣列形態";
7412
 
7413
			#如果傳入的參數為 null
7414
			if($conf==null){
226 liveuser 7415
 
3 liveuser 7416
				#設置執行錯誤訊息
7417
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 7418
 
3 liveuser 7419
				}#if end
7420
 
7421
			#回傳結果
7422
			return $result;
226 liveuser 7423
 
3 liveuser 7424
			}#if end
226 liveuser 7425
 
3 liveuser 7426
		#檢查參數
7427
		#函式說明:
7428
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7429
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7430
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7431
		#$result["function"],當前執行的函式名稱.
7432
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7433
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7434
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7435
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
7436
		#必填寫的參數:
7437
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7438
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7439
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7440
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePosition");
226 liveuser 7441
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 7442
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
7443
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7444
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7445
		#可以省略的參數:
7446
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
7447
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7448
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7449
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mimeType","compressType","delFile");
226 liveuser 7450
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 7451
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
7452
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,「null」代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7453
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("null","base64","false");
7454
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7455
		#$conf["arrayCountEqualCheck"][]=array();
7456
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7457
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 7458
 
3 liveuser 7459
		#如果檢查參數失敗
7460
		if($checkResult["status"]=="false"){
226 liveuser 7461
 
3 liveuser 7462
			#設置執行失敗
7463
			$result["status"]="false";
226 liveuser 7464
 
3 liveuser 7465
			#設置錯誤訊息
7466
			$result["error"]=$checkResult;
226 liveuser 7467
 
3 liveuser 7468
			#回傳結果
7469
			return $result;
226 liveuser 7470
 
3 liveuser 7471
			}#if end
226 liveuser 7472
 
3 liveuser 7473
		#如果檢查參數不通過
7474
		if($checkResult["passed"]=="false"){
226 liveuser 7475
 
3 liveuser 7476
			#設置執行失敗
7477
			$result["status"]="false";
226 liveuser 7478
 
3 liveuser 7479
			#設置錯誤訊息
7480
			$result["error"]=$checkResult;
226 liveuser 7481
 
3 liveuser 7482
			#回傳結果
7483
			return $result;
226 liveuser 7484
 
3 liveuser 7485
			}#if end
226 liveuser 7486
 
3 liveuser 7487
		#依據檔案名稱取得副檔名 $result["fileTypeName"]
7488
		#函式說明:
7489
		#將固定格式的字串分開,並回傳分開的結果。
7490
		#回傳的參數:
7491
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7492
		#$result["error"],錯誤訊息陣列
7493
		#$result["function"],當前執行的函數名稱.
7494
		#$result["oriStr"],要分割的原始字串內容
7495
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7496
		#$result["dataCounts"],爲總共分成幾段
7497
		#必填參數:
7498
		$conf["stringProcess::spiltString"]["stringIn"]=basename($conf["filePosition"]);#要處理的字串。
7499
		$conf["stringProcess::spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
7500
		#備註:
7501
		#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
7502
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
7503
		unset($conf["stringProcess::spiltString"]);
226 liveuser 7504
 
3 liveuser 7505
		#如果分割字串失敗
7506
		if($spiltString["status"]=="false"){
226 liveuser 7507
 
3 liveuser 7508
			#設置執行失敗
7509
			$result["status"]="false";
226 liveuser 7510
 
3 liveuser 7511
			#設置錯誤訊息
7512
			$result["error"]=$spiltString;
226 liveuser 7513
 
3 liveuser 7514
			#回傳結果
7515
			return $result;
226 liveuser 7516
 
3 liveuser 7517
			}#if end
226 liveuser 7518
 
3 liveuser 7519
		#初始化副檔名
226 liveuser 7520
		$result["fileTypeName"]="";
7521
 
3 liveuser 7522
		#如果只有一段代表沒有副檔名
7523
		if($spiltString["dataCounts"]==1){
226 liveuser 7524
 
3 liveuser 7525
			#副檔名設置為 "unknow"
7526
			$result["fileTypeName"]="unknow";
226 liveuser 7527
 
3 liveuser 7528
			}#if end
226 liveuser 7529
 
3 liveuser 7530
		#不符合以上條件,但至少有兩段
7531
		else if($spiltString["dataCounts"]>=2){
226 liveuser 7532
 
3 liveuser 7533
			#執行 $spiltString["dataCounts"] 減一次的迴圈
7534
			for($i=1;$i<$spiltString["dataCounts"];$i++){
226 liveuser 7535
 
3 liveuser 7536
				#串接副檔名
7537
				$result["fileTypeName"]=$result["fileTypeName"].".".$spiltString["dataArray"][$i];
226 liveuser 7538
 
3 liveuser 7539
				}#for end
226 liveuser 7540
 
3 liveuser 7541
			}#if end
226 liveuser 7542
 
3 liveuser 7543
		#讀取檔案內容
7544
		$fileBin=file_get_contents($conf["filePosition"],"rb");
226 liveuser 7545
 
3 liveuser 7546
		#編碼檔案
7547
		$base64fileBin=base64_encode($fileBin);
226 liveuser 7548
 
3 liveuser 7549
		#如果 $conf["delFile"] 等於 "true"
7550
		if($conf["delFile"]=="true"){
226 liveuser 7551
 
3 liveuser 7552
			#移除檔案
7553
			#函式說明:
7554
			#移除檔案
7555
			#回傳結果:
7556
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
7557
			#$result["error"],錯誤訊息陣列
7558
			#$result["warning"],警告訊息陣列
7559
			#$result["function"],當前執行的函數名稱
7560
			#必填參數:
7561
			$conf["fileAccess::delFile"]["fileAddress"]=$conf["filePosition"];#要移除檔案的位置
7562
			$del=fileAccess::delFile($conf["fileAccess::delFile"]);
7563
			unset($conf["fileAccess::delFile"]);
226 liveuser 7564
 
3 liveuser 7565
			#如果移除圖片失敗
7566
			if($del["status"]=="false"){
226 liveuser 7567
 
3 liveuser 7568
				#設置執行失敗
7569
				$result["status"]="false";
226 liveuser 7570
 
3 liveuser 7571
				#設置錯誤訊息
7572
				$result["error"]=$del;
226 liveuser 7573
 
3 liveuser 7574
				#回傳結果
7575
				return $result;
226 liveuser 7576
 
3 liveuser 7577
				}#if end
226 liveuser 7578
 
3 liveuser 7579
			}#if end
226 liveuser 7580
 
3 liveuser 7581
		#放置檔案的語法
7582
		$result["content"]="data:".$conf["mimeType"].";".$conf["compressType"].",".$base64fileBin;
226 liveuser 7583
 
3 liveuser 7584
		#執行到這邊代表執行正常
7585
		$result["status"]="true";
226 liveuser 7586
 
3 liveuser 7587
		#回傳結果
7588
		return $result;
226 liveuser 7589
 
3 liveuser 7590
		}#function data end
7591
 
7592
	/*
7593
	#函式說明:
7594
	#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
7595
	#回傳結果:
7596
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
7597
	#$result["error"],錯誤訊息陣列.
226 liveuser 7598
	#$result["function"],函數名稱.
3 liveuser 7599
	#$result["argu"],使用的參數.
7600
	#$result["content"],網址,若是在命令列執行,則為"null".
7601
	#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
7602
	#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
7603
	#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
7604
	#必填參數:
7605
	#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
7606
	$conf["address"]="";
7607
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
7608
	$conf["fileArgu"]=__FILE__;
7609
	#可省略參數:
7610
	#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
7611
	#$conf["userDir"]="true";
7612
	#參考資料:
7613
	#無.
7614
	#備註:
7615
	#無.
7616
	*/
7617
	public static function getInternetAddress(&$conf){
226 liveuser 7618
 
3 liveuser 7619
		#初始化要回傳的變數
7620
		$result=array();
226 liveuser 7621
 
3 liveuser 7622
		#記錄當前執行的函數名稱
7623
		$result["function"]=__FUNCTION__;
226 liveuser 7624
 
3 liveuser 7625
		#如果 $conf 不為陣列
7626
		if(gettype($conf)!="array"){
226 liveuser 7627
 
3 liveuser 7628
			#設置執行失敗
7629
			$result["status"]="false";
226 liveuser 7630
 
3 liveuser 7631
			#設置執行錯誤訊息
7632
			$result["error"][]="\$conf變數須為陣列形態";
7633
 
7634
			#如果傳入的參數為 null
7635
			if($conf==null){
226 liveuser 7636
 
3 liveuser 7637
				#設置執行錯誤訊息
7638
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 7639
 
3 liveuser 7640
				}#if end
7641
 
7642
			#回傳結果
7643
			return $result;
226 liveuser 7644
 
3 liveuser 7645
			}#if end
7646
 
7647
		#取得使用的參數
7648
		$result["argu"]=$conf;
226 liveuser 7649
 
3 liveuser 7650
		#檢查參數
7651
		#函式說明:
7652
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
7653
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7654
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7655
		#$result["function"],當前執行的函式名稱.
7656
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7657
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7658
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7659
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
7660
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7661
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7662
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7663
		#必填寫的參數:
7664
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7665
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7666
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7667
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("address","fileArgu");
226 liveuser 7668
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 7669
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
7670
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7671
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7672
		#可以省略的參數:
7673
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
7674
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7675
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7676
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("userDir");
226 liveuser 7677
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 7678
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
7679
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7680
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
7681
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7682
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
7683
		#參考資料來源:
7684
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7685
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7686
		unset($conf["variableCheck::checkArguments"]);
7687
 
7688
		#如果檢查失敗
7689
		if($checkResult["status"]==="false"){
226 liveuser 7690
 
3 liveuser 7691
			#設置錯誤狀態
7692
			$result["status"]="false";
226 liveuser 7693
 
3 liveuser 7694
			#設置錯誤提示
7695
			$result["error"]=$checkResult;
226 liveuser 7696
 
3 liveuser 7697
			#回傳結果
7698
			return $result;
226 liveuser 7699
 
3 liveuser 7700
			}#if end
7701
 
7702
		#如果檢查不通過
7703
		if($checkResult["passed"]==="false"){
226 liveuser 7704
 
3 liveuser 7705
			#設置錯誤狀態
7706
			$result["status"]="false";
226 liveuser 7707
 
3 liveuser 7708
			#設置錯誤提示
7709
			$result["error"]=$checkResult;
226 liveuser 7710
 
3 liveuser 7711
			#回傳結果
7712
			return $result;
226 liveuser 7713
 
3 liveuser 7714
			}#if end
226 liveuser 7715
 
3 liveuser 7716
		#如果是本來就是網址了
7717
		if(strpos($conf["address"],'https://')===0 || strpos($conf["address"],'http://')===0){
226 liveuser 7718
 
3 liveuser 7719
			#設置執行正常
7720
			$result["status"]="true";
226 liveuser 7721
 
3 liveuser 7722
			#取得網址
7723
			$result["content"]=$conf["address"];
226 liveuser 7724
 
3 liveuser 7725
			#回傳結果
226 liveuser 7726
			return $result;
7727
 
7728
			}#if end
7729
 
3 liveuser 7730
		#解析 $conf["fileArgu"]
7731
		#函式說明:
7732
		#將固定格式的字串分開,並回傳分開的結果。
7733
		#回傳的參數:
7734
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7735
		#$result["error"],錯誤訊息陣列
7736
		#$result["function"],當前執行的函數名稱.
7737
		#$result["oriStr"],要分割的原始字串內容
7738
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7739
		#$result["dataCounts"],爲總共分成幾段
7740
		#必填參數:
7741
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["fileArgu"];#要處理的字串。
7742
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
7743
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 7744
		unset($conf["stringProcess::spiltString"]);
7745
 
3 liveuser 7746
		#如果分割字串失敗
7747
		if($spiltString["status"]==="false"){
226 liveuser 7748
 
3 liveuser 7749
			#設置錯誤狀態
7750
			$result["status"]="false";
226 liveuser 7751
 
3 liveuser 7752
			#設置錯誤提示
7753
			$result["error"]=$spiltString;
226 liveuser 7754
 
3 liveuser 7755
			#回傳結果
7756
			return $result;
226 liveuser 7757
 
3 liveuser 7758
			}#if end
226 liveuser 7759
 
3 liveuser 7760
		#函式說明:
7761
		#將多個路徑字串變成相對於當前路徑的相對路徑字串
7762
		#回傳結果:
7763
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
7764
		#$result["error"],錯誤訊息陣列.
226 liveuser 7765
		#$result["function"],函數名稱.
3 liveuser 7766
		#$result["content"],字串陣列,多個轉換好的相對路徑字串.
7767
		#必填參數:
7768
		#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
7769
		$conf["fileAccess::getRelativePath"]["path"]=array($conf["address"]);
7770
		#$conf["fileArgu"],字串,當前路徑.
7771
		$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
7772
		$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
7773
		unset($conf["fileAccess::getRelativePath"]);
226 liveuser 7774
 
3 liveuser 7775
		#如果取得相對位置失敗
7776
		if($getRelativePath["status"]==="false"){
226 liveuser 7777
 
3 liveuser 7778
			#設置錯誤狀態
7779
			$result["status"]="false";
226 liveuser 7780
 
3 liveuser 7781
			#設置錯誤提示
7782
			$result["error"]=$getRelativePath;
226 liveuser 7783
 
3 liveuser 7784
			#回傳結果
7785
			return $result;
226 liveuser 7786
 
7787
			}#if end
7788
 
3 liveuser 7789
		#取得轉換成相對路徑的位置
7790
		$result["fileSystemRelativePosition"]=$getRelativePath["content"][0];
226 liveuser 7791
 
3 liveuser 7792
		#解析 $conf["fileArgu"]
7793
		#函式說明:
7794
		#將固定格式的字串分開,並回傳分開的結果。
7795
		#回傳的參數:
7796
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7797
		#$result["error"],錯誤訊息陣列
7798
		#$result["function"],當前執行的函數名稱.
7799
		#$result["oriStr"],要分割的原始字串內容
7800
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7801
		#$result["dataCounts"],爲總共分成幾段
7802
		#必填參數:
7803
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["fileArgu"];#要處理的字串。
7804
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
7805
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 7806
		unset($conf["stringProcess::spiltString"]);
7807
 
3 liveuser 7808
		#如果分割字串失敗
7809
		if($spiltString["status"]==="false"){
226 liveuser 7810
 
3 liveuser 7811
			#設置錯誤狀態
7812
			$result["status"]="false";
226 liveuser 7813
 
3 liveuser 7814
			#設置錯誤提示
7815
			$result["error"]=$spiltString;
226 liveuser 7816
 
3 liveuser 7817
			#回傳結果
7818
			return $result;
226 liveuser 7819
 
3 liveuser 7820
			}#if end
226 liveuser 7821
 
3 liveuser 7822
		#debug
7823
		#var_dump($spiltString);
7824
		#var_dump($_SERVER);
7825
 
7826
		#初始化檔案在伺服器上的檔案系統位置
7827
		$result["fileSystemAbsoulutePosition"]="/";
226 liveuser 7828
 
3 liveuser 7829
		#將最後一段捨棄
7830
		for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 7831
 
3 liveuser 7832
			$result["fileSystemAbsoulutePosition"]=$result["fileSystemAbsoulutePosition"].$spiltString["dataArray"][$i]."/";
226 liveuser 7833
 
7834
			}#for end
7835
 
3 liveuser 7836
		#取得非直觀的絕對位置
7837
		$result["fileSystemAbsoulutePosition"]=$result["fileSystemAbsoulutePosition"].$result["fileSystemRelativePosition"];
226 liveuser 7838
 
3 liveuser 7839
		#將檔案的相對路徑進行整理,變成可以直接讀的路徑.
7840
		#函式說明:
7841
		#將檔案目錄的絕對位置中的 "../" 剔除變成直觀的路徑.
7842
		#回傳的結果:
7843
		#$result["status"],執行是否成功,"true"代表執行成功,"false"代表執行失敗.
7844
		#$result["function"],當前執行的函數.
7845
		#$result["error"],錯誤訊息陣列.
7846
		#$result["changedPath"],處理完後回傳的目錄字串.
7847
		#$result["oriPath"],原始的路徑字串
7848
		#必填參數:
7849
		#$conf["stringProcess::changeDirByDotDotSolidus"]["dirStr"],字串,要處理的檔案目錄字串.
7850
		$conf["stringProcess::changeDirByDotDotSolidus"]["dirStr"]=$result["fileSystemAbsoulutePosition"];
7851
		$changeDirByDotDotSolidus=stringProcess::changeDirByDotDotSolidus($conf["stringProcess::changeDirByDotDotSolidus"]);
7852
		unset($conf["stringProcess::changeDirByDotDotSolidus"]);
226 liveuser 7853
 
3 liveuser 7854
		#如果處理失敗
7855
		if($changeDirByDotDotSolidus["status"]==="false"){
226 liveuser 7856
 
3 liveuser 7857
			#設置錯誤狀態
7858
			$result["status"]="false";
226 liveuser 7859
 
3 liveuser 7860
			#設置錯誤提示
7861
			$result["error"]=$changeDirByDotDotSolidus;
226 liveuser 7862
 
3 liveuser 7863
			#回傳結果
7864
			return $result;
226 liveuser 7865
 
3 liveuser 7866
			}#if end
226 liveuser 7867
 
3 liveuser 7868
		#改變為易讀的絕對路徑
226 liveuser 7869
		$result["fileSystemAbsoulutePosition"]=$changeDirByDotDotSolidus["changedPath"];
7870
 
3 liveuser 7871
		#如果 $conf["userDir"] 為 "true"
7872
		if($conf["userDir"]==="true"){
226 liveuser 7873
 
3 liveuser 7874
			#重設為 絕對路徑 [/~家目錄名稱」
7875
			$result["webPathFromRoot"]="/~".$spiltString["dataArray"][1];
226 liveuser 7876
 
3 liveuser 7877
			#從第四段到倒數第二段,將其內容合併
7878
			for($i=3;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 7879
 
3 liveuser 7880
				$result["webPathFromRoot"]=$result["webPathFromRoot"]."/".$spiltString["dataArray"][$i];
226 liveuser 7881
 
3 liveuser 7882
				}#for end
226 liveuser 7883
 
3 liveuser 7884
			}#if end
226 liveuser 7885
 
3 liveuser 7886
		#反之 $conf["userDir"] 為 "false",
7887
		else{
226 liveuser 7888
 
3 liveuser 7889
			#重設為 ""
7890
			$result["webPathFromRoot"]="";
7891
 
226 liveuser 7892
			#可能的根目錄層級 - start
7893
 
3 liveuser 7894
			#解析 $conf["fileArgu"]
7895
			#函式說明:
7896
			#將固定格式的字串分開,並回傳分開的結果。
7897
			#回傳的參數:
7898
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7899
			#$result["error"],錯誤訊息陣列
7900
			#$result["function"],當前執行的函數名稱.
7901
			#$result["oriStr"],要分割的原始字串內容
7902
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
7903
			#$result["dataCounts"],爲總共分成幾段
7904
			#必填參數:
7905
			$conf["stringProcess::spiltString"]["stringIn"]=$_SERVER["PHP_SELF"];#要處理的字串。
7906
			$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
7907
			$keyWord=stringProcess::spiltString($conf["stringProcess::spiltString"]);
226 liveuser 7908
			unset($conf["stringProcess::spiltString"]);
3 liveuser 7909
 
7910
			#如果處理失敗
7911
			if($keyWord["status"]==="false"){
226 liveuser 7912
 
3 liveuser 7913
				#設置錯誤狀態
7914
				$result["status"]="false";
226 liveuser 7915
 
3 liveuser 7916
				#設置錯誤提示
7917
				$result["error"]=$keyWord;
226 liveuser 7918
 
3 liveuser 7919
				#回傳結果
7920
				return $result;
226 liveuser 7921
 
3 liveuser 7922
				}#if end
226 liveuser 7923
 
3 liveuser 7924
			#取得關鍵字
7925
			$keyWord=$keyWord["dataArray"][0];
7926
 
7927
			#預設層級為4層
7928
			$layer=4;
7929
 
7930
			#檢查每個絕對路徑片段
7931
			for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 7932
 
3 liveuser 7933
				#如果路徑片段等於 $keyWord
7934
				if($spiltString["dataArray"][$i]===$keyWord){
226 liveuser 7935
 
3 liveuser 7936
					#取得層級
7937
					$layer=$i;
226 liveuser 7938
 
3 liveuser 7939
					#跳出迴圈
7940
					break;
7941
 
7942
					}#if end
226 liveuser 7943
 
3 liveuser 7944
				}#for end
7945
 
7946
			#可能的根目錄層級 - end
7947
 
7948
			#網頁於檔案系統中的存放路徑可能為「/var/www/html」,從第四段到倒數第二段,將其內容合併
7949
			for($i=$layer;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 7950
 
3 liveuser 7951
				$result["webPathFromRoot"]=$result["webPathFromRoot"]."/".$spiltString["dataArray"][$i];
226 liveuser 7952
 
3 liveuser 7953
				}#for end
226 liveuser 7954
 
3 liveuser 7955
			}#else end
226 liveuser 7956
 
3 liveuser 7957
		#加上檔案的路徑
226 liveuser 7958
		$result["webPathFromRoot"]=$result["webPathFromRoot"]."/".$conf["address"];
7959
 
3 liveuser 7960
		#取得檔案位於網頁伺服器的絕對位置
7961
		#函式說明:
7962
		#取得用戶端的資訊,並依據需要寫入到資料表裡面
7963
		#回傳結果:
7964
		#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
7965
		#$result["error"],錯誤訊息.
7966
		#$result["function"],檔前執行的函數名稱.
7967
		#$result["userBrowserType"],爲使用者的瀏覽器資訊
7968
		#$result["userIp"],爲使用者的IP
7969
		#$result["serverIp"],為伺服器的IP
7970
		#$result["scheme"],通訊協定
7971
		#$result["serverPort"],伺服器給對外下載網頁的port
7972
		#$result["requestUri"],爲使用者要求的網址
7973
		#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功
7974
		#$result["clientRequestIP"],用戶端要求的ip與port
7975
		#必填參數:
7976
		$conf["csInformation::getConnectionInfo"]["getAccount"]="false";#是否要取得帳號
7977
		#可省略參數:
7978
		#$conf["accountVar"]=$_SESSION["username"];#帳號儲存在哪個變數裏面,預設爲$_SESSION["username"]
7979
		#$conf["saveToDb"]="true";#是否要除儲存到資料庫,"true"為要儲存",預設為不儲存
7980
		#$conf["dbAddress"]=$dbAddress;;#爲mysql-Server的位置,若#$conf["saveToDb"]設為"true",則該參數為必填。
7981
		#$conf["dbAccount"]=$dbAccount;#爲用於連入mysql-Server時要使用的帳號,若#$conf["saveToDb"]設為"true",則該參數為必填。
7982
		#$conf["dbName"]=$dbName;#要選取的資料庫名稱,若#$conf["saveToDb"]設為"true",則該參數為必填。
7983
		#$conf["tableName"]="visitorInfo";#爲要插入資料的資料表名稱,若#$conf["saveToDb"]設為"true",則該參數為必填。
7984
		#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");#爲資料表的項目名稱,
7985
			#例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);
7986
			#寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間
7987
			#$conf["saveToDb"]設為"true",則該參數為必填。
7988
		#$conf["dbPassword"]=$dbPassword;#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
7989
		$getConnectionInfo=csInformation::getConnectionInfo($conf["csInformation::getConnectionInfo"]);
226 liveuser 7990
		unset($conf["csInformation::getConnectionInfo"]);
7991
 
3 liveuser 7992
		#如果取得連線資訊失敗
7993
		if($getConnectionInfo["status"]==="false"){
226 liveuser 7994
 
3 liveuser 7995
			#設置錯誤狀態
7996
			$result["status"]="false";
226 liveuser 7997
 
3 liveuser 7998
			#設置錯誤提示
7999
			$result["error"]=$getConnectionInfo;
226 liveuser 8000
 
3 liveuser 8001
			#回傳結果
8002
			return $result;
226 liveuser 8003
 
3 liveuser 8004
			}#if end
226 liveuser 8005
 
3 liveuser 8006
		#如果運行環境為 "web"
8007
		if($getConnectionInfo["mode"]=="web"){
226 liveuser 8008
 
3 liveuser 8009
			#為絕對路徑加上通訊協定與ip與port
226 liveuser 8010
			#$result["content"]=$getConnectionInfo["scheme"]."://".$getConnectionInfo["serverIp"].":".$getConnectionInfo["serverPort"].$result["webPathFromRoot"];
8011
 
8012
			#為絕對路徑加上用戶端通訊協定與ip與port
3 liveuser 8013
			$result["content"]=$getConnectionInfo["scheme"]."://".$getConnectionInfo["clientRequestIP"].$result["webPathFromRoot"];
226 liveuser 8014
 
3 liveuser 8015
			}#if end
226 liveuser 8016
 
3 liveuser 8017
		#反之如果為 "cmd" 環境
8018
		else{
226 liveuser 8019
 
3 liveuser 8020
			$result["content"]="null";
226 liveuser 8021
 
3 liveuser 8022
			}#else end
226 liveuser 8023
 
3 liveuser 8024
		#設置執行正常
8025
		$result["status"]="true";
226 liveuser 8026
 
3 liveuser 8027
		#回傳結果
8028
		return $result;
226 liveuser 8029
 
3 liveuser 8030
		}#function getInternetAddress end
8031
 
8032
	/*
8033
	#函式說明:
8034
	#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
8035
	#回傳結果:
8036
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8037
	#$result["error"],錯誤訊息陣列.
226 liveuser 8038
	#$result["function"],函數名稱.
3 liveuser 8039
	#$result["argu"],使用的參數.
8040
	#$result["content"],網址,若是在命令列執行,則為"null".
8041
	#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
8042
	#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
8043
	#必填參數:
8044
	#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
8045
	$conf["address"]="";
8046
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
8047
	$conf["fileArgu"]=__FILE__;
8048
	#可省略參數:
8049
	#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
8050
	#$conf["web"]="true";
8051
	#參考資料:
8052
	#無.
8053
	#備註:
8054
	#無.
8055
	*/
8056
	public static function getInternetAddressV2(&$conf){
226 liveuser 8057
 
3 liveuser 8058
		#初始化要回傳的變數
8059
		$result=array();
226 liveuser 8060
 
3 liveuser 8061
		#記錄當前執行的函數名稱
8062
		$result["function"]=__FUNCTION__;
226 liveuser 8063
 
3 liveuser 8064
		#取得參數
8065
		$result["argu"]=$conf;
226 liveuser 8066
 
3 liveuser 8067
		#檢查參數
8068
		#函式說明:
8069
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
8070
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8071
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8072
		#$result["function"],當前執行的函式名稱.
8073
		#$result["argu"],設置給予的參數.
8074
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8075
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8076
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8077
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8078
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8079
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8080
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8081
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8082
		#必填寫的參數:
8083
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8084
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8085
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8086
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8087
		#可以省略的參數:
8088
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8089
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("address","fileArgu");
8090
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
8091
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
8092
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8093
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8094
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
8095
		#$conf["canNotBeEmpty"]=array();
8096
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
8097
		#$conf["canBeEmpty"]=array();
8098
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
8099
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web");
8100
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8101
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
8102
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
8103
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
8104
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8105
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
8106
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
8107
		#$conf["disallowAllSkipableVarIsEmpty"]="";
8108
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
8109
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
8110
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8111
		#$conf["arrayCountEqualCheck"][]=array();
8112
		#參考資料來源:
8113
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8114
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8115
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 8116
 
3 liveuser 8117
		#如果檢查失敗
8118
		if($checkArguments["status"]==="false"){
226 liveuser 8119
 
3 liveuser 8120
			#設置錯誤狀態
8121
			$result["status"]="false";
226 liveuser 8122
 
3 liveuser 8123
			#設置錯誤提示
8124
			$result["error"]=$checkArguments;
226 liveuser 8125
 
3 liveuser 8126
			#回傳結果
8127
			return $result;
226 liveuser 8128
 
3 liveuser 8129
			}#if end
226 liveuser 8130
 
3 liveuser 8131
		#如果檢查不通過
8132
		if($checkArguments["passed"]==="false"){
226 liveuser 8133
 
3 liveuser 8134
			#設置錯誤狀態
8135
			$result["status"]="false";
226 liveuser 8136
 
3 liveuser 8137
			#設置錯誤提示
8138
			$result["error"]=$checkArguments;
226 liveuser 8139
 
3 liveuser 8140
			#回傳結果
8141
			return $result;
226 liveuser 8142
 
3 liveuser 8143
			}#if end
226 liveuser 8144
 
3 liveuser 8145
		#如果是本來就是網址了
8146
		if(strpos($conf["address"],'https://')===0 || strpos($conf["address"],'http://')===0){
226 liveuser 8147
 
3 liveuser 8148
			#取得網址
8149
			$result["content"]=$conf["address"];
226 liveuser 8150
 
3 liveuser 8151
			}#if end
226 liveuser 8152
 
3 liveuser 8153
		#反之是絕對或相對路徑
8154
		else{
226 liveuser 8155
 
3 liveuser 8156
			#確認 $conf["address"] 是否為 escaped 後的內容
8157
			#函式說明:
8158
			#判斷字串是否一定需要經過escapeshellarg才能為單一shell參數,並回傳可以成為單一shell參數的結果.
8159
			#回傳結果:
8160
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8161
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
8162
			#$result["function"],當前執行的函式名稱.
8163
			#$result["argu"],使用的參數.
8164
			#$result["content"],字串,單一shell參數.
8165
			#$result["escaped"],字串,"true"代表content為 escape後的結果;反之為"false".
8166
			#$result["urlEncodeStr"],字串,未被escape過的單一shell參數被url encode後的結果.
8167
			#必填參數:
8168
			#$conf["str"],字串,認為要為單一 shell參數的字串.
8169
			$conf["stringProcess::toSingleShellArg"]["str"]=$conf["address"];
8170
			#可省略參數:
8171
			#無.
8172
			#參考資料:
8173
			#無.
8174
			#備註:
8175
			#無.
8176
			$toSingleShellArg=stringProcess::toSingleShellArg($conf["stringProcess::toSingleShellArg"]);
8177
			unset($conf["stringProcess::toSingleShellArg"]);
226 liveuser 8178
 
3 liveuser 8179
			#如果執行失敗
8180
			if($toSingleShellArg["status"]==="false"){
226 liveuser 8181
 
3 liveuser 8182
				#設置錯誤狀態
8183
				$result["status"]="false";
226 liveuser 8184
 
3 liveuser 8185
				#設置錯誤提示
8186
				$result["error"]=$toSingleShellArg;
226 liveuser 8187
 
3 liveuser 8188
				#回傳結果
8189
				return $result;
226 liveuser 8190
 
3 liveuser 8191
				}#if end
226 liveuser 8192
 
3 liveuser 8193
			#取得不含escape字元的address參數
8194
			$conf["address"]=urldecode($toSingleShellArg["urlEncodeStr"]);
226 liveuser 8195
 
3 liveuser 8196
			#不是絕對位置
8197
			if(strpos($conf["address"],"/")!==0){
226 liveuser 8198
 
3 liveuser 8199
				#如果有這些參數
8200
				if( isset($_SERVER['REQUEST_SCHEME']) && isset($_SERVER['SERVER_NAME']) && isset($_SERVER['SERVER_PORT']) ){
226 liveuser 8201
 
3 liveuser 8202
					#網址
8203
					$result["content"]=$_SERVER['REQUEST_SCHEME']."://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT']."/".$conf["address"];
226 liveuser 8204
 
3 liveuser 8205
					}#if end
226 liveuser 8206
 
3 liveuser 8207
				#反之
8208
				else{
226 liveuser 8209
 
3 liveuser 8210
					#網址設置為 null
8211
					$result["content"]=null;
226 liveuser 8212
 
3 liveuser 8213
					}#else
226 liveuser 8214
 
3 liveuser 8215
				}#if end
226 liveuser 8216
 
3 liveuser 8217
			#反之是絕對位置
8218
			else{
226 liveuser 8219
 
3 liveuser 8220
				#移除開頭的 "/"
8221
				$conf["address"]=substr($conf["address"],1);
226 liveuser 8222
 
3 liveuser 8223
				#如果有這些參數
8224
				if( isset($_SERVER['REQUEST_SCHEME']) && isset($_SERVER['SERVER_NAME']) && isset($_SERVER['SERVER_PORT']) ){
226 liveuser 8225
 
3 liveuser 8226
					#網址
8227
					$result["content"]=$_SERVER['REQUEST_SCHEME']."://".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT']."/".$conf["address"];
226 liveuser 8228
 
3 liveuser 8229
					}#if end
226 liveuser 8230
 
3 liveuser 8231
				#反之
8232
				else{
226 liveuser 8233
 
3 liveuser 8234
					#網址設置為 null
8235
					$result["content"]=null;
226 liveuser 8236
 
3 liveuser 8237
					}#else
226 liveuser 8238
 
3 liveuser 8239
				}#else end
226 liveuser 8240
 
3 liveuser 8241
			#取得 doc root;
8242
			$docRoot=$_SERVER['DOCUMENT_ROOT'];
226 liveuser 8243
 
3 liveuser 8244
			#如果不是網路環境
8245
			if($conf["web"]==="false"){
226 liveuser 8246
 
3 liveuser 8247
				#不採用 docRoot
8248
				$docRoot="";
226 liveuser 8249
 
3 liveuser 8250
				}#if end
226 liveuser 8251
 
3 liveuser 8252
			#如果不存在 DOCUMENT_ROOT 變數或 web 參數為 "false" 且為相對位置.
8253
			if( ($_SERVER['DOCUMENT_ROOT']==="" || $conf["web"]==="false") && (strpos($result["argu"]["address"],"/")!==0) ){
226 liveuser 8254
 
3 liveuser 8255
				#執行 "pwd" 取得當前位置
8256
				exec("pwd",$output,$status);
226 liveuser 8257
 
3 liveuser 8258
				#預設為`pwd`的結果加"/"
8259
				$docRoot=$output[0]."/";
226 liveuser 8260
 
8261
				}#if end
8262
 
3 liveuser 8263
			#如果是絕對位置
8264
			else if(strpos($result["argu"]["address"],"/")===0){
226 liveuser 8265
 
8266
				#補回 "/"
3 liveuser 8267
				$conf["address"]="/".$conf["address"];
226 liveuser 8268
 
3 liveuser 8269
				}#if end
226 liveuser 8270
 
3 liveuser 8271
			#針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
8272
			$result["fileSystemAbsoulutePosition"]=$docRoot.$conf["address"];
226 liveuser 8273
 
3 liveuser 8274
			}#else end
226 liveuser 8275
 
3 liveuser 8276
		#設置執行正常
226 liveuser 8277
		$result["status"]="true";
8278
 
3 liveuser 8279
		#回傳結果
8280
		return $result;
226 liveuser 8281
 
3 liveuser 8282
		}#function getInternetAddressV2 end
8283
 
8284
	/*
8285
	#函式說明:
8286
	#將含有「*」的檔案路徑名稱,變成多個符合條件的路徑檔案.
8287
	#回傳結果:
8288
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8289
	#$result["error"],錯誤訊息陣列.
226 liveuser 8290
	#$result["function"],函數名稱.
3 liveuser 8291
	#$result["content"],字串陣列,多個解析回來的檔案路徑字串.
8292
	#必填參數:
8293
	#$conf["path"],字串,要解析含有「*」的檔案路徑字串.
8294
	$conf["path"]="";
8295
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
8296
	$conf["fileArgu"]=__FILE__;
8297
	#可省略參數:
8298
	#$conf["noDotStart"],字串,"true"代表不包含「.」開頭的名稱,預設為"false"代表包含「.」開頭的名稱.
8299
	#$conf["noDotStart"]="true";
8300
	#$conf["noWaveEnd"],字串,預設為"true"代表不包含「~」結尾的名稱,"false"代表包含結尾為「~」的名稱.
8301
	#$conf["noWaveEnd"]="true";
8302
	#參考資料:
8303
	#無.
8304
	#備註:
8305
	#無.
8306
	*/
8307
	public static function resolvePostionStringWhichContainStarSymbol(&$conf){
226 liveuser 8308
 
3 liveuser 8309
		#初始化要回傳的結果
8310
		$result=array();
226 liveuser 8311
 
3 liveuser 8312
		#設置當其函數名稱
8313
		$result["function"]=__FUNCTION__;
226 liveuser 8314
 
3 liveuser 8315
		#如果 $conf 不為陣列
8316
		if(gettype($conf)!="array"){
226 liveuser 8317
 
3 liveuser 8318
			#設置執行失敗
8319
			$result["status"]="false";
226 liveuser 8320
 
3 liveuser 8321
			#設置執行錯誤訊息
8322
			$result["error"][]="\$conf變數須為陣列形態";
8323
 
8324
			#如果傳入的參數為 null
8325
			if($conf==null){
226 liveuser 8326
 
3 liveuser 8327
				#設置執行錯誤訊息
8328
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 8329
 
3 liveuser 8330
				}#if end
8331
 
8332
			#回傳結果
8333
			return $result;
226 liveuser 8334
 
3 liveuser 8335
			}#if end
226 liveuser 8336
 
3 liveuser 8337
		#檢查參數
8338
		#函式說明:
8339
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
8340
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8341
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8342
		#$result["function"],當前執行的函式名稱.
8343
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8344
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8345
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8346
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
8347
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8348
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8349
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8350
		#必填寫的參數:
8351
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8352
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8353
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8354
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","fileArgu");
226 liveuser 8355
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 8356
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
8357
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8358
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8359
		#可以省略的參數:
8360
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
8361
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8362
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8363
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("noDotStart","noWaveEnd");
226 liveuser 8364
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 8365
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
8366
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8367
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","true");
8368
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8369
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
8370
		#參考資料來源:
8371
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8372
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8373
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 8374
 
3 liveuser 8375
		#如果 $checkResult["status"] 等於 "fasle"
8376
		if($checkResult["status"]==="false"){
226 liveuser 8377
 
3 liveuser 8378
			#設置錯誤識別
8379
			$result["status"]="false";
226 liveuser 8380
 
3 liveuser 8381
			#設置錯誤訊息
8382
			$result["error"]=$checkResult;
226 liveuser 8383
 
3 liveuser 8384
			#回傳結果
8385
			return $result;
226 liveuser 8386
 
3 liveuser 8387
			}#if end
226 liveuser 8388
 
3 liveuser 8389
		#如果 $checkResult["passed"] 等於 "fasle"
8390
		if($checkResult["passed"]==="false"){
226 liveuser 8391
 
3 liveuser 8392
			#設置錯誤識別
8393
			$result["status"]="false";
226 liveuser 8394
 
3 liveuser 8395
			#設置錯誤訊息
8396
			$result["error"]=$checkResult;
226 liveuser 8397
 
3 liveuser 8398
			#回傳結果
8399
			return $result;
226 liveuser 8400
 
3 liveuser 8401
			}#if end
226 liveuser 8402
 
3 liveuser 8403
		#轉換檔案路徑為相對於伺服器檔案系統的絕對路徑
8404
		#函式說明:
8405
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
8406
		#回傳結果:
8407
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8408
		#$result["error"],錯誤訊息陣列.
226 liveuser 8409
		#$result["function"],函數名稱.
3 liveuser 8410
		#$result["content"],網址.
8411
		#$result["localAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
8412
		#$result["fileSystemAbsoulutePosition"],針對伺服器檔案系統的絕對位置.
8413
		#必填參數:
8414
		#$conf["address"],字串,檔案的相對位置.
8415
		$conf["fileAccess::getInternetAddress"]["address"]=$conf["path"];
8416
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
8417
		$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
8418
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是.
8419
		$conf["fileAccess::getInternetAddress"]["userDir"]="true";
8420
		$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
8421
		unset($conf["fileAccess::getInternetAddress"]);
226 liveuser 8422
 
3 liveuser 8423
		#如果轉換路徑失敗
8424
		if($getInternetAddress["status"]=="false"){
226 liveuser 8425
 
3 liveuser 8426
			#設置錯誤識別
8427
			$result["status"]="false";
226 liveuser 8428
 
3 liveuser 8429
			#設置錯誤訊息
8430
			$result["error"]=$checkResult;
226 liveuser 8431
 
3 liveuser 8432
			#回傳結果
8433
			return $result;
226 liveuser 8434
 
3 liveuser 8435
			}#if end
226 liveuser 8436
 
3 liveuser 8437
		#取得轉換好的路徑
8438
		$conf["path"]=$getInternetAddress["fileSystemAbsoulutePosition"];
226 liveuser 8439
 
3 liveuser 8440
		#檢查檔案路徑字串是否含有「*」
8441
		#函式說明:
8442
		#檢查字串裡面有無指定的關鍵字
8443
		#回傳結果:
8444
		#$result["status"],"true"代表執行成功,"false"代表執行失敗。
8445
		#$result["error"],錯誤訊息
8446
		#$result["function"],當前執行的函數名稱.
8447
		#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
8448
		#$result["keyWordCount"],找到的關鍵字數量.
8449
		#必填參數:
8450
		$conf["search::findKeyWord"]["keyWord"]="*";#想要搜尋的關鍵字
8451
		$conf["search::findKeyWord"]["string"]=$conf["path"];#要被搜尋的字串內容
8452
		#可省略參數:
8453
		#$conf["fileAccess::findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
8454
		$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
8455
		unset($conf["search::findKeyWord"]);
226 liveuser 8456
 
3 liveuser 8457
		#如果尋找關鍵字出錯
8458
		if($findKeyWord["status"]=="false"){
226 liveuser 8459
 
3 liveuser 8460
			#設置錯誤識別
8461
			$result["status"]="false";
226 liveuser 8462
 
3 liveuser 8463
			#設置錯誤訊息
8464
			$result["error"]=$findKeyWord;
226 liveuser 8465
 
3 liveuser 8466
			#回傳結果
8467
			return $result;
226 liveuser 8468
 
3 liveuser 8469
			}#if end
226 liveuser 8470
 
3 liveuser 8471
		#如果含有「*」
8472
		if($findKeyWord["founded"]=="true"){
226 liveuser 8473
 
3 liveuser 8474
			#透過「/」分割路徑字串
8475
			#函式說明:
8476
			#將固定格式的字串分開,並回傳分開的結果。
8477
			#回傳的參數:
8478
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8479
			#$result["error"],錯誤訊息陣列
8480
			#$result["function"],當前執行的函數名稱.
8481
			#$result["oriStr"],要分割的原始字串內容
8482
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
8483
			#$result["dataCounts"],爲總共分成幾段
8484
			#必填參數:
8485
			$conf["stringProcess::spiltString"]["stringIn"]=$conf["path"];#要處理的字串。
8486
			$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
8487
			$spiltPathStr=stringProcess::spiltString($conf["stringProcess::spiltString"]);
8488
			unset($conf["stringProcess::spiltString"]);
226 liveuser 8489
 
3 liveuser 8490
			#如果分割字串失敗
8491
			if($spiltPathStr["status"]=="false"){
226 liveuser 8492
 
3 liveuser 8493
				#設置錯誤識別
8494
				$result["status"]="false";
226 liveuser 8495
 
3 liveuser 8496
				#設置錯誤訊息
8497
				$result["error"]=$spiltPathStr;
226 liveuser 8498
 
3 liveuser 8499
				#回傳結果
8500
				return $result;
226 liveuser 8501
 
3 liveuser 8502
				}#if end
226 liveuser 8503
 
3 liveuser 8504
			#初始化暫存展開後的檔案路徑字串
226 liveuser 8505
			$extendPath=array("");
8506
 
3 liveuser 8507
			#要解析的路徑分成幾段就執行幾次
8508
			foreach($spiltPathStr["dataArray"] as $pathPart){
226 liveuser 8509
 
3 liveuser 8510
				#檢查該段名稱是否有「*」
8511
				#函式說明:
8512
				#檢查字串裡面有無指定的關鍵字
8513
				#回傳結果:
8514
				#$result["status"],"true"代表執行成功,"false"代表執行失敗。
8515
				#$result["error"],錯誤訊息
8516
				#$result["function"],當前執行的函數名稱.
8517
				#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
8518
				#$result["keyWordCount"],找到的關鍵字數量.
8519
				#必填參數:
8520
				$conf["search::findKeyWord"]["keyWord"]="*";#想要搜尋的關鍵字
8521
				$conf["search::findKeyWord"]["string"]=$pathPart;#要被搜尋的字串內容
8522
				#可省略參數:
8523
				#$conf["fileAccess::findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
8524
				$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
8525
				unset($conf["search::findKeyWord"]);
226 liveuser 8526
 
3 liveuser 8527
				#如果尋找關鍵字出錯
8528
				if($findKeyWord["status"]=="false"){
226 liveuser 8529
 
3 liveuser 8530
					#設置錯誤識別
8531
					$result["status"]="false";
226 liveuser 8532
 
3 liveuser 8533
					#設置錯誤訊息
8534
					$result["error"]=$findKeyWord;
226 liveuser 8535
 
3 liveuser 8536
					#回傳結果
8537
					return $result;
226 liveuser 8538
 
8539
					}#if end
8540
 
3 liveuser 8541
				#如果不含「*」
8542
				if($findKeyWord["founded"]=="false"){
226 liveuser 8543
 
3 liveuser 8544
					#針對每個既有的路徑
8545
					for($i=0;$i<count($extendPath);$i++){
226 liveuser 8546
 
3 liveuser 8547
						#加上切割好的路徑
8548
						$extendPath[$i]=$extendPath[$i]."/".$pathPart;
226 liveuser 8549
 
3 liveuser 8550
						}#for end
226 liveuser 8551
 
3 liveuser 8552
					}#if end
226 liveuser 8553
 
8554
				#反之該段含有「*」
3 liveuser 8555
				else{
226 liveuser 8556
 
3 liveuser 8557
					#用「*」分割該段
8558
					#函式說明:
8559
					#將固定格式的字串分開,並回傳分開的結果。
8560
					#回傳的參數:
8561
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8562
					#$result["error"],錯誤訊息陣列
8563
					#$result["function"],當前執行的函數名稱.
8564
					#$result["oriStr"],要分割的原始字串內容
8565
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
8566
					#$result["dataCounts"],爲總共分成幾段
8567
					#必填參數:
8568
					$conf["stringProcess::spiltString"]["stringIn"]=$pathPart;#要處理的字串。
8569
					$conf["stringProcess::spiltString"]["spiltSymbol"]="*";#爲以哪個符號作爲分割
8570
					$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
8571
					unset($conf["stringProcess::spiltString"]);
226 liveuser 8572
 
3 liveuser 8573
					#如果分字串失敗
8574
					if($spiltString["status"]=="false"){
226 liveuser 8575
 
3 liveuser 8576
						#設置錯誤識別
8577
						$result["status"]="false";
226 liveuser 8578
 
3 liveuser 8579
						#設置錯誤訊息
8580
						$result["error"]=$spiltStringByStar;
226 liveuser 8581
 
3 liveuser 8582
						#回傳結果
8583
						return $result;
226 liveuser 8584
 
3 liveuser 8585
						}#if end
226 liveuser 8586
 
3 liveuser 8587
					#如果用「*」分割後的段數為0
8588
					if($spiltString["dataCounts"]==0){
226 liveuser 8589
 
3 liveuser 8590
						#初始化儲存符合條件的路徑
8591
						$newExtendPath=array();
226 liveuser 8592
 
3 liveuser 8593
						#代表沒有塞選條件
8594
						#當前有幾個符合條件的路徑就執行幾次
8595
						for($i=0;$i<count($extendPath);$i++){
226 liveuser 8596
 
3 liveuser 8597
							#取得該目錄下所有的東西
8598
							#取得該目錄底下的檔案目錄清單
8599
							#函式說明:
8600
							#取得目錄底下所有目錄與檔案清單.
8601
							#回傳結果:
8602
							#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8603
							#$result["error"],錯誤訊息陣列.
8604
							#$result["function"],函數名稱.
8605
							#$result["content"],陣列,目錄底下的檔案與子目錄.
8606
							#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
8607
							#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
8608
							#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
8609
							#$result["position"],目前的位置.
8610
							#必填參數:
8611
							#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
8612
							$conf["fileAccess::getList"]["position"]=$extendPath[$i];
8613
							#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8614
							$conf["fileAccess::getList"]["fileArgu"]=$conf["fileArgu"];
8615
							#可省略參數:
8616
							#無
8617
							#參考資料來源:
8618
							#opendir=>http://php.net/manual/en/function.opendir.php
8619
							#is_dir=>http://php.net/manual/en/function.is-dir.php
8620
							$getList=fileAccess::getList($conf["fileAccess::getList"]);
226 liveuser 8621
							unset($conf["fileAccess::getList"]);
8622
 
3 liveuser 8623
							#如果取得目標目錄底下的檔案目錄清單失敗
8624
							if($getList["status"]=="false"){
226 liveuser 8625
 
3 liveuser 8626
								#設置錯誤識別
8627
								$result["status"]="false";
226 liveuser 8628
 
3 liveuser 8629
								#設置錯誤訊息
226 liveuser 8630
								$result["error"]=$getList;
8631
 
3 liveuser 8632
								#回傳結果
8633
								return $result;
226 liveuser 8634
 
3 liveuser 8635
								}#if end
226 liveuser 8636
 
3 liveuser 8637
							#如果底下有東西
8638
							if(count($getList["content"])>0){
226 liveuser 8639
 
3 liveuser 8640
								#初始化儲存要檢查的檔案或資料夾名稱陣列
8641
								$list=array();
226 liveuser 8642
 
3 liveuser 8643
								#針對每個檔案或資料夾
8644
								foreach($getList["content"] as $num=>$array){
226 liveuser 8645
 
3 liveuser 8646
									#儲存該名稱
8647
									$list[]=$array["name"];
226 liveuser 8648
 
3 liveuser 8649
									}#foreach end
226 liveuser 8650
 
3 liveuser 8651
								#初始化儲存符合新條件字串的陣列
8652
								$tempExtendPath=array();
226 liveuser 8653
 
3 liveuser 8654
								#針對每個現有的路徑字串
8655
								for($j=0;$j<count($extendPath);$j++){
226 liveuser 8656
 
3 liveuser 8657
									#附加每個符合條件的名稱到路徑字串裡面
8658
									for($k=0;$k<count($list);$k++){
226 liveuser 8659
 
3 liveuser 8660
										#如果 $conf["noDotStart"] 為 "true"
8661
										if($conf["noDotStart"]==="true"){
226 liveuser 8662
 
3 liveuser 8663
											#將 $list[$k] 用 "/" 分割
8664
											#函式說明:
8665
											#將固定格式的字串分開,並回傳分開的結果。
8666
											#回傳結果:
8667
											#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8668
											#$result["error"],錯誤訊息陣列
8669
											#$result["function"],當前執行的函數名稱.
8670
											#$result["oriStr"],要分割的原始字串內容
8671
											#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
8672
											#$result["dataCounts"],爲總共分成幾段
8673
											#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
8674
											#必填參數:
8675
											$conf["stringProcess::spiltString"]["stringIn"]=$list[$k];#要處理的字串。
8676
											$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
8677
											#可省略參數:
8678
											#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
8679
											$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
8680
											$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
8681
											unset($conf["stringProcess::spiltString"]);
226 liveuser 8682
 
3 liveuser 8683
											#如果分割路徑失敗
8684
											if($spiltString["status"]==="false"){
226 liveuser 8685
 
3 liveuser 8686
												#設置執行錯誤識別
8687
												$result["status"]="false";
226 liveuser 8688
 
3 liveuser 8689
												#取得錯誤訊息
8690
												$result["error"]=$spiltString;
226 liveuser 8691
 
3 liveuser 8692
												#回傳結果
8693
												return $result;
226 liveuser 8694
 
3 liveuser 8695
												}#if end
226 liveuser 8696
 
3 liveuser 8697
											#如果有關鍵字「/」存在
8698
											if($spiltString["found"]==="true"){
226 liveuser 8699
 
3 liveuser 8700
												#針對每個段落
8701
												foreach($spiltString["dataArray"] as $pp){
226 liveuser 8702
 
3 liveuser 8703
													#看該符合的名稱開頭是否包含「.」
8704
													#函式說明:
8705
													#取得符合特定字首與字尾的字串
8706
													#回傳結果:
8707
													#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
8708
													#$result["function"],當前執行的函數名稱.
8709
													#$result["error"],錯誤訊息陣列.
8710
													#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
8711
													#$result["returnString"],爲符合字首條件的字串內容。
8712
													#必填參數:
8713
													#$conf["checkString"],字串,要檢查的字串.
8714
													$conf["search::getMeetConditionsString"]["checkString"]=$pp;
8715
													#可省略參數:
8716
													#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
8717
													$conf["search::getMeetConditionsString"]["frontWord"]=".";
8718
													#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
8719
													#$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
8720
													#參考資料:
8721
													#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
8722
													$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
8723
													unset($conf["search::getMeetConditionsString"]);
226 liveuser 8724
 
3 liveuser 8725
													#如果 取得符合特定字首的字串 出錯
8726
													if($getMeetConditionsString["status"]=="false"){
226 liveuser 8727
 
3 liveuser 8728
														#設置執行錯誤識別
8729
														$result["status"]="false";
226 liveuser 8730
 
3 liveuser 8731
														#設置錯誤訊息
8732
														$result["error"]=$getMeetConditionsString;
226 liveuser 8733
 
3 liveuser 8734
														#回傳結果
8735
														return $result;
226 liveuser 8736
 
3 liveuser 8737
														}#if end
226 liveuser 8738
 
3 liveuser 8739
													#如果有「.」在開頭
8740
													if($getMeetConditionsString["founded"]=="true"){
226 liveuser 8741
 
8742
														#忽略這個名稱
3 liveuser 8743
														continue 2;
226 liveuser 8744
 
3 liveuser 8745
														}#if end
226 liveuser 8746
 
3 liveuser 8747
													}#foreach end
226 liveuser 8748
 
3 liveuser 8749
												}#if end
226 liveuser 8750
 
3 liveuser 8751
											#反之沒有關鍵字「/」存在
8752
											else{
226 liveuser 8753
 
3 liveuser 8754
												#看該符合的名稱開頭是否包含「.」
8755
												#函式說明:
8756
												#取得符合特定字首與字尾的字串
8757
												#回傳結果:
8758
												#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
8759
												#$result["function"],當前執行的函數名稱.
8760
												#$result["error"],錯誤訊息陣列.
8761
												#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
8762
												#$result["returnString"],爲符合字首條件的字串內容。
8763
												#必填參數:
8764
												#$conf["checkString"],字串,要檢查的字串.
8765
												$conf["search::getMeetConditionsString"]["checkString"]=$list[$k];
8766
												#可省略參數:
8767
												#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
8768
												$conf["search::getMeetConditionsString"]["frontWord"]=".";
8769
												#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
8770
												#$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
8771
												#參考資料:
8772
												#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
8773
												$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
8774
												unset($conf["search::getMeetConditionsString"]);
226 liveuser 8775
 
3 liveuser 8776
												#如果 取得符合特定字首的字串 出錯
8777
												if($getMeetConditionsString["status"]=="false"){
226 liveuser 8778
 
3 liveuser 8779
													#設置執行錯誤識別
8780
													$result["status"]="false";
226 liveuser 8781
 
3 liveuser 8782
													#設置錯誤訊息
8783
													$result["error"]=$getMeetConditionsString;
226 liveuser 8784
 
3 liveuser 8785
													#回傳結果
8786
													return $result;
226 liveuser 8787
 
3 liveuser 8788
													}#if end
226 liveuser 8789
 
3 liveuser 8790
												#如果有「.」在開頭
8791
												if($getMeetConditionsString["founded"]=="true"){
226 liveuser 8792
 
8793
													#忽略這個名稱
3 liveuser 8794
													continue;
226 liveuser 8795
 
3 liveuser 8796
													}#if end
226 liveuser 8797
 
3 liveuser 8798
												}#else end
226 liveuser 8799
 
3 liveuser 8800
											}#if end
226 liveuser 8801
 
3 liveuser 8802
										#如果 $conf["noWaveEnd"] 為 "true"
8803
										if($conf["noWaveEnd"]==="true"){
226 liveuser 8804
 
3 liveuser 8805
											#看該符合的名稱結尾是否包含「~」
8806
											#函式說明:
8807
											#取得符合特定字首與字尾的字串
8808
											#回傳結果:
8809
											#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
8810
											#$result["function"],當前執行的函數名稱.
8811
											#$result["error"],錯誤訊息陣列.
8812
											#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
8813
											#$result["returnString"],爲符合字首條件的字串內容。
8814
											#必填參數:
8815
											#$conf["checkString"],字串,要檢查的字串.
8816
											$conf["search::getMeetConditionsString"]["checkString"]=$list[$k];
8817
											#可省略參數:
8818
											#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
8819
											#$conf["search::getMeetConditionsString"]["frontWord"]=".";
8820
											#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
8821
											$conf["search::getMeetConditionsString"]["tailWord"]="~";
8822
											#參考資料:
8823
											#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
8824
											$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
8825
											unset($conf["search::getMeetConditionsString"]);
226 liveuser 8826
 
3 liveuser 8827
											#如果 取得符合特定字首的字串 出錯
8828
											if($getMeetConditionsString["status"]=="false"){
226 liveuser 8829
 
3 liveuser 8830
												#設置執行錯誤識別
8831
												$result["status"]="false";
226 liveuser 8832
 
3 liveuser 8833
												#設置錯誤訊息
8834
												$result["error"]=$getMeetConditionsString;
226 liveuser 8835
 
3 liveuser 8836
												#回傳結果
8837
												return $result;
226 liveuser 8838
 
3 liveuser 8839
												}#if end
226 liveuser 8840
 
3 liveuser 8841
											#如果有「~」在結尾
8842
											if($getMeetConditionsString["founded"]=="true"){
226 liveuser 8843
 
3 liveuser 8844
												#忽略這個名稱
8845
												continue;
226 liveuser 8846
 
3 liveuser 8847
												}#if end
226 liveuser 8848
 
3 liveuser 8849
											}#if end
226 liveuser 8850
 
3 liveuser 8851
										#暫存該符合的路徑
8852
										$tempExtendPath[]=$extendPath[$j]."/".$list[$k];
226 liveuser 8853
 
3 liveuser 8854
										}#for end
226 liveuser 8855
 
8856
									}#for end
8857
 
3 liveuser 8858
								#該次有幾個符合的路徑就執行幾次
8859
								foreach($tempExtendPath as $path){
226 liveuser 8860
 
3 liveuser 8861
									#暫存符合的路徑
8862
									$newExtendPath[]=$path;
226 liveuser 8863
 
8864
									}#for end
8865
 
3 liveuser 8866
								}#if end
226 liveuser 8867
 
3 liveuser 8868
							#反之該目錄底下沒有東西
8869
							else{
226 liveuser 8870
 
3 liveuser 8871
								#移除該 $extendPath[$i]
8872
								unset($extendPath[$i]);
226 liveuser 8873
 
8874
								}#else end
8875
 
3 liveuser 8876
							}#for end
226 liveuser 8877
 
3 liveuser 8878
						#置換原始符合條件字串的路徑字串陣列
8879
						$extendPath=$newExtendPath;
226 liveuser 8880
 
3 liveuser 8881
						}#if end
226 liveuser 8882
 
3 liveuser 8883
						#反之用「*」分割後有分段
8884
						else{
226 liveuser 8885
 
3 liveuser 8886
							#初始化暫存符合條件的新路徑陣列變數
8887
							$newExtendPath=array();
226 liveuser 8888
 
3 liveuser 8889
							#當前有幾個符合條件的路徑就執行幾次
8890
							for($i=0;$i<count($extendPath);$i++){
226 liveuser 8891
 
3 liveuser 8892
								#取得該目錄下所有的東西
8893
								#函式說明:
8894
								#取得目錄底下所有目錄與檔案清單.
8895
								#回傳結果:
8896
								#$result["status"],"true"爲建立成功,"false"爲建立失敗.
8897
								#$result["error"],錯誤訊息陣列.
8898
								#$result["function"],函數名稱.
8899
								#$result["content"],陣列,目錄底下的檔案與子目錄.
8900
								#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
8901
								#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
8902
								#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
8903
								#$result["position"],目前的位置.
8904
								#必填參數:
8905
								#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
8906
								$conf["fileAccess::getList"]["position"]=$extendPath[$i];
8907
								#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8908
								$conf["fileAccess::getList"]["fileArgu"]=$conf["fileArgu"];
8909
								#可省略參數:
8910
								#無
8911
								#參考資料來源:
8912
								#opendir=>http://php.net/manual/en/function.opendir.php
8913
								#is_dir=>http://php.net/manual/en/function.is-dir.php
8914
								$getList=fileAccess::getList($conf["fileAccess::getList"]);
226 liveuser 8915
								unset($conf["fileAccess::getList"]);
8916
 
3 liveuser 8917
								#如果取得目標目錄底下的檔案目錄清單失敗
8918
								if($getList["status"]=="false"){
226 liveuser 8919
 
3 liveuser 8920
									#設置錯誤識別
8921
									$result["status"]="false";
226 liveuser 8922
 
3 liveuser 8923
									#設置錯誤訊息
226 liveuser 8924
									$result["error"]=$getList;
8925
 
3 liveuser 8926
									#回傳結果
8927
									return $result;
226 liveuser 8928
 
3 liveuser 8929
									}#if end
226 liveuser 8930
 
3 liveuser 8931
								#如果底下有東西
8932
								if(count($getList["content"])>0){
226 liveuser 8933
 
3 liveuser 8934
									#初始化儲存要檢查的檔案或資料夾名稱陣列
8935
									$list=array();
226 liveuser 8936
 
3 liveuser 8937
									#針對每個檔案或資料夾
8938
									foreach($getList["content"] as $num=>$array){
226 liveuser 8939
 
3 liveuser 8940
										#儲存該名稱
8941
										$list[]=$array["name"];
226 liveuser 8942
 
3 liveuser 8943
										}#foreach end
226 liveuser 8944
 
3 liveuser 8945
									#初始化儲存符合的名稱
8946
									$passedName=array();
226 liveuser 8947
 
3 liveuser 8948
									#依據每個檔案目錄名稱,檢查有無符合篩選條件
8949
									foreach($list as $filteredName){
226 liveuser 8950
 
3 liveuser 8951
										#初始化儲存被檢查的片段檔案資料夾名稱
8952
										$partName=$filteredName;
226 liveuser 8953
 
3 liveuser 8954
										#依據 $pathPart 分割成幾段(關鍵字數量)就執行幾次
8955
										for($i=0;$i<$spiltString["dataCounts"];$i++){
226 liveuser 8956
 
3 liveuser 8957
											#尋找關鍵字 $spiltString["dataArray"][$i]
8958
											#函式說明:
8959
											#檢查字串裡面有無指定的關鍵字
8960
											#回傳結果:
8961
											#$result["status"],"true"代表執行成功,"false"代表執行失敗。
8962
											#$result["error"],錯誤訊息
8963
											#$result["function"],當前執行的函數名稱.
8964
											#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
8965
											#$result["keyWordCount"],找到的關鍵字數量.
8966
											#必填參數:
8967
											$conf["search::findKeyWord"]["keyWord"]=$spiltString["dataArray"][$i];#想要搜尋的關鍵字
8968
											$conf["search::findKeyWord"]["string"]=$partName;#要被搜尋的字串內容
8969
											#可省略參數:
8970
											#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
8971
											$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
8972
											unset($conf["search::findKeyWord"]);
226 liveuser 8973
 
3 liveuser 8974
											#如果尋找關鍵字失敗
8975
											if($findKeyWord["status"]=="false"){
226 liveuser 8976
 
3 liveuser 8977
												#設置執行錯誤識別
8978
												$result["status"]="false";
226 liveuser 8979
 
3 liveuser 8980
												#設置錯誤訊息
8981
												$result["error"]=$findKeyWord;
226 liveuser 8982
 
3 liveuser 8983
												#回傳結果
8984
												return $result;
226 liveuser 8985
 
3 liveuser 8986
												}#if end
226 liveuser 8987
 
3 liveuser 8988
											#如果有找到關鍵字
8989
											if($findKeyWord["founded"]=="true"){
226 liveuser 8990
 
3 liveuser 8991
												#如果是最後一段要檢查的關鍵字
8992
												if($i==$spiltString["dataCounts"]-1){
226 liveuser 8993
 
3 liveuser 8994
													#判斷該關鍵字是否在該未分割的 $pathPart(含有*字號的關鍵字字串) 的開頭
8995
													#函式說明:
8996
													#取得符合特定字首與字尾的字串
8997
													#回傳結果:
8998
													#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
8999
													#$result["function"],當前執行的函數名稱.
9000
													#$result["error"],錯誤訊息陣列.
9001
													#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9002
													#$result["returnString"],爲符合字首條件的字串內容。
9003
													#必填參數:
9004
													#$conf["checkString"],字串,要檢查的字串.
9005
													$conf["search::getMeetConditionsString"]["checkString"]=$pathPart;
9006
													#可省略參數:
9007
													#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9008
													$conf["search::getMeetConditionsString"]["frontWord"]=$spiltString["dataArray"][0];
9009
													#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9010
													#$conf["tailWord"]="";
9011
													#參考資料:
9012
													#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9013
													$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9014
													unset($conf["search::getMeetConditionsString"]);
226 liveuser 9015
 
3 liveuser 9016
													#如果 取得符合特定字首的字串 出錯
9017
													if($getMeetConditionsString["status"]=="false"){
226 liveuser 9018
 
3 liveuser 9019
														#設置執行錯誤識別
9020
														$result["status"]="false";
226 liveuser 9021
 
3 liveuser 9022
														#設置錯誤訊息
9023
														$result["error"]=$getMeetConditionsString;
226 liveuser 9024
 
3 liveuser 9025
														#回傳結果
9026
														return $result;
226 liveuser 9027
 
3 liveuser 9028
														}#if end
226 liveuser 9029
 
3 liveuser 9030
													#如果關鍵字是在開頭
9031
													if($getMeetConditionsString["founded"]=="true"){
226 liveuser 9032
 
3 liveuser 9033
														#判斷關鍵字是否在該檔案目錄名稱的開頭
9034
														#函式說明:
9035
														#取得符合特定字首與字尾的字串
9036
														#回傳結果:
9037
														#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9038
														#$result["function"],當前執行的函數名稱.
9039
														#$result["error"],錯誤訊息陣列.
9040
														#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9041
														#$result["returnString"],爲符合字首條件的字串內容。
9042
														#必填參數:
9043
														#$conf["checkString"],字串,要檢查的字串.
9044
														$conf["search::getMeetConditionsString"]["checkString"]=$filteredName;
9045
														#可省略參數:
9046
														#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9047
														$conf["search::getMeetConditionsString"]["frontWord"]=$spiltString["dataArray"][0];
9048
														#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9049
														#$conf["tailWord"]="";
9050
														#參考資料:
9051
														#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9052
														$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9053
														unset($conf["search::getMeetConditionsString"]);
226 liveuser 9054
 
3 liveuser 9055
														#如果 取得符合特定字首的字串 出錯
9056
														if($getMeetConditionsString["status"]=="false"){
226 liveuser 9057
 
3 liveuser 9058
															#設置執行錯誤識別
9059
															$result["status"]="false";
226 liveuser 9060
 
3 liveuser 9061
															#設置錯誤訊息
9062
															$result["error"]=$getMeetConditionsString;
226 liveuser 9063
 
3 liveuser 9064
															#回傳結果
9065
															return $result;
226 liveuser 9066
 
3 liveuser 9067
															}#if end
226 liveuser 9068
 
3 liveuser 9069
														#如果關鍵字不在開頭
9070
														if($getMeetConditionsString["founded"]=="false"){
226 liveuser 9071
 
3 liveuser 9072
															#不符合條件,跳過該檔案目錄名稱
9073
															break;
226 liveuser 9074
 
3 liveuser 9075
															}#if end
226 liveuser 9076
 
3 liveuser 9077
														}#if end
226 liveuser 9078
 
3 liveuser 9079
													#判斷最後一個關鍵字是否在該未分割的 $pathPart(含有*字號的關鍵字字串) 的結尾
9080
													#函式說明:
9081
													#取得符合特定字首與字尾的字串
9082
													#回傳結果:
9083
													#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9084
													#$result["function"],當前執行的函數名稱.
9085
													#$result["error"],錯誤訊息陣列.
9086
													#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9087
													#$result["returnString"],爲符合字首條件的字串內容。
9088
													#必填參數:
9089
													#$conf["checkString"],字串,要檢查的字串.
9090
													$conf["search::getMeetConditionsString"]["checkString"]=$pathPart;
9091
													#可省略參數:
9092
													#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9093
													#$conf["search::getMeetConditionsString"]["frontWord"]=$partName;
9094
													#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9095
													$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
9096
													#參考資料:
9097
													#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9098
													$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9099
													unset($conf["search::getMeetConditionsString"]);
226 liveuser 9100
 
3 liveuser 9101
													#如果 取得符合特定字尾的字串 出錯
9102
													if($getMeetConditionsString["status"]=="false"){
226 liveuser 9103
 
3 liveuser 9104
														#設置執行錯誤識別
9105
														$result["status"]="false";
226 liveuser 9106
 
3 liveuser 9107
														#設置錯誤訊息
9108
														$result["error"]=$getMeetConditionsString;
226 liveuser 9109
 
3 liveuser 9110
														#回傳結果
9111
														return $result;
226 liveuser 9112
 
3 liveuser 9113
														}#if end
226 liveuser 9114
 
3 liveuser 9115
													#如果關鍵字是在字尾
9116
													if($getMeetConditionsString["founded"]=="true"){
226 liveuser 9117
 
3 liveuser 9118
														#判斷關鍵字是否在該片段的開頭
9119
														#函式說明:
9120
														#取得符合特定字首與字尾的字串
9121
														#回傳結果:
9122
														#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9123
														#$result["function"],當前執行的函數名稱.
9124
														#$result["error"],錯誤訊息陣列.
9125
														#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9126
														#$result["returnString"],爲符合字首條件的字串內容。
9127
														#必填參數:
9128
														#$conf["checkString"],字串,要檢查的字串.
9129
														$conf["search::getMeetConditionsString"]["checkString"]=$filteredName;
9130
														#可省略參數:
9131
														#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9132
														#$conf["search::getMeetConditionsString"]["frontWord"]=$partName;
9133
														#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9134
														$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
9135
														#參考資料:
9136
														#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9137
														$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9138
														unset($conf["search::getMeetConditionsString"]);
226 liveuser 9139
 
3 liveuser 9140
														#如果 取得符合特定字首的字串 出錯
9141
														if($getMeetConditionsString["status"]=="false"){
226 liveuser 9142
 
3 liveuser 9143
															#設置執行錯誤識別
9144
															$result["status"]="false";
226 liveuser 9145
 
3 liveuser 9146
															#設置錯誤訊息
9147
															$result["error"]=$getMeetConditionsString;
226 liveuser 9148
 
3 liveuser 9149
															#回傳結果
9150
															return $result;
226 liveuser 9151
 
3 liveuser 9152
															}#if end
226 liveuser 9153
 
3 liveuser 9154
														#如果關鍵字不在結尾
9155
														if($getMeetConditionsString["founded"]=="false"){
226 liveuser 9156
 
3 liveuser 9157
															#不符合條件,跳過該檔案目錄名稱
9158
															break;
226 liveuser 9159
 
3 liveuser 9160
															}#if end
226 liveuser 9161
 
3 liveuser 9162
														}#if end
226 liveuser 9163
 
3 liveuser 9164
													#如果 $conf["noDotStart"] 為 "true"
9165
													if($conf["noDotStart"]==="true"){
226 liveuser 9166
 
3 liveuser 9167
														#看該符合的名稱開頭是否包含「.」
9168
														#函式說明:
9169
														#取得符合特定字首與字尾的字串
9170
														#回傳結果:
9171
														#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9172
														#$result["function"],當前執行的函數名稱.
9173
														#$result["error"],錯誤訊息陣列.
9174
														#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9175
														#$result["returnString"],爲符合字首條件的字串內容。
9176
														#必填參數:
9177
														#$conf["checkString"],字串,要檢查的字串.
9178
														$conf["search::getMeetConditionsString"]["checkString"]=$filteredName;
9179
														#可省略參數:
9180
														#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9181
														$conf["search::getMeetConditionsString"]["frontWord"]=".";
9182
														#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9183
														#$conf["search::getMeetConditionsString"]["tailWord"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
9184
														#參考資料:
9185
														#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9186
														$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9187
														unset($conf["search::getMeetConditionsString"]);
226 liveuser 9188
 
3 liveuser 9189
														#如果 取得符合特定字首的字串 出錯
9190
														if($getMeetConditionsString["status"]=="false"){
226 liveuser 9191
 
3 liveuser 9192
															#設置執行錯誤識別
9193
															$result["status"]="false";
226 liveuser 9194
 
3 liveuser 9195
															#設置錯誤訊息
9196
															$result["error"]=$getMeetConditionsString;
226 liveuser 9197
 
3 liveuser 9198
															#回傳結果
9199
															return $result;
226 liveuser 9200
 
3 liveuser 9201
															}#if end
226 liveuser 9202
 
3 liveuser 9203
														#如果有「.」在開頭
9204
														if($getMeetConditionsString["founded"]=="true"){
226 liveuser 9205
 
3 liveuser 9206
															#中斷迴圈
9207
															break;
226 liveuser 9208
 
3 liveuser 9209
															}#if end
226 liveuser 9210
 
3 liveuser 9211
														}#if end
226 liveuser 9212
 
3 liveuser 9213
													#如果 $conf["noWaveEnd"] 為 "true"
9214
													if($conf["noWaveEnd"]==="true"){
226 liveuser 9215
 
3 liveuser 9216
														#看該符合的名稱結尾是否包含「~」
9217
														#函式說明:
9218
														#取得符合特定字首與字尾的字串
9219
														#回傳結果:
9220
														#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
9221
														#$result["function"],當前執行的函數名稱.
9222
														#$result["error"],錯誤訊息陣列.
9223
														#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
9224
														#$result["returnString"],爲符合字首條件的字串內容。
9225
														#必填參數:
9226
														#$conf["checkString"],字串,要檢查的字串.
9227
														$conf["search::getMeetConditionsString"]["checkString"]=$filteredName;
9228
														#可省略參數:
9229
														#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
9230
														#$conf["search::getMeetConditionsString"]["frontWord"]=".";
9231
														#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
9232
														$conf["search::getMeetConditionsString"]["tailWord"]="~";
9233
														#參考資料:
9234
														#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
9235
														$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
9236
														unset($conf["search::getMeetConditionsString"]);
226 liveuser 9237
 
3 liveuser 9238
														#如果 取得符合特定字首的字串 出錯
9239
														if($getMeetConditionsString["status"]=="false"){
226 liveuser 9240
 
3 liveuser 9241
															#設置執行錯誤識別
9242
															$result["status"]="false";
226 liveuser 9243
 
3 liveuser 9244
															#設置錯誤訊息
9245
															$result["error"]=$getMeetConditionsString;
226 liveuser 9246
 
3 liveuser 9247
															#回傳結果
9248
															return $result;
226 liveuser 9249
 
3 liveuser 9250
															}#if end
226 liveuser 9251
 
3 liveuser 9252
														#如果有「~」在結尾
9253
														if($getMeetConditionsString["founded"]=="true"){
226 liveuser 9254
 
3 liveuser 9255
															#中斷迴圈
9256
															break;
226 liveuser 9257
 
3 liveuser 9258
															}#if end
226 liveuser 9259
 
3 liveuser 9260
														}#if end
226 liveuser 9261
 
3 liveuser 9262
													#取得該符合的名稱
9263
													$passedName[]=$filteredName;
226 liveuser 9264
 
3 liveuser 9265
													#中斷迴圈
9266
													break;
226 liveuser 9267
 
3 liveuser 9268
													}#if end
226 liveuser 9269
 
3 liveuser 9270
												#將 $partName 從左到關鍵字結束的部份剔除
9271
												#函式說明:
9272
												#將特定字串前面的內容剔除
9273
												#回傳結果:
9274
												#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9275
												#$result["error"],錯誤訊息陣列.
9276
												#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
9277
												#$result["function"],當前執行的函數名稱.
9278
												#$result["oriStr"],要處理的原始字串內容.
9279
												#$result["content"],處理好的的字串內容.
9280
												#必填參數:
9281
												$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$partName;#要處理的字串.
9282
												$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=$spiltString["dataArray"][$i];#特定字串.
9283
												$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
9284
												unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 9285
 
3 liveuser 9286
												#如果將 $partName 從左到關鍵字結束的部份剔除失敗
9287
												if($delStrBeforeKeyWord["status"]=="false"){
226 liveuser 9288
 
3 liveuser 9289
													#設置執行錯誤識別
9290
													$result["status"]="false";
226 liveuser 9291
 
3 liveuser 9292
													#設置錯誤訊息
9293
													$result["error"]=$delStrBeforeKeyWord;
226 liveuser 9294
 
3 liveuser 9295
													#回傳結果
9296
													return $result;
226 liveuser 9297
 
3 liveuser 9298
													}#if end
226 liveuser 9299
 
3 liveuser 9300
												#如果沒有找到特定關鍵字字串
9301
												if($delStrBeforeKeyWord["founded"]=="false"){
226 liveuser 9302
 
3 liveuser 9303
													#設置執行錯誤識別
9304
													$result["status"]="false";
226 liveuser 9305
 
3 liveuser 9306
													#設置錯誤訊息
9307
													$result["error"]=$delStrBeforeKeyWord;
226 liveuser 9308
 
3 liveuser 9309
													#回傳結果
9310
													return $result;
226 liveuser 9311
 
3 liveuser 9312
													}#if end
226 liveuser 9313
 
9314
												#取得剔除過關鍵字前字串的字串
3 liveuser 9315
												$partName=$delStrBeforeKeyWord["content"];
226 liveuser 9316
 
3 liveuser 9317
												}#if end
226 liveuser 9318
 
9319
											#反之關鍵字不存在
3 liveuser 9320
											else{
226 liveuser 9321
 
3 liveuser 9322
												#儲存被拋棄的片段
9323
												#$result["dismissLog"][]="片段「".$partName."」沒有關鍵字「".$spiltString["dataArray"][$i]."」";
226 liveuser 9324
 
3 liveuser 9325
												#該名稱不符合條件
9326
												break;
226 liveuser 9327
 
3 liveuser 9328
												}#else end
226 liveuser 9329
 
3 liveuser 9330
											}#for end
226 liveuser 9331
 
3 liveuser 9332
										}#foreach end
226 liveuser 9333
 
3 liveuser 9334
									#初始化儲存符合的暫存路徑
9335
									$tempExtendPath=array();
226 liveuser 9336
 
3 liveuser 9337
									#針對每個現有的路徑字串
9338
									for($j=0;$j<count($extendPath);$j++){
226 liveuser 9339
 
3 liveuser 9340
										#附加每個符合條件的名稱到路徑字串裡面
9341
										for($k=0;$k<count($passedName);$k++){
226 liveuser 9342
 
3 liveuser 9343
											#暫存該符合的路徑
9344
											$tempExtendPath[]=$extendPath[$j]."/".$passedName[$k];
226 liveuser 9345
 
3 liveuser 9346
											}#for end
226 liveuser 9347
 
9348
										}#for end
9349
 
3 liveuser 9350
									#該次有幾個符合的路徑就執行幾次
9351
									foreach($tempExtendPath as $path){
226 liveuser 9352
 
3 liveuser 9353
										#暫存符合的路徑
9354
										$newExtendPath[]=$path;
226 liveuser 9355
 
9356
										}#foreach end
9357
 
3 liveuser 9358
									}#if end
226 liveuser 9359
 
3 liveuser 9360
								#反之該目錄底下沒有東西
9361
								else{
226 liveuser 9362
 
3 liveuser 9363
									#移除該 $extendPath[$i]
9364
									unset($extendPath[$i]);
226 liveuser 9365
 
9366
									}#else end
9367
 
3 liveuser 9368
								}#for end
226 liveuser 9369
 
3 liveuser 9370
							#如果有新的路徑產生
9371
							if(count($newExtendPath)>0){
226 liveuser 9372
 
3 liveuser 9373
								#置換原始符合條件字串的路徑字串陣列
9374
								$extendPath=$newExtendPath;
226 liveuser 9375
 
3 liveuser 9376
								}#if end
226 liveuser 9377
 
3 liveuser 9378
							#反之找不到後續符合的路徑
9379
							else{
226 liveuser 9380
 
3 liveuser 9381
								$extendPath=array();
226 liveuser 9382
 
3 liveuser 9383
								}#else end
226 liveuser 9384
 
3 liveuser 9385
							}#else end
226 liveuser 9386
 
3 liveuser 9387
					}#else end
226 liveuser 9388
 
3 liveuser 9389
				}#foreach end
226 liveuser 9390
 
3 liveuser 9391
			}#if end
226 liveuser 9392
 
3 liveuser 9393
		#反之沒有含有「*」
9394
		else{
226 liveuser 9395
 
3 liveuser 9396
			#判斷 $conf["path"] 是否存在
9397
			#函式說明:
9398
			#檢查多個檔案與資料夾是否存在.
9399
			#回傳的結果:
9400
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
9401
			#$result["error"],錯誤訊息陣列.
9402
			#$resutl["function"],當前執行的涵式名稱.
9403
			#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
9404
			#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
9405
			#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
9406
			#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
9407
			#必填參數:
9408
			#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
9409
			$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["path"]);
9410
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
9411
			$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
9412
			#可省略參數
9413
			#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
9414
			#$conf["disableWebSearch"]="false";
9415
			#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
9416
			#$conf["userDir"]="true";
9417
			#參考資料來源:
9418
			#http://php.net/manual/en/function.file-exists.php
9419
			#http://php.net/manual/en/control-structures.foreach.php
9420
			#備註:
9421
			#函數file_exists檢查的路徑為檔案系統的路徑
9422
			$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
9423
			unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 9424
 
3 liveuser 9425
			#如果檢查失敗
9426
			if($checkMultiFileExist["status"]=="false"){
226 liveuser 9427
 
3 liveuser 9428
				#設置錯誤識別
9429
				$result["status"]="false";
226 liveuser 9430
 
3 liveuser 9431
				#設置錯誤訊息
9432
				$result["error"]=$checkMultiFileExist;
226 liveuser 9433
 
3 liveuser 9434
				#回傳結果
9435
				return $result;
226 liveuser 9436
 
3 liveuser 9437
				}#if end
226 liveuser 9438
 
3 liveuser 9439
			#如果存在
9440
			if($checkMultiFileExist["varExist"][0]=="true"){
226 liveuser 9441
 
3 liveuser 9442
				#初始化暫存展開後的檔案路徑字串
9443
				$extendPath=array($conf["path"]);
226 liveuser 9444
 
3 liveuser 9445
				}#if end
226 liveuser 9446
 
3 liveuser 9447
			#反之不存在
9448
			else{
226 liveuser 9449
 
3 liveuser 9450
				#置換符合的路徑為空字串
9451
				$extendPath=array();
226 liveuser 9452
 
3 liveuser 9453
				}#else end
226 liveuser 9454
 
3 liveuser 9455
			#初始化暫存展開後的檔案路徑字串
9456
			$extendPath=array($conf["path"]);
226 liveuser 9457
 
3 liveuser 9458
			}#else end
226 liveuser 9459
 
3 liveuser 9460
		#取得解析完「*」的檔案路徑字串
9461
		$result["content"]=$extendPath;
226 liveuser 9462
 
3 liveuser 9463
		#取得有幾個檔案路徑
9464
		$result["pathCount"]=count($result["content"]);
226 liveuser 9465
 
3 liveuser 9466
		#設置執行正常
9467
		$result["status"]="true";
226 liveuser 9468
 
3 liveuser 9469
		#回傳結果
9470
		return $result;
226 liveuser 9471
 
3 liveuser 9472
		}#function resolvePostionStringWhichContainStarSymbol end
9473
 
9474
	/*
9475
	#函式說明:
9476
	#將含有「*」的多個檔案路徑名稱,變成多個符合條件的路徑檔案.
9477
	#回傳結果:
9478
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
9479
	#$result["error"],錯誤訊息陣列.
226 liveuser 9480
	#$result["function"],函數名稱.
3 liveuser 9481
	#$result["content"],字串陣列,多個解析回來的檔案路徑字串.
9482
	#$result["pathCount"],整數,有幾個路徑.
9483
	#必填參數:
9484
	#$conf["path"],字串陣列,要解析含有「*」的檔案路徑字串.
9485
	$conf["path"]=array();
9486
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
9487
	$conf["fileArgu"]=__FILE__;
9488
	#可省略參數:
9489
	#$conf["noDotStart"],字串,"true"代表不包含「.」開頭的名稱,預設為"false"代表包含「.」開頭的名稱.
9490
	#$conf["noDotStart"]="true";
9491
	#$conf["noWaveEnd"],字串,預設為"true"代表不包含「~」結尾的名稱,"false"代表包含結尾為「~」的名稱.
9492
	#$conf["noWaveEnd"]="true";
9493
	#參考資料:
9494
	#無.
9495
	#備註:
9496
	#無.
9497
	*/
9498
	public static function resolveMultiPostionStringWhichContainStarSymbol(&$conf){
226 liveuser 9499
 
3 liveuser 9500
		#初始化要回傳的結果
9501
		$result=array();
226 liveuser 9502
 
3 liveuser 9503
		#設置當其函數名稱
9504
		$result["function"]=__FUNCTION__;
226 liveuser 9505
 
3 liveuser 9506
		#如果 $conf 不為陣列
9507
		if(gettype($conf)!="array"){
226 liveuser 9508
 
3 liveuser 9509
			#設置執行失敗
9510
			$result["status"]="false";
226 liveuser 9511
 
3 liveuser 9512
			#設置執行錯誤訊息
9513
			$result["error"][]="\$conf變數須為陣列形態";
9514
 
9515
			#如果傳入的參數為 null
9516
			if($conf==null){
226 liveuser 9517
 
3 liveuser 9518
				#設置執行錯誤訊息
9519
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 9520
 
3 liveuser 9521
				}#if end
9522
 
9523
			#回傳結果
9524
			return $result;
226 liveuser 9525
 
3 liveuser 9526
			}#if end
226 liveuser 9527
 
3 liveuser 9528
		#檢查參數
9529
		#函式說明:
9530
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
9531
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9532
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
9533
		#$result["function"],當前執行的函式名稱.
9534
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
9535
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
9536
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
9537
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
9538
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
9539
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
9540
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
9541
		#必填寫的參數:
9542
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
9543
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
9544
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
9545
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","fileArgu");
226 liveuser 9546
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 9547
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
9548
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
9549
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
9550
		#可以省略的參數:
9551
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
9552
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
9553
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
9554
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("noDotStart","noWaveEnd");
226 liveuser 9555
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 9556
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
9557
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
9558
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","true");
9559
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
9560
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
9561
		#參考資料來源:
9562
		#array_keys=>http://php.net/manual/en/function.array-keys.php
9563
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
9564
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 9565
 
3 liveuser 9566
		#如果 $checkResult["status"] 等於 "fasle"
9567
		if($checkResult["status"]=="false"){
226 liveuser 9568
 
3 liveuser 9569
			#設置錯誤識別
9570
			$result["status"]="false";
226 liveuser 9571
 
3 liveuser 9572
			#設置錯誤訊息
9573
			$result["error"]=$checkResult;
226 liveuser 9574
 
3 liveuser 9575
			#回傳結果
9576
			return $result;
226 liveuser 9577
 
3 liveuser 9578
			}#if end
226 liveuser 9579
 
3 liveuser 9580
		#如果 $checkResult["passed"] 等於 "fasle"
9581
		if($checkResult["passed"]=="false"){
226 liveuser 9582
 
3 liveuser 9583
			#設置錯誤識別
9584
			$result["status"]="false";
226 liveuser 9585
 
3 liveuser 9586
			#設置錯誤訊息
9587
			$result["error"]=$checkResult;
226 liveuser 9588
 
3 liveuser 9589
			#回傳結果
9590
			return $result;
226 liveuser 9591
 
3 liveuser 9592
			}#if end
226 liveuser 9593
 
3 liveuser 9594
		#針對每個要解析的路徑字串
9595
		foreach($conf["path"] as $path){
226 liveuser 9596
 
3 liveuser 9597
			#函式說明:
9598
			#將含有「*」的檔案路徑名稱,變成多個符合條件的路徑檔案.
9599
			#回傳結果:
9600
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
9601
			#$result["error"],錯誤訊息陣列.
226 liveuser 9602
			#$result["function"],函數名稱.
3 liveuser 9603
			#$result["content"],字串陣列,多個解析回來的檔案路徑字串.
9604
			#必填參數:
9605
			#$conf["path"],字串,要解析含有「*」的檔案路徑字串.
9606
			$conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]["path"]=$path;
9607
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
9608
			$conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]["fileArgu"]=$conf["fileArgu"];
9609
			#可省略參數:
9610
			#$conf["noDotStart"],字串,"true"代表不包含「.」開頭的名稱,預設為"false"代表包含「.」開頭的名稱.
9611
			$conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]["noDotStart"]=$conf["noDotStart"];
9612
			#$conf["noWaveEnd"],字串,預設為"true"代表不包含「~」結尾的名稱,"false"代表包含結尾為「~」的名稱.
9613
			$conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]["noWaveEnd"]=$conf["noWaveEnd"];
9614
			$resolvePostionStringWhichContainStarSymbol=fileAccess::resolvePostionStringWhichContainStarSymbol($conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]);
9615
			unset($conf["fileAccess::resolvePostionStringWhichContainStarSymbol"]);
226 liveuser 9616
 
3 liveuser 9617
			#如果解析失敗
9618
			if($resolvePostionStringWhichContainStarSymbol["status"]=="false"){
226 liveuser 9619
 
3 liveuser 9620
				#設置錯誤識別
9621
				$result["status"]="false";
226 liveuser 9622
 
3 liveuser 9623
				#設置錯誤訊息
9624
				$result["error"]=$resolvePostionStringWhichContainStarSymbol;
226 liveuser 9625
 
3 liveuser 9626
				#回傳結果
9627
				return $result;
226 liveuser 9628
 
3 liveuser 9629
				}#if end
226 liveuser 9630
 
3 liveuser 9631
			#針對每個解析出來的路徑
9632
			foreach($resolvePostionStringWhichContainStarSymbol["content"] as $filteredPath){
226 liveuser 9633
 
3 liveuser 9634
				#儲存符合條件的路徑
9635
				$result["content"][]=$filteredPath;
226 liveuser 9636
 
3 liveuser 9637
				}#foreach end
226 liveuser 9638
 
3 liveuser 9639
			}#foreach end
226 liveuser 9640
 
3 liveuser 9641
		#如果有路徑存在
9642
		if(isset($result["content"])){
226 liveuser 9643
 
3 liveuser 9644
			#取得有幾個路徑
9645
			$result["pathCount"]=count($result["content"]);
226 liveuser 9646
 
3 liveuser 9647
			}#if end
226 liveuser 9648
 
9649
		#反之
3 liveuser 9650
		else{
226 liveuser 9651
 
3 liveuser 9652
			#設置空的路徑結果
9653
			$result["content"]=array();
226 liveuser 9654
 
3 liveuser 9655
			#取得有幾個路徑
9656
			$result["pathCount"]=count($result["content"]);
226 liveuser 9657
 
3 liveuser 9658
			}#else end
226 liveuser 9659
 
3 liveuser 9660
		#設置執行正常
9661
		$result["status"]="true";
226 liveuser 9662
 
3 liveuser 9663
		#回傳結果
9664
		return $result;
226 liveuser 9665
 
3 liveuser 9666
		}#function resolveMultiPostionStringWhichContainStarSymbol end
9667
 
9668
	/*
9669
	#函式說明:
9670
	#將多個路徑字串變成相對於當前路徑的相對路徑字串
9671
	#回傳結果:
9672
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
9673
	#$result["error"],錯誤訊息陣列.
226 liveuser 9674
	#$result["function"],函數名稱.
3 liveuser 9675
	#$result["argu"],使用的參數.
9676
	#$result["content"],字串陣列,多個轉換好的相對路徑字串.
9677
	#$result["cmd"],使用的指令.
9678
	#必填參數:
9679
	#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
9680
	$conf["path"]=array();
9681
	#$conf["fileArgu"],字串,當前路徑.
9682
	$conf["fileArgu"]=__FILE__;
9683
	#可省略參數:
9684
	#$conf["baseFrom"],字串,指定要依據哪個位置為起點的起始位置,預設不指定,代表使用當前路徑.
9685
	#$conf["baseFrom"]="";
9686
	#參考資料:
9687
	#無.
9688
	#備註:
9689
	#無.
9690
	*/
9691
	public static function getRelativePath(&$conf){
226 liveuser 9692
 
3 liveuser 9693
		#初始化要回傳的結果
9694
		$result=array();
226 liveuser 9695
 
3 liveuser 9696
		#設置當其函數名稱
9697
		$result["function"]=__FUNCTION__;
226 liveuser 9698
 
3 liveuser 9699
		#如果 $conf 不為陣列
9700
		if(gettype($conf)!="array"){
226 liveuser 9701
 
3 liveuser 9702
			#設置執行失敗
9703
			$result["status"]="false";
226 liveuser 9704
 
3 liveuser 9705
			#設置執行錯誤訊息
9706
			$result["error"][]="\$conf變數須為陣列形態";
9707
 
9708
			#如果傳入的參數為 null
9709
			if($conf==null){
226 liveuser 9710
 
3 liveuser 9711
				#設置執行錯誤訊息
9712
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 9713
 
3 liveuser 9714
				}#if end
9715
 
9716
			#回傳結果
9717
			return $result;
226 liveuser 9718
 
3 liveuser 9719
			}#if end
226 liveuser 9720
 
3 liveuser 9721
		#檢查參數
9722
		#函式說明:
9723
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
9724
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9725
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
9726
		#$result["function"],當前執行的函式名稱.
9727
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
9728
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
9729
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
9730
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
9731
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
9732
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
9733
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
9734
		#必填寫的參數:
9735
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
9736
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
9737
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
9738
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","fileArgu");
226 liveuser 9739
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 9740
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
9741
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
9742
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
9743
		#可以省略的參數:
9744
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
9745
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
9746
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
9747
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("baseFrom");
226 liveuser 9748
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 9749
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
9750
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
9751
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
9752
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
9753
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
9754
		#參考資料來源:
9755
		#array_keys=>http://php.net/manual/en/function.array-keys.php
9756
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
9757
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 9758
 
3 liveuser 9759
		#如果 $checkResult["status"] 等於 "false"
9760
		if($checkResult["status"]=="false"){
226 liveuser 9761
 
3 liveuser 9762
			#設置錯誤識別
9763
			$result["status"]="false";
226 liveuser 9764
 
3 liveuser 9765
			#設置錯誤訊息
9766
			$result["error"]=$checkResult;
226 liveuser 9767
 
3 liveuser 9768
			#回傳結果
9769
			return $result;
226 liveuser 9770
 
3 liveuser 9771
			}#if end
226 liveuser 9772
 
3 liveuser 9773
		#如果 $checkResult["passed"] 等於 "fasle"
9774
		if($checkResult["passed"]=="false"){
226 liveuser 9775
 
3 liveuser 9776
			#設置錯誤識別
9777
			$result["status"]="false";
226 liveuser 9778
 
3 liveuser 9779
			#設置錯誤訊息
9780
			$result["error"]=$checkResult;
226 liveuser 9781
 
3 liveuser 9782
			#回傳結果
9783
			return $result;
226 liveuser 9784
 
3 liveuser 9785
			}#if end
226 liveuser 9786
 
3 liveuser 9787
		#取得參數
9788
		$result["argu"]=$conf;
226 liveuser 9789
 
3 liveuser 9790
		#函式說明:
9791
		#將固定格式的字串分開,並回傳分開的結果.
9792
		#回傳結果:
9793
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9794
		#$result["error"],錯誤訊息陣列
9795
		#$result["function"],當前執行的函數名稱.
9796
		#$result["argu"],使用的參數.
9797
		#$result["oriStr"],要分割的原始字串內容
9798
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
9799
		#$result["dataCounts"],爲總共分成幾段
9800
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
9801
		#必填參數:
9802
		#$conf["stringIn"],字串,要處理的字串.
9803
		$conf["fileAccess::spiltString"]["stringIn"]=$conf["fileArgu"];
9804
		#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
9805
		$conf["fileAccess::spiltString"]["spiltSymbol"]="/";
9806
		#可省略參數:
9807
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
9808
		$conf["fileAccess::spiltString"]["allowEmptyStr"]="false";
9809
		#參考資料:
9810
		#無.
9811
		#備註:
9812
		#無.
9813
		$spiltString=stringProcess::spiltString($conf["fileAccess::spiltString"]);
9814
		unset($conf["fileAccess::spiltString"]);
226 liveuser 9815
 
3 liveuser 9816
		#如果執行失敗
9817
		if($spiltString["status"]==="false"){
226 liveuser 9818
 
3 liveuser 9819
			#設置錯誤識別
9820
			$result["status"]="false";
226 liveuser 9821
 
3 liveuser 9822
			#設置錯誤訊息
9823
			$result["error"]=$spiltString;
226 liveuser 9824
 
3 liveuser 9825
			#回傳結果
9826
			return $result;
226 liveuser 9827
 
3 liveuser 9828
			}#if end
226 liveuser 9829
 
3 liveuser 9830
		#如果沒有關鍵字
9831
		if($spiltString["found"]==="false"){
226 liveuser 9832
 
3 liveuser 9833
			#設置錯誤識別
9834
			$result["status"]="false";
226 liveuser 9835
 
3 liveuser 9836
			#設置錯誤訊息
9837
			$result["error"]=$spiltString;
226 liveuser 9838
 
3 liveuser 9839
			#回傳結果
9840
			return $result;
226 liveuser 9841
 
3 liveuser 9842
			}#if end
226 liveuser 9843
 
3 liveuser 9844
		#取得 $conf["fileArgu"] 的路徑
9845
		#函式說明:
9846
		#將固定格式的字串分開,並回傳分開的結果.
9847
		#回傳結果:
9848
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9849
		#$result["error"],錯誤訊息陣列
9850
		#$result["function"],當前執行的函數名稱.
9851
		#$result["argu"],使用的參數.
9852
		#$result["oriStr"],要分割的原始字串內容
9853
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
9854
		#$result["dataCounts"],爲總共分成幾段
9855
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
9856
		#必填參數:
9857
		#$conf["stringIn"],字串,要處理的字串.
9858
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["fileArgu"];
9859
		#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
9860
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";
9861
		#可省略參數:
9862
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
9863
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
9864
		#參考資料:
9865
		#無.
9866
		#備註:
9867
		#無.
9868
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
9869
		unset($conf["stringProcess::spiltString"]);
226 liveuser 9870
 
3 liveuser 9871
		#如果執行失敗
9872
		if($spiltString["status"]==="false"){
226 liveuser 9873
 
3 liveuser 9874
			#設置錯誤識別
9875
			$result["status"]="false";
226 liveuser 9876
 
3 liveuser 9877
			#設置錯誤訊息
9878
			$result["error"]=$spiltString;
226 liveuser 9879
 
3 liveuser 9880
			#回傳結果
9881
			return $result;
226 liveuser 9882
 
3 liveuser 9883
			}#if end
226 liveuser 9884
 
3 liveuser 9885
		/*
9886
		#break point
9887
		var_dump($spiltString);
9888
		exit;
9889
		*/
226 liveuser 9890
 
3 liveuser 9891
		#預設 fileArgu 的路徑為 ""
9892
		$fileArguPath="";
226 liveuser 9893
 
3 liveuser 9894
		#針對每個目錄
9895
		for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 9896
 
3 liveuser 9897
			#串接路徑
9898
			$fileArguPath=$fileArguPath."/".$spiltString["dataArray"][$i];
226 liveuser 9899
 
3 liveuser 9900
			}#for end
226 liveuser 9901
 
3 liveuser 9902
		#取得相對於目標的當前位置
9903
		#函式說明:
9904
		#呼叫shell執行系統命令,並取得回傳的內容.
9905
		#回傳結果:
9906
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9907
		#$result["error"],錯誤訊息陣列.
9908
		#$result["function"],當前執行的函數名稱.
9909
		#$result["argu"],使用的參數.
9910
		#$result["cmd"],執行的指令內容.
9911
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
9912
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
9913
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
9914
		#$result["running"],是否還在執行.
9915
		#$result["pid"],pid.
9916
		#$result["statusCode"],執行結束後的代碼.
9917
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
9918
		#必填參數:
9919
		#$conf["command"],字串,要執行的指令.
9920
		$conf["external::callShell"]["command"]="cd";
9921
		#$conf["fileArgu"],字串,變數__FILE__的內容.
9922
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
9923
		#可省略參數:
9924
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
9925
		$conf["external::callShell"]["argu"]=array($fileArguPath,";","pwd");
9926
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
9927
		#$conf["arguIsAddr"]=array();
9928
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
9929
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
9930
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
9931
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
9932
		#$conf["enablePrintDescription"]="true";
9933
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
9934
		#$conf["printDescription"]="";
9935
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
9936
		$conf["external::callShell"]["escapeshellarg"]="true";
9937
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
9938
		#$conf["thereIsShellVar"]=array();
9939
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
9940
		#$conf["username"]="";
9941
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
9942
		#$conf["password"]="";
9943
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
9944
		#$conf["useScript"]="";
9945
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
9946
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
9947
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
9948
		#$conf["inBackGround"]="";
9949
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
9950
		#$conf["getErr"]="false";
9951
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
9952
		#$conf["doNotRun"]="false";
9953
		#參考資料:
9954
		#exec=>http://php.net/manual/en/function.exec.php
9955
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
9956
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
9957
		#備註:
9958
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
9959
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
9960
		$callShell=external::callShell($conf["external::callShell"]);
9961
		unset($conf["external::callShell"]);
226 liveuser 9962
 
3 liveuser 9963
		#如果執行失敗
9964
		if($callShell["status"]==="false"){
226 liveuser 9965
 
3 liveuser 9966
			#設置錯誤識別
9967
			$result["status"]="false";
226 liveuser 9968
 
3 liveuser 9969
			#設置錯誤訊息
9970
			$result["error"]=$callShell;
226 liveuser 9971
 
3 liveuser 9972
			#回傳結果
9973
			return $result;
226 liveuser 9974
 
3 liveuser 9975
			}#if end
226 liveuser 9976
 
3 liveuser 9977
		#如果執行失敗
9978
		if(!isset($callShell["output"][0])){
226 liveuser 9979
 
3 liveuser 9980
			#設置錯誤識別
9981
			$result["status"]="false";
226 liveuser 9982
 
3 liveuser 9983
			#設置錯誤訊息
9984
			$result["error"]=$callShell;
226 liveuser 9985
 
3 liveuser 9986
			#回傳結果
9987
			return $result;
226 liveuser 9988
 
9989
			}#if end
9990
 
3 liveuser 9991
		/*
9992
		#break point
9993
		var_dump($callShell);
9994
		exit;
9995
		*/
226 liveuser 9996
 
3 liveuser 9997
		#記錄執行的指令
9998
		$result["cmd"][]=$callShell["cmd"];
226 liveuser 9999
 
3 liveuser 10000
		#保存相對於目標的當前位置
10001
		$pwd=$callShell["output"][0];
226 liveuser 10002
 
3 liveuser 10003
		#更新 fileArgu
10004
		$conf["fileArgu"]=$pwd."/".$spiltString["dataArray"][$spiltString["dataCounts"]-1];
226 liveuser 10005
 
3 liveuser 10006
		#針對每個 $conf["path"]
10007
		foreach($conf["path"] as $path){
226 liveuser 10008
 
3 liveuser 10009
			#將 $path 變成易讀的格式
10010
			#函式說明:
10011
			#將檔案目錄的絕對位置中的 "../" 剔除變成直觀的路徑.
10012
			#回傳的結果:
10013
			#$result["status"],執行是否成功,"true"代表執行成功,"false"代表執行失敗.
10014
			#$result["function"],當前執行的函數.
10015
			#$result["error"],錯誤訊息陣列.
10016
			#$result["changedPath"],處理完後回傳的目錄字串.
10017
			#$result["oriPath"],原始的路徑字串
10018
			#必填參數:
10019
			#$conf["dirStr"],字串,要處理的檔案目錄字串.
10020
			$conf["stringProcess::changeDirByDotDotSolidus"]["dirStr"]=$path;
10021
			$changeDirByDotDotSolidus=stringProcess::changeDirByDotDotSolidus($conf["stringProcess::changeDirByDotDotSolidus"]);
10022
			unset($conf["stringProcess::changeDirByDotDotSolidus"]);
226 liveuser 10023
 
3 liveuser 10024
			#如果處理失敗
10025
			if($changeDirByDotDotSolidus["status"]==="false"){
226 liveuser 10026
 
3 liveuser 10027
				#設置錯誤識別
10028
				$result["status"]="false";
226 liveuser 10029
 
3 liveuser 10030
				#設置錯誤訊息
10031
				$result["error"]=$changeDirByDotDotSolidus;
226 liveuser 10032
 
3 liveuser 10033
				#回傳結果
10034
				return $result;
226 liveuser 10035
 
3 liveuser 10036
				}#if end
226 liveuser 10037
 
3 liveuser 10038
			#取得易讀的路徑
10039
			$path=$changeDirByDotDotSolidus["changedPath"];
226 liveuser 10040
 
3 liveuser 10041
			#判斷 $path 是否為絕對路徑
10042
			#函式說明:
10043
			#取得符合特定字首與字尾的字串
10044
			#回傳結果:
10045
			#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
10046
			#$result["function"],當前執行的函數名稱.
10047
			#$result["error"],錯誤訊息陣列.
10048
			#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
10049
			#$result["returnString"],爲符合字首條件的字串內容。
10050
			#必填參數:
10051
			#$conf["checkString"],字串,要檢查的字串.
10052
			$conf["search::getMeetConditionsString"]["checkString"]=$path;
10053
			#可省略參數:
10054
			#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
10055
			$conf["search::getMeetConditionsString"]["frontWord"]="/";
10056
			#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
10057
			#$conf["tailWord"]="";
10058
			#參考資料:
10059
			#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
10060
			$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
226 liveuser 10061
			unset($conf["search::getMeetConditionsString"]);
10062
 
3 liveuser 10063
			#如果檢查失敗
10064
			if($getMeetConditionsString["status"]=="false"){
226 liveuser 10065
 
3 liveuser 10066
				#設置錯誤識別
10067
				$result["status"]="false";
226 liveuser 10068
 
3 liveuser 10069
				#設置錯誤訊息
10070
				$result["error"]=$getMeetConditionsString;
226 liveuser 10071
 
3 liveuser 10072
				#回傳結果
10073
				return $result;
226 liveuser 10074
 
3 liveuser 10075
				}#if end
226 liveuser 10076
 
3 liveuser 10077
			#如果沒有「/」開頭
10078
			if($getMeetConditionsString["founded"]==="false"){
226 liveuser 10079
 
3 liveuser 10080
				#將 $conf["fileArgu"] 最後面的檔案或目錄名稱剔除
10081
				#函式說明:
10082
				#將固定格式的字串分開,並回傳分開的結果。
10083
				#回傳結果:
10084
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10085
				#$result["error"],錯誤訊息陣列
10086
				#$result["function"],當前執行的函數名稱.
10087
				#$result["oriStr"],要分割的原始字串內容
10088
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
10089
				#$result["dataCounts"],爲總共分成幾段
10090
				#必填參數:
10091
				$conf["stringProcess::spiltString"]["stringIn"]=$conf["fileArgu"];#要處理的字串。
10092
				$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
10093
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
10094
				unset($conf["stringProcess::spiltString"]);
226 liveuser 10095
 
3 liveuser 10096
				#如果分割字串失敗
10097
				if($spiltString["status"]=="false"){
226 liveuser 10098
 
3 liveuser 10099
					#設置錯誤識別
10100
					$result["status"]="false";
226 liveuser 10101
 
3 liveuser 10102
					#設置錯誤訊息
10103
					$result["error"]=$spiltString;
226 liveuser 10104
 
3 liveuser 10105
					#回傳結果
10106
					return $result;
226 liveuser 10107
 
3 liveuser 10108
					}#if end
226 liveuser 10109
 
3 liveuser 10110
				#初始化相對路徑為開頭片段""
10111
				$relativePathPart="/";
226 liveuser 10112
 
3 liveuser 10113
				#剔除最後一段
10114
				for($i=0;$i<$spiltString["dataCounts"]-1;$i++){
226 liveuser 10115
 
3 liveuser 10116
					#串接起來
10117
					$relativePathPart=$relativePathPart.$spiltString["dataArray"][$i]."/";
226 liveuser 10118
 
3 liveuser 10119
					}#for end
226 liveuser 10120
 
3 liveuser 10121
				#如果有設定 baseFrom
10122
				if(isset($conf["baseFrom"])){
226 liveuser 10123
 
3 liveuser 10124
					#函式說明:
10125
					#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
10126
					#回傳結果:
10127
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
10128
					#$result["error"],錯誤訊息陣列.
226 liveuser 10129
					#$result["function"],函數名稱.
3 liveuser 10130
					#$result["argu"],使用的參數.
10131
					#$result["content"],網址,若是在命令列執行,則為"null".
10132
					#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
10133
					#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
10134
					#必填參數:
10135
					#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
10136
					$conf["fileAccess::getInternetAddressV2"]["address"]=$path;
10137
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
10138
					$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
10139
					#可省略參數:
10140
					#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
10141
					$conf["fileAccess::getInternetAddressV2"]["web"]="false";
10142
					#參考資料:
10143
					#無.
10144
					#備註:
10145
					#無.
10146
					$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
10147
					unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 10148
 
3 liveuser 10149
					##var_dump(__LINE__." ".print_r($getInternetAddressV2,true));
226 liveuser 10150
 
3 liveuser 10151
					#如果執行失敗
10152
					if($getInternetAddressV2["status"]==="false"){
226 liveuser 10153
 
3 liveuser 10154
						#設置錯誤識別
10155
						$result["status"]="false";
226 liveuser 10156
 
3 liveuser 10157
						#設置錯誤訊息
10158
						$result["error"]=$getInternetAddressV2;
226 liveuser 10159
 
3 liveuser 10160
						#回傳結果
10161
						return $result;
226 liveuser 10162
 
3 liveuser 10163
						}#if end
226 liveuser 10164
 
3 liveuser 10165
					#取得絕對位置
10166
					$path=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 10167
 
3 liveuser 10168
					#函式說明:
10169
					#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
10170
					#回傳結果:
10171
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
10172
					#$result["error"],錯誤訊息陣列.
226 liveuser 10173
					#$result["function"],函數名稱.
3 liveuser 10174
					#$result["argu"],使用的參數.
10175
					#$result["content"],網址,若是在命令列執行,則為"null".
10176
					#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
10177
					#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
10178
					#必填參數:
10179
					#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
10180
					$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["baseFrom"];
10181
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
10182
					$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
10183
					#可省略參數:
10184
					#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
10185
					$conf["fileAccess::getInternetAddressV2"]["web"]="false";
10186
					#參考資料:
10187
					#無.
10188
					#備註:
10189
					#無.
10190
					$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
10191
					unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 10192
 
3 liveuser 10193
					#var_dump(__LINE__." ".print_r($getInternetAddressV2,true));
226 liveuser 10194
 
3 liveuser 10195
					#如果執行失敗
10196
					if($getInternetAddressV2["status"]==="false"){
226 liveuser 10197
 
3 liveuser 10198
						#設置錯誤識別
10199
						$result["status"]="false";
226 liveuser 10200
 
3 liveuser 10201
						#設置錯誤訊息
10202
						$result["error"]=$getInternetAddressV2;
226 liveuser 10203
 
3 liveuser 10204
						#回傳結果
10205
						return $result;
226 liveuser 10206
 
3 liveuser 10207
						}#if end
226 liveuser 10208
 
3 liveuser 10209
					#取得絕對位置
10210
					$conf["baseFrom"]=$getInternetAddressV2["fileSystemAbsoulutePosition"];
226 liveuser 10211
 
3 liveuser 10212
					#函式說明:
10213
					#將多個路徑字串變成相對於當前路徑的相對路徑字串
10214
					#回傳結果:
10215
					#$result["status"],"true"爲建立成功,"false"爲建立失敗.
10216
					#$result["error"],錯誤訊息陣列.
226 liveuser 10217
					#$result["function"],函數名稱.
3 liveuser 10218
					#$result["argu"],使用的參數.
10219
					#$result["content"],字串陣列,多個轉換好的相對路徑字串.
10220
					#必填參數:
10221
					#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
10222
					$conf["fileAccess::getRelativePath"]["path"]=array($path);
10223
					#$conf["fileArgu"],字串,當前路徑.
10224
					$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["baseFrom"]."/name";
10225
					#可省略參數:
10226
					#$conf["baseFrom"],字串,指定要依據哪個位置為起點的起始位置,預設不指定,代表使用當前路徑.
10227
					#$conf["baseFrom"]="";
10228
					#參考資料:
10229
					#無.
10230
					#備註:
10231
					#無.
10232
					$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
10233
					unset($conf["fileAccess::getRelativePath"]);
226 liveuser 10234
 
3 liveuser 10235
					#var_dump(__LINE__." ".print_r($getRelativePath,true));
226 liveuser 10236
 
3 liveuser 10237
					#如果執行失敗
10238
					if($getRelativePath["status"]==="false"){
226 liveuser 10239
 
3 liveuser 10240
						#設置錯誤識別
10241
						$result["status"]="false";
226 liveuser 10242
 
3 liveuser 10243
						#設置錯誤訊息
10244
						$result["error"]=$getRelativePath;
226 liveuser 10245
 
3 liveuser 10246
						#回傳結果
10247
						return $result;
226 liveuser 10248
 
3 liveuser 10249
						}#if end
226 liveuser 10250
 
3 liveuser 10251
					#取得轉換好的絕對路徑
10252
					$relativePathPart=$getRelativePath["content"][0]."/";
226 liveuser 10253
 
3 liveuser 10254
					#清空path,避免出錯
10255
					$path="";
226 liveuser 10256
 
3 liveuser 10257
					}#if end
226 liveuser 10258
 
3 liveuser 10259
				#轉換成易讀的相對路徑
10260
				#函式說明:
10261
				#將檔案目錄的絕對位置中的 "../" 剔除變成直觀的路徑.
10262
				#回傳的結果:
10263
				#$result["status"],執行是否成功,"true"代表執行成功,"false"代表執行失敗.
10264
				#$result["function"],當前執行的函數.
10265
				#$result["error"],錯誤訊息陣列.
10266
				#$result["changedPath"],處理完後回傳的目錄字串.
10267
				#$result["oriPath"],原始的路徑字串
10268
				#必填參數:
10269
				#$conf["dirStr"],字串,要處理的檔案目錄字串.
10270
				$conf["stringProcess::changeDirByDotDotSolidus"]["dirStr"]=$relativePathPart.$path;
10271
				$changeDirByDotDotSolidus=stringProcess::changeDirByDotDotSolidus($conf["stringProcess::changeDirByDotDotSolidus"]);
10272
				unset($conf["stringProcess::changeDirByDotDotSolidus"]);
226 liveuser 10273
 
10274
				#var_dump($changeDirByDotDotSolidus);
10275
 
3 liveuser 10276
				#如果轉換失敗
10277
				if($changeDirByDotDotSolidus["status"]=="false"){
226 liveuser 10278
 
3 liveuser 10279
					#設置錯誤識別
10280
					$result["status"]="false";
226 liveuser 10281
 
3 liveuser 10282
					#設置錯誤訊息
10283
					$result["error"]=$changeDirByDotDotSolidus;
226 liveuser 10284
 
3 liveuser 10285
					#回傳結果
10286
					return $result;
226 liveuser 10287
 
3 liveuser 10288
					}#if end
226 liveuser 10289
 
3 liveuser 10290
				#轉換為相對路徑
10291
				#函式說明:
10292
				#將多個路徑字串變成相對於當前路徑的相對路徑字串
10293
				#回傳結果:
10294
				#$result["status"],"true"爲建立成功,"false"爲建立失敗.
10295
				#$result["error"],錯誤訊息陣列.
226 liveuser 10296
				#$result["function"],函數名稱.
3 liveuser 10297
				#$result["content"],字串陣列,多個轉換好的相對路徑字串.
10298
				#必填參數:
10299
				#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
10300
				$conf["fileAccess::getRelativePath"]["path"]=array($changeDirByDotDotSolidus["changedPath"]);
10301
				#$conf["fileArgu"],字串,當前路徑.
10302
				$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
10303
				$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
10304
				unset($conf["fileAccess::getRelativePath"]);
226 liveuser 10305
 
10306
				#var_dump($getRelativePath);
10307
 
3 liveuser 10308
				#如果轉換路徑失敗
10309
				if($getRelativePath["status"]==="false"){
226 liveuser 10310
 
3 liveuser 10311
					#設置錯誤識別
10312
					$result["status"]="false";
226 liveuser 10313
 
3 liveuser 10314
					#設置錯誤訊息
10315
					$result["error"]=$changeDirByDotDotSolidus;
226 liveuser 10316
 
3 liveuser 10317
					#回傳結果
10318
					return $result;
226 liveuser 10319
 
3 liveuser 10320
					}#if end
226 liveuser 10321
 
3 liveuser 10322
				#取得相對路徑
10323
				$result["content"][]=$getRelativePath["content"][0];
226 liveuser 10324
 
3 liveuser 10325
				}#if end
226 liveuser 10326
 
3 liveuser 10327
			#反之有「/」開頭
10328
			else{
10329
				#函式說明:
10330
				#移除多個絕對路徑字串開頭相同的部分
10331
				#回傳結果:
10332
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10333
				#$result["error"],錯誤訊息陣列.
10334
				#$result["function"],當前執行的函數名稱.
10335
				#$result["content"],處理好的的字串內容.
10336
				#必填參數:
10337
				#$conf["pathIn"],字串陣列,每個要處理的絕對路徑字串.
226 liveuser 10338
				$conf["fileAccess::delSamePathHead"]["pathIn"]=array($path,$conf["fileArgu"]);
3 liveuser 10339
				$delSamePathHead=fileAccess::delSamePathHead($conf["fileAccess::delSamePathHead"]);
10340
				unset($conf["fileAccess::delSamePathHead"]);
226 liveuser 10341
 
3 liveuser 10342
				#var_dump($delSamePathHead);
226 liveuser 10343
 
3 liveuser 10344
				#如果移除多個絕對路徑字串開頭相同的部分失敗
10345
				if($delSamePathHead["status"]==="false"){
226 liveuser 10346
 
3 liveuser 10347
					#設置錯誤識別
10348
					$result["status"]="false";
226 liveuser 10349
 
3 liveuser 10350
					#設置錯誤訊息
10351
					$result["error"]=$delSameHead;
226 liveuser 10352
 
3 liveuser 10353
					#回傳結果
10354
					return $result;
226 liveuser 10355
 
3 liveuser 10356
					}#if end
226 liveuser 10357
 
3 liveuser 10358
				#如果 $conf["fileArgu"] 剩下空
10359
				if($delSamePathHead["content"][1]===""){
226 liveuser 10360
 
3 liveuser 10361
					#檢查 $delSamePathHead[0] 開頭是否為「/」
10362
					#函式說明:
10363
					#取得符合特定字首與字尾的字串
10364
					#回傳結果:
10365
					#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
10366
					#$result["function"],當前執行的函數名稱.
10367
					#$result["error"],錯誤訊息陣列.
10368
					#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
10369
					#$result["returnString"],爲符合字首條件的字串內容。
10370
					#必填參數:
10371
					#$conf["checkString"],字串,要檢查的字串.
10372
					$conf["search::getMeetConditionsString"]["checkString"]=$delSamePathHead["content"][0];
10373
					#可省略參數:
10374
					#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
10375
					$conf["search::getMeetConditionsString"]["frontWord"]="/";
10376
					#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
10377
					#$conf["tailWord"]="";
10378
					#參考資料:
10379
					#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
10380
					$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
10381
					unset($conf["search::getMeetConditionsString"]);
226 liveuser 10382
 
3 liveuser 10383
					#如果檢查失敗
10384
					if($getMeetConditionsString["status"]=="false"){
226 liveuser 10385
 
3 liveuser 10386
						#設置錯誤識別
10387
						$result["status"]="false";
226 liveuser 10388
 
3 liveuser 10389
						#設置錯誤訊息
10390
						$result["error"]=$getMeetConditionsString;
226 liveuser 10391
 
3 liveuser 10392
						#回傳結果
10393
						return $result;
226 liveuser 10394
 
3 liveuser 10395
						}#if end
226 liveuser 10396
 
3 liveuser 10397
					#如果有開頭有「/」
10398
					if($getMeetConditionsString["founded"]==="true"){
226 liveuser 10399
 
3 liveuser 10400
						#函式說明:
10401
						#將字串特定關鍵字與其前面的內容剔除
10402
						#回傳結果:
10403
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10404
						#$result["error"],錯誤訊息陣列.
10405
						#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
10406
						#$result["function"],當前執行的函數名稱.
10407
						#$result["oriStr"],要處理的原始字串內容.
10408
						#$result["content"],處理好的的字串內容.
10409
						#必填參數:
10410
						$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$delSamePathHead["content"][0];#要處理的字串.
10411
						$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="/";#特定字串.
10412
						$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
10413
						unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 10414
 
3 liveuser 10415
						#如果 將字串特定關鍵字與其前面的內容剔除 失敗
10416
						if($delStrBeforeKeyWord["status"]=="false"){
226 liveuser 10417
 
3 liveuser 10418
							#設置錯誤識別
10419
							$result["status"]="false";
226 liveuser 10420
 
3 liveuser 10421
							#設置錯誤訊息
10422
							$result["error"]=$delStrBeforeKeyWord;
226 liveuser 10423
 
3 liveuser 10424
							#回傳結果
10425
							return $result;
226 liveuser 10426
 
3 liveuser 10427
							}#if end
226 liveuser 10428
 
3 liveuser 10429
						#取得相對位置
10430
						$result["content"][]=$delStrBeforeKeyWord["content"];
226 liveuser 10431
 
3 liveuser 10432
						}#if end
226 liveuser 10433
 
3 liveuser 10434
					#反之
10435
					else{
226 liveuser 10436
 
3 liveuser 10437
						#取得相對位置
10438
						$result["content"][]=$delSamePathHead["content"][0];
226 liveuser 10439
 
10440
						}#else end
10441
 
3 liveuser 10442
					}#if end
226 liveuser 10443
 
3 liveuser 10444
				#反之剩下的 $conf["fileArgu"] 不為空
10445
				else{
226 liveuser 10446
 
3 liveuser 10447
					#檢查 $delSamePathHead["content"][1] 有幾個「/」
10448
					#函式說明:
10449
					#檢查字串裡面有無指定的關鍵字
10450
					#回傳結果:
10451
					#$result["status"],"true"代表執行成功,"false"代表執行失敗。
10452
					#$result["error"],錯誤訊息
10453
					#$result["function"],當前執行的函數名稱.
10454
					#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
10455
					#$result["keyWordCount"],找到的關鍵字數量.
10456
					#必填參數:
10457
					$conf["search::findKeyWord"]["keyWord"]="/";#想要搜尋的關鍵字
10458
					$conf["search::findKeyWord"]["string"]=$delSamePathHead["content"][1];#要被搜尋的字串內容
10459
					#可省略參數:
10460
					#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
10461
					$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
10462
					unset($conf["search::findKeyWord"]);
226 liveuser 10463
 
3 liveuser 10464
					#如果 檢查字串裡面有無指定的關鍵字 失敗
10465
					if($findKeyWord["status"]==="false"){
226 liveuser 10466
 
3 liveuser 10467
						#設置錯誤識別
10468
						$result["status"]="false";
226 liveuser 10469
 
3 liveuser 10470
						#設置錯誤訊息
10471
						$result["error"]=$findKeyWord;
226 liveuser 10472
 
3 liveuser 10473
						#回傳結果
10474
						return $result;
226 liveuser 10475
 
3 liveuser 10476
						}#if end
226 liveuser 10477
 
3 liveuser 10478
					#有幾個「/」就執行幾次
10479
					for($i=0;$i<$findKeyWord["keyWordCount"];$i++){
226 liveuser 10480
 
3 liveuser 10481
						#在前面加上 "../"
10482
						$delSamePathHead["content"][0]="../".$delSamePathHead["content"][0];
226 liveuser 10483
 
3 liveuser 10484
						}#for end
226 liveuser 10485
 
3 liveuser 10486
					#取得相對位置
10487
					$result["content"][]=$delSamePathHead["content"][0];
226 liveuser 10488
 
3 liveuser 10489
					}#else end
226 liveuser 10490
 
3 liveuser 10491
				}#else end
226 liveuser 10492
 
3 liveuser 10493
			}#foreach end
226 liveuser 10494
 
3 liveuser 10495
		#設置執行正常
10496
		$result["status"]="true";
226 liveuser 10497
 
3 liveuser 10498
		#回傳結果
10499
		return $result;
226 liveuser 10500
 
3 liveuser 10501
		}#function getRelativeParh end
10502
 
10503
	/*
10504
	#函式說明:
10505
	#移除多個絕對路徑字串開頭相同的部分
10506
	#回傳結果:
10507
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10508
	#$result["error"],錯誤訊息陣列.
10509
	#$result["function"],當前執行的函數名稱.
10510
	#$result["argu"],參數.
10511
	#$result["content"],處理好的的字串內容.
10512
	#必填參數:
10513
	#$conf["pathIn"],字串陣列,每個要處理的絕對路徑字串.
226 liveuser 10514
	$conf["pathIn"]=array();
3 liveuser 10515
	#可省略參數:
10516
	#無
10517
	#參考資料:
10518
	#無.
10519
	#備註:
10520
	#無.
10521
	*/
10522
	public static function delSamePathHead(&$conf){
226 liveuser 10523
 
3 liveuser 10524
		#初始化要回傳的結果
10525
		$result=array();
10526
 
10527
		#取得當前執行的函數名稱
10528
		$result["function"]=__FUNCTION__;
10529
 
10530
		#如果沒有參數
10531
		if(func_num_args()==0){
226 liveuser 10532
 
3 liveuser 10533
			#設置執行失敗
10534
			$result["status"]="false";
226 liveuser 10535
 
3 liveuser 10536
			#設置執行錯誤訊息
10537
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 10538
 
3 liveuser 10539
			#回傳結果
10540
			return $result;
226 liveuser 10541
 
3 liveuser 10542
			}#if end
10543
 
10544
		#如果 $conf 不為陣列
10545
		if(gettype($conf)!="array"){
226 liveuser 10546
 
3 liveuser 10547
			#設置執行失敗
10548
			$result["status"]="false";
226 liveuser 10549
 
3 liveuser 10550
			#設置執行錯誤訊息
10551
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 10552
 
3 liveuser 10553
			#如果傳入的參數為 null
10554
			if($conf==null){
226 liveuser 10555
 
3 liveuser 10556
				#設置執行錯誤訊息
10557
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 10558
 
3 liveuser 10559
				}#if end
10560
 
10561
			#回傳結果
10562
			return $result;
226 liveuser 10563
 
3 liveuser 10564
			}#if end
226 liveuser 10565
 
3 liveuser 10566
		#取得參數
226 liveuser 10567
		$result["argv"]=$conf;
10568
 
3 liveuser 10569
		#檢查參數
10570
		#函式說明:
10571
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
10572
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10573
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
10574
		#$result["function"],當前執行的函式名稱.
10575
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
10576
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
10577
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
10578
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
10579
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
10580
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
10581
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
10582
		#必填寫的參數:
10583
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
10584
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
10585
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
10586
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("pathIn");
226 liveuser 10587
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 10588
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
10589
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
10590
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
10591
		#可以省略的參數:
10592
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
10593
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
10594
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
10595
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileToRead","output");
226 liveuser 10596
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 10597
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
10598
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
10599
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("help","help");
10600
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
10601
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
10602
		#參考資料來源:
10603
		#array_keys=>http://php.net/manual/en/function.array-keys.php
10604
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
10605
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 10606
 
3 liveuser 10607
		#如果 $checkResult["status"] 等於 "fasle"
10608
		if($checkResult["status"]=="false"){
226 liveuser 10609
 
3 liveuser 10610
			#設置錯誤識別
10611
			$result["status"]="false";
226 liveuser 10612
 
3 liveuser 10613
			#設置錯誤訊息
10614
			$result["error"]=$checkResult;
226 liveuser 10615
 
3 liveuser 10616
			#回傳結果
10617
			return $result;
226 liveuser 10618
 
3 liveuser 10619
			}#if end
226 liveuser 10620
 
3 liveuser 10621
		#如果 $checkResult["passed"] 等於 "fasle"
10622
		if($checkResult["passed"]=="false"){
226 liveuser 10623
 
3 liveuser 10624
			#設置錯誤識別
10625
			$result["status"]="false";
226 liveuser 10626
 
3 liveuser 10627
			#設置錯誤訊息
10628
			$result["error"]=$checkResult;
226 liveuser 10629
 
3 liveuser 10630
			#回傳結果
10631
			return $result;
226 liveuser 10632
 
3 liveuser 10633
			}#if end
226 liveuser 10634
 
3 liveuser 10635
		#檢查是否都為絕對路徑
10636
		#函式說明:
10637
		#取得多個符合特定字首與字尾的字串.
10638
		#回傳結果:
10639
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
10640
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
10641
		#$result["function"],當前執行的函數名稱.
10642
		#$result["returnString"],爲符合字首條件的字串陣列內容。
10643
		#必填參數:
10644
		#$conf["checkString"],陣列字串,要檢查的字串們.
10645
		$conf["search::getMeetConditionsStringMulti"]["checkString"]=$conf["pathIn"];#要檢查的字串陣列
10646
		#可省略參數:
10647
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
10648
		$conf["search::getMeetConditionsStringMulti"]["frontWord"]="/";
10649
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
10650
		#$conf["tailWord"]="";
10651
		#參考資料:
10652
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
10653
		$getMeetConditionsStringMulti=search::getMeetConditionsStringMulti($conf["search::getMeetConditionsStringMulti"]);
10654
		unset($conf["search::getMeetConditionsStringMulti"]);
226 liveuser 10655
 
3 liveuser 10656
		#如果檢測是否為絕對路徑失敗
10657
		if($getMeetConditionsStringMulti["status"]=="false"){
226 liveuser 10658
 
3 liveuser 10659
			#設置錯誤識別
10660
			$result["status"]="false";
226 liveuser 10661
 
3 liveuser 10662
			#設置錯誤訊息
10663
			$result["error"]=$getMeetConditionsStringMulti;
226 liveuser 10664
 
3 liveuser 10665
			#增加額外的錯誤訊息
10666
			$result["error"][]="僅接受絕對路徑字串";
226 liveuser 10667
 
3 liveuser 10668
			#回傳結果
10669
			return $result;
226 liveuser 10670
 
3 liveuser 10671
			}#if end
226 liveuser 10672
 
3 liveuser 10673
		#函式說明:
10674
		#將多個固定格式的字串分開,並回傳分開的結果
10675
		#回傳的參數:
10676
		#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
10677
		#$result["error"],錯誤訊息陣列.
10678
		#$result["function"],當前執行的函數名稱.
10679
		#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
10680
		#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
10681
		#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
10682
		#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
10683
		#必填參數:
10684
		#$conf["stringIn"],字串陣列,要處理的字串陣列.
10685
		$conf["stringProcess::spiltMutiString"]["stringIn"]=$conf["pathIn"];
10686
		#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
10687
		$conf["stringProcess::spiltMutiString"]["spiltSymbol"]="/";
10688
		$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
226 liveuser 10689
 
3 liveuser 10690
		#如果分割所有路徑字串失敗
10691
		if($spiltMutiString["status"]=="false"){
226 liveuser 10692
 
3 liveuser 10693
			#設置錯誤識別
10694
			$result["status"]="false";
226 liveuser 10695
 
3 liveuser 10696
			#設置錯誤訊息
226 liveuser 10697
			$result["error"]=$spiltMutiString;
10698
 
3 liveuser 10699
			#回傳結果
10700
			return $result;
226 liveuser 10701
 
3 liveuser 10702
			}#if end
226 liveuser 10703
 
3 liveuser 10704
		#初始化暫存每個路徑分割成的段數
226 liveuser 10705
		$spiltedPathCount=array();
10706
 
3 liveuser 10707
		#取得每個路徑分割成的段數
10708
		#針對每個 $spiltMutiString["spiltString"]
10709
		for($i=0;$i<count($spiltMutiString["spiltString"]);$i++){
226 liveuser 10710
 
3 liveuser 10711
			$spiltedPathCount[]=$spiltMutiString["spiltString"][$i]["dataCounts"];
226 liveuser 10712
 
3 liveuser 10713
			}#for end
226 liveuser 10714
 
3 liveuser 10715
		#取得所有路徑字串分割後的最小數量
10716
		#涵式說明
10717
		#找最小值,結果會回傳最小值
10718
		#回傳的內容
10719
		#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
10720
		#$result["error"],錯誤訊息陣列.
10721
		#$result["function"],當前執行的函數名稱.
10722
		#$result["key"],最大值原先的key.
10723
		#$result["value"],陣列裏面最小的數值.
10724
		#必填參數:
10725
		$conf["math::getMinValue"]["rawDataArray"]=$spiltedPathCount;#爲原始數據
10726
		$getMinValue=math::getMinValue($conf["math::getMinValue"]);
10727
		unset($conf["math::getMinValue"]);
226 liveuser 10728
 
3 liveuser 10729
		#如果取得最小數值失敗
10730
		if($getMinValue["status"]=="false"){
226 liveuser 10731
 
3 liveuser 10732
			#設置錯誤識別
10733
			$result["status"]="false";
226 liveuser 10734
 
3 liveuser 10735
			#設置錯誤訊息
226 liveuser 10736
			$result["error"]=$getMinValue;
10737
 
3 liveuser 10738
			#回傳結果
10739
			return $result;
226 liveuser 10740
 
10741
			}#if end
10742
 
3 liveuser 10743
		#初始化暫存每個路徑字串的前面幾個片段是相同的
10744
		$samePartCount=0;
226 liveuser 10745
 
10746
		#var_dump($getMinValue["value"]);
10747
 
3 liveuser 10748
		#依據所有路徑字串分割後的最小數量
10749
		for($j=0;$j<$getMinValue["value"];$j++){
226 liveuser 10750
 
3 liveuser 10751
			#初始化暫存第一個路徑的片段字串
10752
			$firstPathPart="";
226 liveuser 10753
 
3 liveuser 10754
			#針對每個 $spiltMutiString["spiltString"]
10755
			for($i=0;$i<count($spiltMutiString["spiltString"]);$i++){
226 liveuser 10756
 
3 liveuser 10757
				#暫存分割的字串
10758
				$spiltedPath=$spiltMutiString["spiltString"][$i];
226 liveuser 10759
 
3 liveuser 10760
				#如果是第一個路徑
10761
				if($i==0){
226 liveuser 10762
 
3 liveuser 10763
					#取得第一個路徑的片段字串
10764
					$firstPathPart=$spiltedPath["dataArray"][$j];
226 liveuser 10765
 
10766
					}#if end
10767
 
3 liveuser 10768
				#如果第$i+1個路徑片段不跟第1個路徑的片段字串一樣
10769
				if($spiltedPath["dataArray"][$j]!=$firstPathPart){
226 liveuser 10770
 
3 liveuser 10771
					#讓最外層迴圈中止
10772
					$getMinValue["value"]=-1;
226 liveuser 10773
 
3 liveuser 10774
					#跳出迴圈
10775
					break;
226 liveuser 10776
 
10777
					}#if end
10778
 
3 liveuser 10779
				}#for end
226 liveuser 10780
 
3 liveuser 10781
			#代表每個路徑字串的第$j段是一樣的.
10782
			$samePartCount=$j;
226 liveuser 10783
 
3 liveuser 10784
			}#for end
226 liveuser 10785
 
3 liveuser 10786
		#var_dump($samePartCount);
226 liveuser 10787
 
3 liveuser 10788
		#依據每個路徑
226 liveuser 10789
		for($i=0;$i<count($spiltMutiString["spiltString"]);$i++){
10790
 
3 liveuser 10791
			#初始化儲存第$i+1個處理好的路徑字串
226 liveuser 10792
			$result["content"][$i]="";
10793
 
3 liveuser 10794
			#依據 $samePartCount 與 路徑的段數
10795
			for($j=$samePartCount;$j<$spiltMutiString["spiltString"][$i]["dataCounts"];$j++){
226 liveuser 10796
 
3 liveuser 10797
				#如果不是第一段
10798
				if($j!=$samePartCount){
226 liveuser 10799
 
3 liveuser 10800
					#組裝每個路徑片段
10801
					$result["content"][$i]=$result["content"][$i]."/".$spiltMutiString["spiltString"][$i]["dataArray"][$j];
226 liveuser 10802
 
3 liveuser 10803
					}#if end
226 liveuser 10804
 
3 liveuser 10805
				#反之為第一段
10806
				else{
226 liveuser 10807
 
3 liveuser 10808
					#組裝每個路徑片段
10809
					$result["content"][$i]=$result["content"][$i].$spiltMutiString["spiltString"][$i]["dataArray"][$j];
226 liveuser 10810
 
3 liveuser 10811
					}#else end
226 liveuser 10812
 
3 liveuser 10813
				}#for end
226 liveuser 10814
 
3 liveuser 10815
			}#for end
226 liveuser 10816
 
3 liveuser 10817
		#設置執行正常
10818
		$result["status"]="true";
226 liveuser 10819
 
3 liveuser 10820
		#回傳結果
10821
		return $result;
226 liveuser 10822
 
3 liveuser 10823
		}#function delSamePathHead end
10824
 
10825
	/*
10826
	#函式說明:
226 liveuser 10827
	#於本套件位置底下的tmp資料夾下建立與回傳暫存檔案名稱路徑
3 liveuser 10828
	#回傳結果:
10829
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10830
	#$result["error"],錯誤訊息.
10831
	#$result["function"],當前執行的函數名稱.
10832
	#$result["content"],暫存檔案的路徑與名稱.
10833
	#$result["fileName"],暫存檔案的名稱.
10834
	#$result["path"],暫存檔案的路徑.
10835
	#必填參數:
10836
	#無.
10837
	#可省略參數:
36 liveuser 10838
	#$conf["content"],陣列,每行檔案的內容,預設為空陣列,不寫入任何資料.
10839
	#$conf["contant"]=array();
3 liveuser 10840
	#參考資料:
10841
	#無.
10842
	#備註:
10843
	#無.
10844
	*/
36 liveuser 10845
	public static function createTempFile(&$conf){
226 liveuser 10846
 
3 liveuser 10847
		#初始化要回傳的結果
10848
		$result=array();
10849
 
10850
		#取得當前執行的函數名稱
10851
		$result["function"]=__FUNCTION__;
226 liveuser 10852
 
36 liveuser 10853
		#取得參數
10854
		$result["argu"]=$conf;
10855
 
10856
		#如果 $conf 不為陣列
10857
		if(gettype($conf)!="array"){
10858
 
10859
			#設置執行失敗
10860
			$result["status"]="false";
10861
 
10862
			#設置執行錯誤訊息
10863
			$result["error"][]="\$conf變數須為陣列形態";
10864
 
10865
			#如果傳入的參數為 null
10866
			if(is_null($conf)){
10867
 
10868
				#設置執行錯誤訊息
10869
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
10870
 
10871
				}#if end
10872
 
10873
			#回傳結果
10874
			return $result;
10875
 
10876
			}#if end
226 liveuser 10877
 
36 liveuser 10878
		#檢查參數
10879
		#函式說明:
10880
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
10881
		#回傳結果:
10882
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10883
		#$result["error"],執行不正常結束的錯訊息陣列.
10884
		#$result["simpleError"],簡單表示的錯誤訊息.
10885
		#$result["function"],當前執行的函式名稱.
10886
		#$result["argu"],設置給予的參數.
10887
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
10888
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
10889
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
10890
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
10891
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
10892
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
10893
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
10894
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
10895
		#必填參數:
10896
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
10897
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
10898
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
10899
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
10900
		#可省略參數:
10901
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
10902
		#$conf["mustBeFilledVariableName"]=array();
10903
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
10904
		#$conf["mustBeFilledVariableType"]=array();
10905
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
10906
		#$conf["canBeEmptyString"]="false";
10907
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
10908
		#$conf["canNotBeEmpty"]=array();
10909
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
10910
		#$conf["canBeEmpty"]=array();
10911
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
10912
		#$conf["skipableVariableCanNotBeEmpty"]=array();
10913
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
10914
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("content");
10915
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
10916
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
10917
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
10918
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(array());
10919
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
10920
		#$conf["disallowAllSkipableVarIsEmpty"]="";
10921
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
10922
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
10923
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
10924
		#$conf["disallowAllSkipableVarNotExist"]="";
10925
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
10926
		#$conf["arrayCountEqualCheck"][]=array();
10927
		#參考資料:
10928
		#array_keys=>http://php.net/manual/en/function.array-keys.php
10929
		#備註:
10930
		#無.
10931
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
10932
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 10933
 
36 liveuser 10934
		#如果執行失敗
10935
		if($checkArguments["status"]==="false"){
226 liveuser 10936
 
36 liveuser 10937
			#設置執行異常
10938
			$result["status"]="false";
226 liveuser 10939
 
36 liveuser 10940
			#設置錯誤訊息
10941
			$result["error"]=$checkArguments;
226 liveuser 10942
 
36 liveuser 10943
			#回傳結果
10944
			return $result;
226 liveuser 10945
 
36 liveuser 10946
			}#if end
226 liveuser 10947
 
36 liveuser 10948
		#如果檢查不通過
10949
		if($checkArguments["passed"]==="false"){
226 liveuser 10950
 
36 liveuser 10951
			#設置執行異常
10952
			$result["status"]="false";
226 liveuser 10953
 
36 liveuser 10954
			#設置錯誤訊息
10955
			$result["error"]=$checkArguments;
226 liveuser 10956
 
36 liveuser 10957
			#回傳結果
10958
			return $result;
226 liveuser 10959
 
36 liveuser 10960
			}#if end
226 liveuser 10961
 
3 liveuser 10962
		#取得相對於當前路徑的  tmp 目錄.
10963
		exec("cd ".pathinfo(__FILE__)["dirname"]."/../../../var/qbpwcf/tmp;pwd;",$output,$status);
226 liveuser 10964
 
3 liveuser 10965
		#如果執行失敗
10966
		if($status!==0){
226 liveuser 10967
 
3 liveuser 10968
			#設置執行失敗
10969
			$result["status"]="false";
10970
 
10971
			#設置執行錯誤訊息
10972
			$result["error"][]="取得暫存目錄失敗";
226 liveuser 10973
 
3 liveuser 10974
			#回傳結果
10975
			return $result;
226 liveuser 10976
 
10977
			}#if end
10978
 
3 liveuser 10979
		#設置預設的暫存目錄
226 liveuser 10980
		$defaultTmpDir=$output[0];
10981
 
3 liveuser 10982
		#取得暫存檔案的路徑與名稱
10983
		$result["content"]=tempnam($defaultTmpDir,"qbpwcf_tmpfile_");
226 liveuser 10984
 
42 liveuser 10985
		#如果產生的暫存檔案位置異常
10986
		#參考資料:
10987
		#https://www.php.net/manual/en/function.tempnam.php
10988
		if(strpos("/tmp/",$result["content"])===0){
226 liveuser 10989
 
42 liveuser 10990
			#設置執行失敗
10991
			$result["status"]="false";
10992
 
10993
			#設置執行錯誤訊息
10994
			$result["error"][]="於暫存目錄建立檔案失敗";
226 liveuser 10995
 
42 liveuser 10996
			#回傳結果
10997
			return $result;
226 liveuser 10998
 
42 liveuser 10999
			}#if end
226 liveuser 11000
 
3 liveuser 11001
		#函式說明:
11002
		#將字串特定關鍵字與其前面的內容剔除
11003
		#回傳結果:
11004
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11005
		#$result["error"],錯誤訊息陣列.
11006
		#$result["warning"],警告訊息鎮列.
11007
		#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
11008
		#$result["function"],當前執行的函數名稱.
11009
		#$result["argu"],使用的參數.
11010
		#$result["oriStr"],要處理的原始字串內容.
226 liveuser 11011
		#$result["content"],處理好的的字串內容.
3 liveuser 11012
		#必填參數:
11013
		#$conf["stringIn"],字串,要處理的字串.
11014
		$conf["stringPorcess::delStrBeforeKeyWord"]["stringIn"]=$result["content"];
11015
		#$conf["keyWord"],字串,特定字串.
42 liveuser 11016
		$conf["stringPorcess::delStrBeforeKeyWord"]["keyWord"]=$defaultTmpDir."/";
3 liveuser 11017
		#可省略參數:
11018
		#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
42 liveuser 11019
		$conf["stringPorcess::delStrBeforeKeyWord"]["recursive"]="true";
3 liveuser 11020
		#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
11021
		#$conf["lastResult"]=$delStrBeforeKeyWord;
11022
		#參考資料:
11023
		#無.
11024
		#備註:
11025
		#無.
11026
		$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringPorcess::delStrBeforeKeyWord"]);
11027
		unset($conf["stringPorcess::delStrBeforeKeyWord"]);
226 liveuser 11028
 
3 liveuser 11029
		#如果執行失敗
11030
		if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 11031
 
3 liveuser 11032
			#設置執行失敗
11033
			$result["status"]="false";
11034
 
11035
			#設置執行錯誤訊息
11036
			$result["error"]=$delStrBeforeKeyWord;
226 liveuser 11037
 
3 liveuser 11038
			#回傳結果
11039
			return $result;
226 liveuser 11040
 
3 liveuser 11041
			}#if end
226 liveuser 11042
 
3 liveuser 11043
		#如果應該要存在的路徑關鍵字不在
11044
		if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 11045
 
3 liveuser 11046
			#設置執行失敗
11047
			$result["status"]="false";
11048
 
11049
			#設置執行錯誤訊息
11050
			$result["error"]=$delStrBeforeKeyWord;
226 liveuser 11051
 
3 liveuser 11052
			#回傳結果
11053
			return $result;
226 liveuser 11054
 
3 liveuser 11055
			}#if end
226 liveuser 11056
 
3 liveuser 11057
		#取得檔案名稱
11058
		$result["fileName"]=$delStrBeforeKeyWord["content"];
226 liveuser 11059
 
3 liveuser 11060
		#函式說明:
11061
		#將字串特定關鍵字與其後面的內容剔除
11062
		#回傳結果:
11063
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11064
		#$result["error"],錯誤訊息陣列.
11065
		#$result["warning"],警告訊息鎮列.
11066
		#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
11067
		#$result["function"],當前執行的函數名稱.
11068
		#$result["oriStr"],要處理的原始字串內容.
11069
		#$result["content"],處理好的的字串內容.
11070
		#$result["argu"],使用的參數.
11071
		#必填參數:
11072
		#$conf["stringIn"],字串,要處理的字串.
11073
		$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$result["content"];
11074
		#$conf["keyWord"],字串,特定字串.
11075
		$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=$result["fileName"];
11076
		#可省略參數:
11077
		#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
11078
		#$conf["deleteLastRepeatedOne"]="";
11079
		#參考資料:
11080
		#無.
11081
		#備註:
11082
		#無.
11083
		$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
11084
		unset($conf["stringProcess::delStrAfterKeyWord"]);
226 liveuser 11085
 
3 liveuser 11086
		#如果執行失敗
11087
		if($delStrAfterKeyWord["status"]==="false"){
226 liveuser 11088
 
3 liveuser 11089
			#設置執行失敗
11090
			$result["status"]="false";
11091
 
11092
			#設置執行錯誤訊息
11093
			$result["error"]=$delStrAfterKeyWord;
226 liveuser 11094
 
3 liveuser 11095
			#回傳結果
11096
			return $result;
226 liveuser 11097
 
3 liveuser 11098
			}#if end
226 liveuser 11099
 
3 liveuser 11100
		#如果應該要存在的檔案名稱關鍵字不在
11101
		if($delStrAfterKeyWord["founded"]==="false"){
226 liveuser 11102
 
3 liveuser 11103
			#設置執行失敗
11104
			$result["status"]="false";
11105
 
11106
			#設置執行錯誤訊息
11107
			$result["error"]=$delStrAfterKeyWord;
226 liveuser 11108
 
3 liveuser 11109
			#回傳結果
11110
			return $result;
226 liveuser 11111
 
3 liveuser 11112
			}#if end
226 liveuser 11113
 
3 liveuser 11114
		#取得路徑
11115
		$result["path"]=$delStrAfterKeyWord["content"];
226 liveuser 11116
 
36 liveuser 11117
		#如果有內容要寫入
11118
		if(!empty($conf["content"])){
226 liveuser 11119
 
36 liveuser 11120
			#函式說明:
11121
			#將多行字串寫入到檔案
11122
			#回傳結果:
11123
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
11124
			#$result["error"],錯誤訊息陣列.
11125
			#$result["function"],當前執行函數的名稱.
11126
			#必填參數:
11127
			#$conf["fileName"],字串,爲要編輯的檔案名稱
11128
			$conf["fileAccess::writeMultiLine"]["fileName"]=$result["content"];
11129
			#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
11130
			$conf["fileAccess::writeMultiLine"]["inputString"]=$conf["content"];
11131
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
11132
			$conf["fileAccess::writeMultiLine"]["fileArgu"]=__FILE__;
11133
			#可省略參數:
11134
			#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
11135
			#參考資料:
11136
			#無.
11137
			#備註:
11138
			#無.
11139
			$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
11140
			unset($conf["fileAccess::writeMultiLine"]);
226 liveuser 11141
 
36 liveuser 11142
			#如果執行失敗
11143
			if($writeMultiLine["status"]==="false"){
226 liveuser 11144
 
36 liveuser 11145
				#設置執行失敗
11146
				$result["status"]="false";
11147
 
11148
				#設置執行錯誤訊息
11149
				$result["error"]=$writeMultiLine;
226 liveuser 11150
 
36 liveuser 11151
				#回傳結果
11152
				return $result;
226 liveuser 11153
 
36 liveuser 11154
				}#if end
226 liveuser 11155
 
36 liveuser 11156
			}#if end
226 liveuser 11157
 
3 liveuser 11158
		#設置執行正常
11159
		$result["status"]="true";
226 liveuser 11160
 
3 liveuser 11161
		#回傳結果
11162
		return $result;
226 liveuser 11163
 
3 liveuser 11164
		}#function createTempFile end
11165
 
11166
	/*
11167
	#函式說明:
11168
	#分割檔案,分割出來的檔案名稱編號為aa, ab ac...ba, bb, bc...,zx, zy, zz的順序.
11169
	#回傳結果:
11170
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
11171
	#$result["error"],錯誤訊息陣列.
11172
	#$result["function"],當前執行的函數名稱.
11173
	#$result["cmd"],執行的指令.
11174
	#$result["content"],執行指令回傳的結果.
11175
	#必填參數:
11176
	#$conf["file"],字串,要分割的檔案名稱.
226 liveuser 11177
	$conf["file"]="";
3 liveuser 11178
	#可省略參數:
11179
	#$conf["splitNameHead"],字串,分割成檔案的名稱開頭,預設為 $conf["file"]."-" .
226 liveuser 11180
	#$conf["splitNameHead"]="";
3 liveuser 11181
	#$conf["partSize"],字串,分割檔的大小為多少?可以為XMB,XGB,XKB,可參見split指令的說明,預設為50MB.
11182
	#$conf["partSize"]="";
11183
	#參考資料:
11184
	#無.
11185
	#備註:
11186
	#需要有split指令
11187
	*/
11188
	public static function split(&$conf=array()){
226 liveuser 11189
 
3 liveuser 11190
		#初始化要回傳的結果
11191
		$result=array();
11192
 
11193
		#取得當前執行的函數名稱
11194
		$result["function"]=__FUNCTION__;
11195
 
11196
		#如果沒有參數
11197
		if(func_num_args()==0){
226 liveuser 11198
 
3 liveuser 11199
			#設置執行失敗
11200
			$result["status"]="false";
226 liveuser 11201
 
3 liveuser 11202
			#設置執行錯誤訊息
11203
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 11204
 
3 liveuser 11205
			#回傳結果
11206
			return $result;
226 liveuser 11207
 
3 liveuser 11208
			}#if end
11209
 
11210
		#函式說明:
11211
		#判斷當前環境為web還是cmd
11212
		#回傳結果:
11213
		#$result,"web"或"cmd"
11214
		if(csInformation::getEnv()==="web"){
226 liveuser 11215
 
3 liveuser 11216
			#設置執行失敗
11217
			$result["status"]="false";
226 liveuser 11218
 
3 liveuser 11219
			#設置執行錯誤訊息
11220
			$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
226 liveuser 11221
 
3 liveuser 11222
			#回傳結果
11223
			return $result;
226 liveuser 11224
 
3 liveuser 11225
			}#if end
226 liveuser 11226
 
3 liveuser 11227
		#取得參數
11228
		$result["argu"]=$conf;
11229
 
11230
		#如果 $conf 不為陣列
11231
		if(gettype($conf)!=="array"){
226 liveuser 11232
 
3 liveuser 11233
			#設置執行失敗
11234
			$result["status"]="false";
226 liveuser 11235
 
3 liveuser 11236
			#設置執行錯誤訊息
11237
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 11238
 
3 liveuser 11239
			#如果傳入的參數為 null
11240
			if($conf===null){
226 liveuser 11241
 
3 liveuser 11242
				#設置執行錯誤訊息
11243
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 11244
 
3 liveuser 11245
				}#if end
11246
 
11247
			#回傳結果
11248
			return $result;
226 liveuser 11249
 
3 liveuser 11250
			}#if end
226 liveuser 11251
 
3 liveuser 11252
		#檢查參數
11253
		#函式說明:
11254
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
11255
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11256
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
11257
		#$result["function"],當前執行的函式名稱.
11258
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
11259
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
11260
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
11261
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
11262
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
11263
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
11264
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
11265
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
11266
		#必填寫的參數:
11267
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
11268
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
11269
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
11270
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file");
11271
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
11272
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
11273
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
11274
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
11275
		#可以省略的參數:
11276
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
11277
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
11278
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
11279
		#$conf["canNotBeEmpty"]=array();
11280
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
11281
		#$conf["canBeEmpty"]=array();
11282
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
11283
		#$conf["skipableVariableCanNotBeEmpty"]=array();
11284
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
11285
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("splitNameHead","partSize");
226 liveuser 11286
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 11287
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
11288
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]",若後面需要加上內容,則可以再補上\",後面再補上要串接的內容.
11289
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("\$conf[\"file\"]\"-","50MB");
11290
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
11291
		#$conf["arrayCountEqualCheck"][]=array();
11292
		#參考資料來源:
11293
		#array_keys=>http://php.net/manual/en/function.array-keys.php
11294
		#建議:
11295
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
11296
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
11297
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 11298
 
3 liveuser 11299
		#如果檢查參數失敗
11300
		if($checkArguments["status"]==="false"){
226 liveuser 11301
 
3 liveuser 11302
			#設置執行失敗
11303
			$result["status"]="false";
226 liveuser 11304
 
3 liveuser 11305
			#設置錯誤訊息
11306
			$result["error"]=$checkArguments;
226 liveuser 11307
 
3 liveuser 11308
			#回傳結果
11309
			return $result;
226 liveuser 11310
 
3 liveuser 11311
			}#if end
226 liveuser 11312
 
3 liveuser 11313
		#如果要分割的檔案存在
11314
		if(file_exists($conf["file"])){
226 liveuser 11315
 
3 liveuser 11316
			#取得執行的指令
11317
			$result["cmd"]="split -b ".$conf["partSize"]." '".$conf["file"]."' '".$conf["splitNameHead"]."'";
11318
 
11319
			#執行還原的指令
11320
			exec($result["cmd"],$output,$status);
11321
 
11322
			#取得執行後的輸出
11323
			$result["content"]=$output;
226 liveuser 11324
 
3 liveuser 11325
			}#if end
226 liveuser 11326
 
3 liveuser 11327
		#反之
11328
		else{
226 liveuser 11329
 
3 liveuser 11330
			#設置執行失敗
11331
			$result["status"]="false";
226 liveuser 11332
 
3 liveuser 11333
			#設置執行錯誤訊息
11334
			$result["error"][]="要分割的檔案「".$conf["file"]."」不存在";
226 liveuser 11335
 
3 liveuser 11336
			#回傳結果
11337
			return $result;
226 liveuser 11338
 
3 liveuser 11339
			}#else end
226 liveuser 11340
 
3 liveuser 11341
		#設置執行正常
11342
		$result["status"]="true";
226 liveuser 11343
 
3 liveuser 11344
		#回傳結果
11345
		return $result;
226 liveuser 11346
 
3 liveuser 11347
		}#function split end
11348
 
11349
	/*
11350
	#函式說明:
11351
	#合併檔案,檔案編號為aa, ab ac...ba, bb, bc...,zx, zy, zz的順序.
11352
	#回傳結果:
11353
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
11354
	#$result["error"],錯誤訊息陣列.
11355
	#$result["function"],當前執行的函數名稱.
11356
	#$result["cmd"],執行的指令.
11357
	#$result["content"],執行指令回傳的結果.
11358
	#必填參數:
11359
	#$conf["filePartHead"],字串,分割檔案的名稱開頭.
11360
	$conf["filePartHead"]="";
11361
	#$conf["oriFileName"],字串,合併後的檔案名稱.
11362
	$conf["oriFileName"]="";
11363
	#可省略參數:
11364
	#無
11365
	#參考資料:
11366
	#無.
11367
	#備註:
11368
	#需要有cat指令.
11369
	#僅能在命令列執行.
11370
	*/
11371
	public static function merge(&$conf=array()){
226 liveuser 11372
 
3 liveuser 11373
		#初始化要回傳的結果
11374
		$result=array();
11375
 
11376
		#取得當前執行的函數名稱
11377
		$result["function"]=__FUNCTION__;
11378
 
11379
		#如果沒有參數
11380
		if(func_num_args()==0){
226 liveuser 11381
 
3 liveuser 11382
			#設置執行失敗
11383
			$result["status"]="false";
226 liveuser 11384
 
3 liveuser 11385
			#設置執行錯誤訊息
11386
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 11387
 
3 liveuser 11388
			#回傳結果
11389
			return $result;
226 liveuser 11390
 
3 liveuser 11391
			}#if end
11392
 
11393
		#函式說明:
11394
		#判斷當前環境為web還是cmd
11395
		#回傳結果:
11396
		#$result,"web"或"cmd"
11397
		if(csInformation::getEnv()==="web"){
226 liveuser 11398
 
3 liveuser 11399
			#設置執行失敗
11400
			$result["status"]="false";
226 liveuser 11401
 
3 liveuser 11402
			#設置執行錯誤訊息
11403
			$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
226 liveuser 11404
 
3 liveuser 11405
			#回傳結果
11406
			return $result;
226 liveuser 11407
 
3 liveuser 11408
			}#if end
226 liveuser 11409
 
3 liveuser 11410
		#取得參數
11411
		$result["argu"]=$conf;
11412
 
11413
		#如果 $conf 不為陣列
11414
		if(gettype($conf)!=="array"){
226 liveuser 11415
 
3 liveuser 11416
			#設置執行失敗
11417
			$result["status"]="false";
226 liveuser 11418
 
3 liveuser 11419
			#設置執行錯誤訊息
11420
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 11421
 
3 liveuser 11422
			#如果傳入的參數為 null
11423
			if($conf===null){
226 liveuser 11424
 
3 liveuser 11425
				#設置執行錯誤訊息
11426
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 11427
 
3 liveuser 11428
				}#if end
11429
 
11430
			#回傳結果
11431
			return $result;
226 liveuser 11432
 
3 liveuser 11433
			}#if end
226 liveuser 11434
 
3 liveuser 11435
		#檢查參數
11436
		#函式說明:
11437
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
11438
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11439
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
11440
		#$result["function"],當前執行的函式名稱.
11441
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
11442
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
11443
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
11444
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
11445
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
11446
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
11447
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
11448
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
11449
		#必填寫的參數:
11450
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
11451
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
11452
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
11453
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePartHead","oriFileName");
11454
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
11455
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
11456
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
11457
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
11458
		#可以省略的參數:
11459
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
11460
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
11461
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
11462
		#$conf["canNotBeEmpty"]=array();
11463
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
11464
		#$conf["canBeEmpty"]=array();
11465
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
11466
		#$conf["skipableVariableCanNotBeEmpty"]=array();
11467
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
11468
		#$conf["skipableVariableName"]=array();
226 liveuser 11469
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 11470
		#$conf["skipableVariableType"]=array();
11471
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
11472
		#$conf["skipableVarDefaultValue"]=array("");
11473
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
11474
		#$conf["arrayCountEqualCheck"][]=array();
11475
		#參考資料來源:
11476
		#array_keys=>http://php.net/manual/en/function.array-keys.php
11477
		#建議:
11478
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
11479
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
11480
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 11481
 
3 liveuser 11482
		#如果檢查參數失敗
11483
		if($checkArguments["status"]==="false"){
226 liveuser 11484
 
3 liveuser 11485
			#設置執行失敗
11486
			$result["status"]="false";
226 liveuser 11487
 
3 liveuser 11488
			#設置錯誤訊息
11489
			$result["error"]=$checkArguments;
226 liveuser 11490
 
3 liveuser 11491
			#回傳結果
11492
			return $result;
226 liveuser 11493
 
3 liveuser 11494
			}#if end
226 liveuser 11495
 
3 liveuser 11496
		#定義編號
11497
		$charArray=array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","v","u","w","x","y","z");
11498
 
11499
		#定義分割檔案的前置字串
11500
		$filePartHead=$conf["filePartHead"];
11501
 
11502
		#要合併成的檔案名稱
11503
		$oriFileName=$conf["oriFileName"];
11504
 
11505
		#初始化要執行合併的語法
11506
		$restoreCmd="cat ";
11507
 
11508
		#有幾個編號就執行幾次
11509
		for($i=0;$i<count($charArray);$i++){
11510
 
11511
			#有幾個編號就執行幾次
11512
			for($j=0;$j<count($charArray);$j++){
11513
 
11514
				#如果該分割檔存在
11515
				if(file_exists($filePartHead.$charArray[$i].$charArray[$j])){
11516
 
11517
					#串接要還原的分割檔
11518
					$restoreCmd=$restoreCmd." '".$filePartHead.$charArray[$i].$charArray[$j]."'";
11519
 
11520
					}#if end
11521
 
11522
				#反之
11523
				else{
11524
 
11525
					#如果是第一個分割檔就找不到
11526
					if($i===0 && $j===0){
226 liveuser 11527
 
3 liveuser 11528
						#設置執行失敗
11529
						$result["status"]="false";
226 liveuser 11530
 
3 liveuser 11531
						#設置錯誤訊息
11532
						$result["error"][]="找不到第一個分割檔「".$filePartHead.$charArray[$i].$charArray[$j]."」";
226 liveuser 11533
 
3 liveuser 11534
						#回傳結果
11535
						return $result;
226 liveuser 11536
 
3 liveuser 11537
						}#if end
11538
 
11539
					#串接要還原成的檔案名稱
11540
					$restoreCmd=$restoreCmd." > '".$oriFileName."'";
11541
 
11542
					#取得執行的指令
11543
					$result["cmd"]=$restoreCmd;
11544
 
11545
					#執行還原的指令
11546
					exec($restoreCmd,$output,$status);
11547
 
11548
					#取得執行後的輸出
11549
					$result["content"]=$output;
11550
 
11551
					#結束回圈
11552
					break 2;
226 liveuser 11553
 
3 liveuser 11554
					}#else end
11555
 
11556
				}#for end
11557
 
11558
			}#for end
226 liveuser 11559
 
3 liveuser 11560
		#設置執行正常
11561
		$result["status"]="true";
226 liveuser 11562
 
3 liveuser 11563
		#回傳結果
11564
		return $result;
226 liveuser 11565
 
3 liveuser 11566
		}#function merge end
11567
 
11568
	/*
11569
	#函式說明:
11570
	#取得檔案的部分內容
11571
	#回傳結果:
11572
	#$result["status"],"true"代表移除成功,"false"代表移除失敗.
11573
	#$result["error"],錯誤訊息陣列.
11574
	#$result["function"],當前執行的函數名稱.
11575
	#$result["cmd"],執行的指令.
11576
	#$result["content"],取得的檔案內容.
11577
	#$result["length"],取得的內容長度.
11578
	#$result["EOF"],識別是否已經到檔案結尾,"true"代表是,"false"代表不是.
11579
	#$result["mimeType"],檔案的 mime type.
11580
	#必填參數:
11581
	#$conf["file"],字串,檔案的路徑與名稱.
11582
	$conf["file"]="";
11583
	#$conf["fileArgu"],字串,__FILE__的內容.
11584
	$conf["fileArgu"]=__FILE__;
11585
	#$conf["bytes"],整數字串,要讀取多少bytes.
11586
	$conf["bytes"]="";
11587
	#$conf["startIndex"],要從哪個bytes位置開始,起始點為0.
11588
	$conf["startIndex"]="";
11589
	#可省略參數:
11590
	#無
11591
	#參考資料:
11592
	#無.
11593
	#備註:
11594
	#無
11595
	*/
11596
	public static function getFilePart(&$conf){
226 liveuser 11597
 
3 liveuser 11598
		#初始化要回傳的結果
11599
		$result=array();
11600
 
11601
		#取得當前執行的函數名稱
11602
		$result["function"]=__FUNCTION__;
11603
 
11604
		#如果沒有參數
11605
		if(func_num_args()==0){
11606
 
11607
			#設置執行失敗
11608
			$result["status"]="false";
11609
 
11610
			#設置執行錯誤訊息
11611
			$result["error"]="函數".$result["function"]."需要參數";
11612
 
11613
			#回傳結果
11614
			return $result;
11615
 
11616
			}#if end
226 liveuser 11617
 
3 liveuser 11618
		#取得參數
11619
		$result["argu"]=$conf;
11620
 
11621
		#如果 $conf 不為陣列
11622
		if(gettype($conf)!=="array"){
11623
 
11624
			#設置執行失敗
11625
			$result["status"]="false";
11626
 
11627
			#設置執行錯誤訊息
11628
			$result["error"][]="\$conf變數須為陣列形態";
11629
 
11630
			#如果傳入的參數為 null
11631
			if(is_null($conf)){
11632
 
11633
				#設置執行錯誤訊息
11634
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
11635
 
11636
				}#if end
11637
 
11638
			#回傳結果
11639
			return $result;
11640
 
11641
			}#if end
226 liveuser 11642
 
3 liveuser 11643
		#函式說明:
11644
		#檢查多個檔案與資料夾是否存在.
11645
		#回傳的結果:
11646
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
11647
		#$result["error"],錯誤訊息陣列.
11648
		#$resutl["function"],當前執行的涵式名稱.
11649
		#$result["argu"],使用的參數.
11650
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
11651
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
11652
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
11653
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
11654
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
11655
		#必填參數:
11656
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
11657
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
11658
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
11659
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
11660
		#可省略參數:
11661
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
11662
		#$conf["disableWebSearch"]="false";
11663
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
11664
		#$conf["userDir"]="true";
11665
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
11666
		#$conf["web"]="true";
11667
		#參考資料:
11668
		#http://php.net/manual/en/function.file-exists.php
11669
		#http://php.net/manual/en/control-structures.foreach.php
11670
		#備註:
11671
		#函數file_exists檢查的路徑為檔案系統的路徑
11672
		#$result["varName"][$i]結果未實作
11673
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
11674
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 11675
 
3 liveuser 11676
		#如果執行失敗
11677
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 11678
 
3 liveuser 11679
			#設置執行失敗
11680
			$result["status"]="false";
226 liveuser 11681
 
3 liveuser 11682
			#設置執行錯誤訊息
11683
			$result["error"]=$checkMultiFileExist;
226 liveuser 11684
 
3 liveuser 11685
			#回傳結果
11686
			return $result;
226 liveuser 11687
 
3 liveuser 11688
			}#if end
226 liveuser 11689
 
3 liveuser 11690
		#如果檔案不存在
11691
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 11692
 
3 liveuser 11693
			#設置執行失敗
11694
			$result["status"]="false";
226 liveuser 11695
 
3 liveuser 11696
			#設置執行錯誤訊息
11697
			$result["error"]=$checkMultiFileExist;
226 liveuser 11698
 
3 liveuser 11699
			#回傳結果
11700
			return $result;
226 liveuser 11701
 
3 liveuser 11702
			}#if end
226 liveuser 11703
 
3 liveuser 11704
		#取得mimetype
11705
		$mimetype=mime_content_type($conf["file"]);
226 liveuser 11706
 
3 liveuser 11707
		#取得檔案的 mime type
11708
		$result["mimeType"]=$mimetype;
226 liveuser 11709
 
3 liveuser 11710
		#透過 dd 指令,取得部分內容.
11711
		#函式說明:
11712
		#呼叫shell執行系統命令,並取得回傳的內容.
11713
		#回傳結果:
11714
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11715
		#$result["error"],錯誤訊息陣列.
11716
		#$result["function"],當前執行的函數名稱.
11717
		#$result["argu"],使用的參數.
11718
		#$result["cmd"],執行的指令內容.
11719
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
11720
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
11721
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
11722
		#$result["running"],是否還在執行.
11723
		#$result["pid"],pid.
11724
		#$result["statusCode"],執行結束後的代碼.
11725
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
11726
		#必填參數:
11727
		#$conf["command"],字串,要執行的指令.
11728
		$conf["external::callShell"]["command"]="dd";
11729
		#$conf["fileArgu"],字串,變數__FILE__的內容.
11730
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
11731
		#可省略參數:
11732
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
11733
		$conf["external::callShell"]["argu"]=array("if=".$conf["file"],"bs=".$conf["bytes"],"count=1","status=none");
11734
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
11735
		#$conf["arguIsAddr"]=array();
11736
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
11737
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
11738
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
11739
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
11740
		#$conf["enablePrintDescription"]="true";
11741
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
11742
		#$conf["printDescription"]="";
11743
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
11744
		#$conf["escapeshellarg"]="false";
11745
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
11746
		#$conf["thereIsShellVar"]=array();
11747
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
11748
		#$conf["username"]="";
11749
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
11750
		#$conf["password"]="";
11751
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
11752
		#$conf["useScript"]="";
11753
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
11754
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
11755
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
11756
		#$conf["inBackGround"]="";
11757
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
11758
		#$conf["getErr"]="false";
11759
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
11760
		#$conf["doNotRun"]="false";
11761
		#參考資料:
11762
		#exec=>http://php.net/manual/en/function.exec.php
11763
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
11764
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
11765
		#備註:
11766
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
11767
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
11768
		$callShell=external::callShell($conf["external::callShell"]);
11769
		unset($conf["external::callShell"]);
226 liveuser 11770
 
3 liveuser 11771
		#如果執行失敗
11772
		if($callShell["status"]==="false"){
226 liveuser 11773
 
3 liveuser 11774
			#設置執行失敗
11775
			$result["status"]="false";
226 liveuser 11776
 
3 liveuser 11777
			#設置執行錯誤訊息
11778
			$result["error"]=$callShell;
226 liveuser 11779
 
3 liveuser 11780
			#回傳結果
11781
			return $result;
226 liveuser 11782
 
3 liveuser 11783
			}#if end
226 liveuser 11784
 
3 liveuser 11785
		#取得結果
11786
		$result["content"]=$callShell["output"][0];
226 liveuser 11787
 
3 liveuser 11788
		#取得內容長度
11789
		$result["length"]=strlen($result["content"]);
226 liveuser 11790
 
11791
		#預設尚未到檔案結尾
3 liveuser 11792
		$result["EOF"]="false";
226 liveuser 11793
 
3 liveuser 11794
		#如果取得的內容長度小於預期
11795
		if($result["length"]<$conf["bytes"]){
226 liveuser 11796
 
3 liveuser 11797
			#設置已經到檔案結尾了
11798
			$result["EOF"]="true";
226 liveuser 11799
 
3 liveuser 11800
			}#if end
226 liveuser 11801
 
3 liveuser 11802
		#設置執行正常
11803
		$result["status"]="true";
226 liveuser 11804
 
3 liveuser 11805
		#回傳結果
11806
		return $result;
226 liveuser 11807
 
3 liveuser 11808
		}#function getFilePart end
11809
 
11810
	/*
11811
	#函式說明:
11812
	#取得節點的資訊.
11813
	#回傳結果:
11814
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
11815
	#$result["error"],錯誤訊息陣列.
226 liveuser 11816
	#$result["function"],函數名稱.
3 liveuser 11817
	#$result["content"],檔案資訊陣列.
226 liveuser 11818
	#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
3 liveuser 11819
	#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
11820
	#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
11821
	#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
11822
	#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
11823
	#$result["content"]["ownerName"],檔案擁有着資訊.
11824
	#$result["content"]["groupName"],檔案所屬擁有着資訊.
11825
	#$result["content"]["size"],檔案大小.
11826
	#$result["content"]["modifyDate"],檔案變更年月日.
11827
	#$result["content"]["modifyTime"],檔案變更時分秒.
11828
	#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
11829
	#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
11830
	#必填參數:
11831
	#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
11832
	$conf["fileArgu"]=__FILE__;
11833
	#$conf["file"],字串,要查看擁有者資訊的檔案.
11834
	$conf["file"]="";
11835
	#可省略參數:
11836
	#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
11837
	#$conf["web"]="true";
11838
	#參考資料:
11839
	#fileowner=>http://php.net/manual/en/function.fileowner.php
11840
	#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
11841
	#備註:
11842
	#無.
11843
	*/
11844
	public static function fileInfo(&$conf=array()){
226 liveuser 11845
 
3 liveuser 11846
		#初始化要回傳的結果
11847
		$result=array();
11848
 
11849
		#取得當前執行的函數名稱
11850
		$result["function"]=__FUNCTION__;
11851
 
11852
		#如果沒有參數
11853
		if(func_num_args()==0){
226 liveuser 11854
 
3 liveuser 11855
			#設置執行失敗
11856
			$result["status"]="false";
226 liveuser 11857
 
3 liveuser 11858
			#設置執行錯誤訊息
11859
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 11860
 
3 liveuser 11861
			#回傳結果
11862
			return $result;
226 liveuser 11863
 
3 liveuser 11864
			}#if end
11865
 
11866
		#取得參數
11867
		$result["argu"]=$conf;
11868
 
11869
		#如果 $conf 不為陣列
11870
		if(gettype($conf)!=="array"){
226 liveuser 11871
 
3 liveuser 11872
			#設置執行失敗
11873
			$result["status"]="false";
226 liveuser 11874
 
3 liveuser 11875
			#設置執行錯誤訊息
11876
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 11877
 
3 liveuser 11878
			#如果傳入的參數為 null
11879
			if($conf===null){
226 liveuser 11880
 
3 liveuser 11881
				#設置執行錯誤訊息
11882
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 11883
 
3 liveuser 11884
				}#if end
11885
 
11886
			#回傳結果
11887
			return $result;
226 liveuser 11888
 
3 liveuser 11889
			}#if end
226 liveuser 11890
 
3 liveuser 11891
		#檢查參數
11892
		#函式說明:
11893
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
11894
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11895
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
11896
		#$result["function"],當前執行的函式名稱.
11897
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
11898
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
11899
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
11900
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
11901
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
11902
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
11903
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
11904
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
11905
		#必填寫的參數:
11906
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 11907
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 11908
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
11909
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
11910
		#可以省略的參數:
11911
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
11912
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
11913
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
11914
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
11915
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
11916
		#$conf["canBeEmptyString"]="false";
11917
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
11918
		#$conf["ileAccess::checkArguments"]["canNotBeEmpty"]=array();
11919
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
11920
		#$conf["canBeEmpty"]=array();
11921
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
11922
		#$conf["skipableVariableCanNotBeEmpty"]=array();
11923
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
11924
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
226 liveuser 11925
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 11926
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
11927
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
11928
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
11929
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
11930
		#$conf["disallowAllSkipableVarIsEmpty"]="";
11931
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
11932
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
11933
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
11934
		#$conf["arrayCountEqualCheck"][]=array();
11935
		#參考資料來源:
11936
		#array_keys=>http://php.net/manual/en/function.array-keys.php
11937
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
11938
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 11939
 
3 liveuser 11940
		#如果檢查參數失敗
11941
		if($checkArguments["status"]==="false"){
226 liveuser 11942
 
3 liveuser 11943
			#設置執行失敗
11944
			$result["status"]="false";
226 liveuser 11945
 
3 liveuser 11946
			#設置執行錯誤訊息
11947
			$result["error"]=$checkArguments;
226 liveuser 11948
 
3 liveuser 11949
			#回傳結果
11950
			return $result;
226 liveuser 11951
 
3 liveuser 11952
			}#if end
226 liveuser 11953
 
3 liveuser 11954
		#如果檢查參數不通過
11955
		if($checkArguments["passed"]==="false"){
226 liveuser 11956
 
3 liveuser 11957
			#設置執行失敗
11958
			$result["status"]="false";
226 liveuser 11959
 
3 liveuser 11960
			#設置執行錯誤訊息
11961
			$result["error"]=$checkArguments;
226 liveuser 11962
 
3 liveuser 11963
			#回傳結果
11964
			return $result;
226 liveuser 11965
 
3 liveuser 11966
			}#if end
226 liveuser 11967
 
3 liveuser 11968
		#函式說明:
11969
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
11970
		#回傳結果:
11971
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
11972
		#$result["error"],錯誤訊息陣列.
226 liveuser 11973
		#$result["function"],函數名稱.
3 liveuser 11974
		#$result["argu"],使用的參數.
11975
		#$result["content"],網址,若是在命令列執行,則為"null".
11976
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
11977
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
11978
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
11979
		#必填參數:
11980
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
11981
		$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["file"];
11982
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
11983
		$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
11984
		#可省略參數:
11985
		#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
11986
		$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
11987
		#備註:
11988
		#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
11989
		$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
11990
		unset($conf["fileAccess::getInternetAddressV2"]);
226 liveuser 11991
 
3 liveuser 11992
		#如果取得位置失敗
11993
		if($getInternetAddressV2["status"]==="false"){
226 liveuser 11994
 
3 liveuser 11995
			#設置執行失敗
11996
			$result["status"]="false";
226 liveuser 11997
 
3 liveuser 11998
			#設置執行錯誤訊息
11999
			$result["error"]=$getInternetAddressV2;
226 liveuser 12000
 
3 liveuser 12001
			#回傳結果
12002
			return $result;
226 liveuser 12003
 
3 liveuser 12004
			}#if end
12005
 
12006
		#函式說明:
12007
		#檢查多個檔案與資料夾是否存在.
12008
		#回傳的結果:
12009
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
12010
		#$result["error"],錯誤訊息陣列.
12011
		#$resutl["function"],當前執行的涵式名稱.
12012
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
12013
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
12014
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
12015
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
12016
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
12017
		#必填參數:
12018
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
12019
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($getInternetAddressV2["fileSystemAbsoulutePosition"]);
12020
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
12021
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
12022
		#可省略參數
12023
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
12024
		#$conf["disableWebSearch"]="false";
12025
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
12026
		#$conf["userDir"]="true";
12027
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
12028
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
12029
		#參考資料來源:
12030
		#http://php.net/manual/en/function.file-exists.php
12031
		#http://php.net/manual/en/control-structures.foreach.php
12032
		#備註:
12033
		#函數file_exists檢查的路徑為檔案系統的路徑
12034
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
12035
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 12036
 
3 liveuser 12037
		#如果檢查檔案存在失敗
12038
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 12039
 
3 liveuser 12040
			#設置執行失敗
12041
			$result["status"]="false";
226 liveuser 12042
 
3 liveuser 12043
			#設置執行錯誤訊息
12044
			$result["error"]=$checkMultiFileExist;
226 liveuser 12045
 
3 liveuser 12046
			#回傳結果
12047
			return $result;
226 liveuser 12048
 
3 liveuser 12049
			}#if end
226 liveuser 12050
 
3 liveuser 12051
		#如果檔案不存在
12052
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 12053
 
3 liveuser 12054
			#設置執行失敗
12055
			$result["status"]="false";
226 liveuser 12056
 
3 liveuser 12057
			#設置執行錯誤訊息
12058
			$result["error"]=$checkMultiFileExist;
226 liveuser 12059
 
3 liveuser 12060
			#回傳結果
12061
			return $result;
226 liveuser 12062
 
3 liveuser 12063
			}#if end
226 liveuser 12064
 
3 liveuser 12065
		#透過ls指令取得檔案的資訊
12066
		#函式說明:
12067
		#呼叫shell執行系統命令,並取得回傳的內容.
12068
		#回傳的結果:
12069
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12070
		#$result["error"],錯誤訊息陣列.
12071
		#$result["function"],當前執行的函數名稱.
12072
		#$result["cmd"],執行的指令內容.
12073
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
12074
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
12075
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
12076
		#$result["running"],是否還在執行.
12077
		#$result["pid"],pid
12078
		#必填的參數
12079
		#$conf["command"],字串,要執行的指令
12080
		$conf["external::callShell"]["command"]="ls";
12081
		#$conf["fileArgu"],字串,變數__FILE__的內容.
12082
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
12083
		#可省略參數:
12084
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
12085
		$conf["external::callShell"]["argu"]=array("-l","--full-time","-d",$conf["file"]);
12086
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
12087
		$conf["external::callShell"]["arguIsAddr"]=array("false","false","false","false");
12088
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
12089
		#$conf["enablePrintDescription"]="true";
12090
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
12091
		#$conf["printDescription"]="";
12092
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
12093
		$conf["external::callShell"]["escapeshellarg"]="true";
12094
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
12095
		#$conf["username"]="";
12096
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
12097
		#$conf["password"]="";
12098
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
12099
		#$conf["useScript"]="";
12100
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
12101
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
12102
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
12103
		#$conf["inBackGround"]="";
12104
		#備註:
12105
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
12106
		#參考資料:
12107
		#exec=>http://php.net/manual/en/function.exec.php
12108
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
12109
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
12110
		$callShell=external::callShell($conf["external::callShell"]);
12111
		unset($conf["external::callShell"]);
226 liveuser 12112
 
3 liveuser 12113
		#如果執行失敗
12114
		if($callShell["status"]==="false"){
226 liveuser 12115
 
3 liveuser 12116
			#設置執行失敗
12117
			$result["status"]="false";
226 liveuser 12118
 
3 liveuser 12119
			#設置執行錯誤訊息
12120
			$result["error"]=$callShell;
226 liveuser 12121
 
3 liveuser 12122
			#回傳結果
12123
			return $result;
226 liveuser 12124
 
12125
			}#if end
12126
 
3 liveuser 12127
		#解析檔案資訊
12128
		#-rwxrwx--x. 1 apache apache 65K 2017-04-16 22:53:19.044545806 +0800 fileAccessT.php
226 liveuser 12129
 
3 liveuser 12130
		#取得權限資訊 -rwxrwx--x
12131
		$perm=substr($callShell["output"][0],0,strpos($callShell["output"][0],'.'));
226 liveuser 12132
 
3 liveuser 12133
		#如果是目錄
12134
		if(substr($perm,0,1)==="d"){
226 liveuser 12135
 
3 liveuser 12136
			#設定為目錄
12137
			$result["content"]["is_folder"]="true";
226 liveuser 12138
 
3 liveuser 12139
			}#if end
226 liveuser 12140
 
3 liveuser 12141
		#反之
12142
		else{
226 liveuser 12143
 
3 liveuser 12144
			#設定不為目錄
12145
			$result["content"]["is_folder"]="false";
226 liveuser 12146
 
3 liveuser 12147
			}#else end
226 liveuser 12148
 
3 liveuser 12149
		#解析檔案擁有者權限資訊
12150
		$result["content"]["ownerPerm"]=substr($perm,1,3);
226 liveuser 12151
 
3 liveuser 12152
		#如果檔案擁有者名稱為空
12153
		if(empty($result["content"]["ownerPerm"])){
226 liveuser 12154
 
3 liveuser 12155
			#設置執行失敗
12156
			$result["status"]="false";
226 liveuser 12157
 
3 liveuser 12158
			#設置執行錯誤訊息
12159
			$result["error"]=$callShell;
226 liveuser 12160
 
3 liveuser 12161
			#回傳結果
12162
			return $result;
226 liveuser 12163
 
3 liveuser 12164
			}#if end
226 liveuser 12165
 
3 liveuser 12166
		#解析檔案歸屬群組權限資訊
12167
		$result["content"]["groupPerm"]=substr($perm,4,3);
226 liveuser 12168
 
3 liveuser 12169
		#解析檔案對於其他身份使用者的權限資訊
12170
		$result["content"]["otherPerm"]=substr($perm,7,3);
226 liveuser 12171
 
3 liveuser 12172
		#取得目錄底下的檔案目錄數量起始點
12173
		$subElementStartPos=strpos($callShell["output"][0],' ');
226 liveuser 12174
 
3 liveuser 12175
		#取得目錄底下的檔案目錄數量結束點
12176
		$subElementEndPos=strpos($callShell["output"][0],' ',$subElementStartPos+1);
226 liveuser 12177
 
3 liveuser 12178
		#取得目錄底下的檔案目錄數量
12179
		$result["content"]["subElementCount"]=substr($callShell["output"][0],$subElementStartPos,$subElementEndPos-$subElementStartPos);
226 liveuser 12180
 
3 liveuser 12181
		#取得檔案擁有着資訊的起點
12182
		$ownerNameStrPos=strpos($callShell["output"][0],' ',$subElementEndPos)+1;
226 liveuser 12183
 
3 liveuser 12184
		#取得檔案擁有着資訊的結束點
12185
		$ownerNameEndPos=strpos($callShell["output"][0],' ',$ownerNameStrPos+1);
226 liveuser 12186
 
3 liveuser 12187
		#取得檔案擁有着資訊
12188
		$result["content"]["ownerName"]=substr($callShell["output"][0],$ownerNameStrPos,$ownerNameEndPos-$ownerNameStrPos);
226 liveuser 12189
 
3 liveuser 12190
		#取取得檔案群組擁有者資訊的起點
12191
		$groupNameStrPos=strpos($callShell["output"][0],' ',$ownerNameEndPos)+1;
226 liveuser 12192
 
3 liveuser 12193
		#取得檔案群組擁有者資訊的結束點
12194
		$groupNameEndPos=strpos($callShell["output"][0],' ',$groupNameStrPos);
226 liveuser 12195
 
3 liveuser 12196
		#取得檔案群組擁有者資訊
12197
		$result["content"]["groupName"]=substr($callShell["output"][0],$groupNameStrPos,$groupNameEndPos-$groupNameStrPos);
226 liveuser 12198
 
3 liveuser 12199
		#取得檔案大小的起點
12200
		$sizeStrPos=strpos($callShell["output"][0],' ',$groupNameEndPos)+1;
226 liveuser 12201
 
3 liveuser 12202
		#取得檔案大小的結束點
12203
		$sizeEndPos=strpos($callShell["output"][0],' ',$sizeStrPos);
226 liveuser 12204
 
3 liveuser 12205
		#取得檔案大小
12206
		$result["content"]["size"]=substr($callShell["output"][0],$sizeStrPos,$sizeEndPos-$sizeStrPos);
226 liveuser 12207
 
3 liveuser 12208
		#取得檔案變更年月日的起點
12209
		$modifyDateStrPos=strpos($callShell["output"][0],' ',$sizeEndPos)+1;
226 liveuser 12210
 
3 liveuser 12211
		#取得檔案變更年月日的結束點
12212
		$modifyDateEndPos=strpos($callShell["output"][0],' ',$modifyDateStrPos);
226 liveuser 12213
 
12214
		#取得檔案變更年月日
3 liveuser 12215
		$result["content"]["modifyDate"]=substr($callShell["output"][0],$modifyDateStrPos,$modifyDateEndPos-$modifyDateStrPos);
226 liveuser 12216
 
3 liveuser 12217
		#取得檔案變更時分秒的起點
12218
		$modifyTimeStrPos=strpos($callShell["output"][0],' ',$modifyDateEndPos)+1;
226 liveuser 12219
 
3 liveuser 12220
		#取得檔案變更時分秒的結束點
12221
		$modifyTimeEndPos=strpos($callShell["output"][0],'.',$modifyTimeStrPos);
226 liveuser 12222
 
3 liveuser 12223
		#取得檔案變更時分秒
12224
		$result["content"]["modifyTime"]=substr($callShell["output"][0],$modifyTimeStrPos,$modifyTimeEndPos-$modifyTimeStrPos);
226 liveuser 12225
 
3 liveuser 12226
		#取得檔版變更時間秒的float數值起點
12227
		$modifyTimeFloatStrPos=strpos($callShell["output"][0],'.',$modifyTimeEndPos)+1;
226 liveuser 12228
 
3 liveuser 12229
		#取得檔版變更時間秒的float數值結束點
12230
		$modifyTimeFloatEndPos=strpos($callShell["output"][0],' ',$modifyTimeFloatStrPos);
226 liveuser 12231
 
12232
		#取得檔版變更時間秒的float數值
3 liveuser 12233
		$result["content"]["modifyTimeFloat"]=substr($callShell["output"][0],$modifyTimeFloatStrPos,$modifyTimeFloatEndPos-$modifyTimeFloatStrPos);
226 liveuser 12234
 
3 liveuser 12235
		#取得時區起始點
12236
		$timezoneStrPos=strpos($callShell["output"][0],' ',$modifyTimeFloatEndPos)+1;
226 liveuser 12237
 
3 liveuser 12238
		#取得時區結束點
226 liveuser 12239
		$timezoneEndPos=strpos($callShell["output"][0],' ',$timezoneStrPos)+1;
12240
 
3 liveuser 12241
		#取得檔案變更時間的時區與UTC的差距.
226 liveuser 12242
		$result["content"]["timezone"]=substr($callShell["output"][0],$timezoneStrPos,$timezoneEndPos-$timezoneStrPos);
12243
 
3 liveuser 12244
		#設置執行正常
12245
		$result["status"]="true";
226 liveuser 12246
 
3 liveuser 12247
		#回傳結果
12248
		return $result;
226 liveuser 12249
 
3 liveuser 12250
		}#function fileInfo end
12251
 
12252
	/*
12253
	#函式說明:
226 liveuser 12254
	#依據函數getListTree執行的結果,將其底下與其子目錄底下的特定檔案內容依據目錄層級輸出成html檔案
3 liveuser 12255
	#回傳結果:
12256
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
12257
	#$result["error"],錯誤訊息陣列.
226 liveuser 12258
	#$result["function"],函數名稱.
3 liveuser 12259
	#$result["content"],html檔案輸出的位置與名稱.
12260
	#必填參數:
12261
	#$conf["getListTree"],陣列變數,函數getListTree執行的結果.
12262
	$conf["getListTree"]=$getListTree;
12263
	#可省略參數:
12264
	#$conf["fileToRead"],字串,要讀取的檔案名稱為何?預設為"help".
12265
	#$conf["fileToRead"]="help";
12266
	#$conf["output"],字串,輸出的網頁檔案位置與名稱,副檔名html會自動補上,預設為"help".
226 liveuser 12267
	#$conf["output"]="help.html";
3 liveuser 12268
	#參考資料:
12269
	#無.
12270
	#備註:
12271
	#建構中...
12272
	*/
12273
	public static function createHelpFile($conf){
226 liveuser 12274
 
3 liveuser 12275
		#初始化要回傳的結果
12276
		$result=array();
226 liveuser 12277
 
3 liveuser 12278
		#設置當其函數名稱
12279
		$result["function"]=__FUNCTION__;
226 liveuser 12280
 
3 liveuser 12281
		#如果 $conf 不為陣列
12282
		if(gettype($conf)!="array"){
226 liveuser 12283
 
3 liveuser 12284
			#設置執行失敗
12285
			$result["status"]="false";
226 liveuser 12286
 
3 liveuser 12287
			#設置執行錯誤訊息
12288
			$result["error"][]="\$conf變數須為陣列形態";
12289
 
12290
			#如果傳入的參數為 null
12291
			if($conf==null){
226 liveuser 12292
 
3 liveuser 12293
				#設置執行錯誤訊息
12294
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 12295
 
3 liveuser 12296
				}#if end
12297
 
12298
			#回傳結果
12299
			return $result;
226 liveuser 12300
 
3 liveuser 12301
			}#if end
226 liveuser 12302
 
3 liveuser 12303
		#檢查參數
12304
		#函式說明:
12305
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
12306
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12307
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12308
		#$result["function"],當前執行的函式名稱.
12309
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12310
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12311
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12312
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
12313
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12314
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12315
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12316
		#必填寫的參數:
12317
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
12318
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
12319
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12320
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("getListTree");
226 liveuser 12321
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3 liveuser 12322
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
12323
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12324
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12325
		#可以省略的參數:
12326
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
12327
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
12328
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12329
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileToRead","output");
226 liveuser 12330
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 12331
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
12332
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12333
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("help","help");
12334
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12335
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
12336
		#參考資料來源:
12337
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12338
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
12339
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 12340
 
3 liveuser 12341
		#如果 $checkResult["status"] 等於 "fasle"
12342
		if($checkResult["status"]=="false"){
226 liveuser 12343
 
3 liveuser 12344
			#設置錯誤識別
12345
			$result["status"]="false";
226 liveuser 12346
 
3 liveuser 12347
			#設置錯誤訊息
12348
			$result["error"]=$checkResult;
226 liveuser 12349
 
3 liveuser 12350
			#回傳結果
12351
			return $result;
226 liveuser 12352
 
3 liveuser 12353
			}#if end
226 liveuser 12354
 
3 liveuser 12355
		#如果 $checkResult["passed"] 等於 "fasle"
12356
		if($checkResult["passed"]=="false"){
226 liveuser 12357
 
3 liveuser 12358
			#設置錯誤識別
12359
			$result["status"]="false";
226 liveuser 12360
 
3 liveuser 12361
			#設置錯誤訊息
12362
			$result["error"]=$checkResult;
226 liveuser 12363
 
3 liveuser 12364
			#回傳結果
12365
			return $result;
226 liveuser 12366
 
3 liveuser 12367
			}#if end
226 liveuser 12368
 
3 liveuser 12369
		#如果 $conf["getListTree"]["status"] 不存在
12370
		if(!isset($conf["getListTree"]["status"])){
226 liveuser 12371
 
3 liveuser 12372
			#設置錯誤識別
12373
			$result["status"]="false";
226 liveuser 12374
 
3 liveuser 12375
			#設置錯誤訊息
12376
			$result["error"][]="getListTree參數必須為getListTree函數執行後的結果";
226 liveuser 12377
 
3 liveuser 12378
			#回傳結果
12379
			return $result;
226 liveuser 12380
 
3 liveuser 12381
			}#if end
226 liveuser 12382
 
3 liveuser 12383
		#如果 $conf["getListTree"] 執行失敗
12384
		if($conf["getListTree"]["status"]=="false"){
226 liveuser 12385
 
3 liveuser 12386
			#設置錯誤識別
12387
			$result["status"]="false";
226 liveuser 12388
 
3 liveuser 12389
			#設置錯誤訊息
12390
			$result["error"]=$conf["getListTree"];
226 liveuser 12391
 
3 liveuser 12392
			#回傳結果
12393
			return $result;
226 liveuser 12394
 
3 liveuser 12395
			}#if end
226 liveuser 12396
 
3 liveuser 12397
		#如果有目錄檔案
12398
		if(isset($conf["getListTree"]["content"])){
226 liveuser 12399
 
12400
 
12401
 
3 liveuser 12402
			}#if end
226 liveuser 12403
 
3 liveuser 12404
		}#function createHelpFile end
226 liveuser 12405
 
3 liveuser 12406
	/*
12407
	#函式說明:
12408
	#嵌入pdf檔案到網頁上面
12409
	#回傳結果:
12410
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
12411
	#$result["error"],錯誤訊息陣列.
226 liveuser 12412
	#$result["function"],函數名稱.
3 liveuser 12413
	#$result["content"],嵌入pdf檔案的語法
12414
	#必填參數:
12415
	#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
12416
	$conf["fileArgu"]=__FILE__;
12417
	#$conf["file"],字串,pdf檔案位置.
12418
	$conf["file"]="";
12419
	#可省略參數:
12420
	#$conf["type"],字串,要用"iframe"還是"object"的方式嵌入pdf檔案,預設為"iframe".
12421
	#$conf["type"]="iframe";
12422
	#參考資料:
12423
	#嵌入pdf到網頁=>https://stackoverflow.com/questions/14690000/embed-a-pdf-in-html5
12424
	#備註:
12425
	#如果是網址就會出錯.
12426
	*/
12427
	public static function embedPdf(&$conf=array()){
226 liveuser 12428
 
3 liveuser 12429
		#初始化要回傳的結果
12430
		$result=array();
12431
 
12432
		#取得當前執行的函數名稱
12433
		$result["function"]=__FUNCTION__;
12434
 
12435
		#如果沒有參數
12436
		if(func_num_args()==0){
226 liveuser 12437
 
3 liveuser 12438
			#設置執行失敗
12439
			$result["status"]="false";
226 liveuser 12440
 
3 liveuser 12441
			#設置執行錯誤訊息
12442
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 12443
 
3 liveuser 12444
			#回傳結果
12445
			return $result;
226 liveuser 12446
 
3 liveuser 12447
			}#if end
12448
 
12449
		#取得參數
12450
		$result["argu"]=$conf;
12451
 
12452
		#如果 $conf 不為陣列
12453
		if(gettype($conf)!=="array"){
226 liveuser 12454
 
3 liveuser 12455
			#設置執行失敗
12456
			$result["status"]="false";
226 liveuser 12457
 
3 liveuser 12458
			#設置執行錯誤訊息
12459
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 12460
 
3 liveuser 12461
			#如果傳入的參數為 null
12462
			if($conf===null){
226 liveuser 12463
 
3 liveuser 12464
				#設置執行錯誤訊息
12465
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 12466
 
3 liveuser 12467
				}#if end
12468
 
12469
			#回傳結果
12470
			return $result;
226 liveuser 12471
 
3 liveuser 12472
			}#if end
226 liveuser 12473
 
3 liveuser 12474
		#檢查參數
12475
		#函式說明:
12476
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
12477
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12478
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12479
		#$result["function"],當前執行的函式名稱.
12480
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12481
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12482
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12483
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
12484
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
12485
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12486
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12487
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12488
		#必填寫的參數:
12489
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
12490
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
12491
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12492
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
12493
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
12494
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
12495
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12496
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12497
		#可以省略的參數:
12498
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
12499
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
12500
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
12501
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("function");
12502
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
12503
		#$conf["canBeEmpty"]=array();
12504
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
12505
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("width","height");
12506
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12507
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("type");
226 liveuser 12508
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 12509
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
12510
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12511
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("iframe");
12512
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12513
		#$conf["arrayCountEqualCheck"][]=array();
12514
		#參考資料來源:
12515
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12516
		#建議:
12517
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
12518
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
226 liveuser 12519
		unset($conf["variableCheck::checkArguments"]);
12520
 
3 liveuser 12521
		#如果檢查參數失敗
12522
		if($checkArguments["status"]==="false"){
226 liveuser 12523
 
3 liveuser 12524
			#設置執行失敗
12525
			$result["status"]="false";
226 liveuser 12526
 
3 liveuser 12527
			#設置執行錯誤訊息
12528
			$result["error"]=$checkArguments;
226 liveuser 12529
 
3 liveuser 12530
			#回傳結果
12531
			return $result;
226 liveuser 12532
 
3 liveuser 12533
			}#if end
226 liveuser 12534
 
3 liveuser 12535
		#如果參數檢查不通過
12536
		if($checkArguments["passed"]==="false"){
226 liveuser 12537
 
3 liveuser 12538
			#設置執行失敗
12539
			$result["status"]="false";
226 liveuser 12540
 
3 liveuser 12541
			#設置執行錯誤訊息
12542
			$result["error"]=$checkArguments;
226 liveuser 12543
 
3 liveuser 12544
			#回傳結果
12545
			return $result;
226 liveuser 12546
 
3 liveuser 12547
			}#if end
226 liveuser 12548
 
3 liveuser 12549
		#檢查檔案是否存在
12550
		#函式說明:
12551
		#檢查多個檔案與資料夾是否存在.
12552
		#回傳的結果:
12553
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
12554
		#$result["error"],錯誤訊息陣列.
12555
		#$resutl["function"],當前執行的涵式名稱.
12556
		#$result["argu"],使用的參數.
12557
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
12558
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
12559
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
12560
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
12561
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
12562
		#必填參數:
12563
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
12564
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
12565
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
12566
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
12567
		#可省略參數
12568
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
12569
		$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="false";
12570
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
12571
		#$conf["userDir"]="true";
12572
		#參考資料來源:
12573
		#http://php.net/manual/en/function.file-exists.php
12574
		#http://php.net/manual/en/control-structures.foreach.php
12575
		#備註:
12576
		#函數file_exists檢查的路徑為檔案系統的路徑
12577
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
12578
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 12579
 
3 liveuser 12580
		#如果檢查檔案是否存在失敗
12581
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 12582
 
3 liveuser 12583
			#設置執行失敗
12584
			$result["status"]="false";
226 liveuser 12585
 
3 liveuser 12586
			#設置執行錯誤訊息
12587
			$result["error"]=$checkMultiFileExist;
226 liveuser 12588
 
3 liveuser 12589
			#回傳結果
12590
			return $result;
226 liveuser 12591
 
3 liveuser 12592
			}#if end
226 liveuser 12593
 
3 liveuser 12594
		#如果檔案不存在
12595
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 12596
 
3 liveuser 12597
			#設置執行失敗
12598
			$result["status"]="false";
226 liveuser 12599
 
3 liveuser 12600
			#設置執行錯誤訊息
12601
			$result["error"]=$checkMultiFileExist;
226 liveuser 12602
 
3 liveuser 12603
			#回傳結果
12604
			return $result;
226 liveuser 12605
 
3 liveuser 12606
			}#if end
226 liveuser 12607
 
3 liveuser 12608
		#產生 base64 的 pdf 編碼字串
12609
		$base64pdf=base64_encode(file_get_contents($conf["file"]));
226 liveuser 12610
 
3 liveuser 12611
		#產生 base64 的 pdf 編碼字串 data
12612
		$base64pdfData="data:application/pdf;base64,".$base64pdf;
226 liveuser 12613
 
3 liveuser 12614
		#判斷要用哪種方式嵌入pdf
12615
		switch($conf["type"]){
226 liveuser 12616
 
3 liveuser 12617
			#如果是用 object 方式
12618
			case "object":
226 liveuser 12619
 
3 liveuser 12620
				#產生嵌入的語法
12621
				$embedSyntax="<object style=\"width:100%;height:100%;\" data=\"".$base64pdfData."\"></object>";
226 liveuser 12622
 
3 liveuser 12623
				#取得語法
12624
				$result["content"]=&$embedSyntax;
226 liveuser 12625
 
3 liveuser 12626
				#跳出 switch
12627
				break;
226 liveuser 12628
 
3 liveuser 12629
			#預設
12630
			default:
226 liveuser 12631
 
3 liveuser 12632
				#產生嵌入的語法
12633
				$embedSyntax="<iframe style=\"width:100%;height:100%;\" src=\"".$base64pdfData."\"></iframe>";
226 liveuser 12634
 
3 liveuser 12635
				#取得語法
12636
				$result["content"]=&$embedSyntax;
226 liveuser 12637
 
3 liveuser 12638
			}#switch end
226 liveuser 12639
 
3 liveuser 12640
		#設置執行正常
12641
		$result["status"]="true";
226 liveuser 12642
 
3 liveuser 12643
		#回傳結果
12644
		return $result;
226 liveuser 12645
 
3 liveuser 12646
		}#function embedPdf end
226 liveuser 12647
 
3 liveuser 12648
	/*
12649
	#函式說明:
226 liveuser 12650
	#用linux unzip去解壓縮zip檔案
3 liveuser 12651
	#回傳結果:
12652
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12653
	#$result["error"],錯誤訊息.
12654
	#$result["function"],當前執行的函數名稱.
12655
	#$result["content"]["each"],每個檔案的資訊.
12656
	#$result["content"]["each"]["Length"][$i],各別檔案目錄的原始長度.
12657
	#$result["content"]["each"]["Method"][$i],各別檔案目錄的壓縮方法.
12658
	#$result["content"]["each"]["Size"][$i],各別檔案目錄的壓縮後長度.
12659
	#$result["content"]["each"]["Cmpr"][$i],各別檔案目錄的壓縮率.
12660
	#$result["content"]["each"]["Date"][$i],各別檔案目錄的最後修改日期.
12661
	#$result["content"]["each"]["Time"][$i],各別檔案目錄的最後修改時間.
12662
	#$result["content"]["each"]["CRC-32"][$i],各別檔案目錄的CRC-32檢查碼.
12663
	#$result["content"]["each"]["Name"][$i],各別檔案目錄的路徑與名稱.
12664
	#$result["content"]["total"],統整的資訊.
12665
	#$result["content"]["Length"],總共的檔案長度.
12666
	#$result["content"]["Size"],壓縮後的檔案長度.
12667
	#$result["content"]["Cmpr"],平均壓縮率.
12668
	#$result["content"]["count"],壓縮檔裡面總共的檔案跟目錄數目.
12669
	#必填參數;
12670
	#$conf["zip"],字串,要解壓縮的zip檔案.
12671
	$conf["zip"]="";
12672
	#$conf["fileArgu"],字串,__FILE__的內容.
12673
	$conf["fileArgu"]=__FILE__;
12674
	#可省略參數:
12675
	#$conf["extract"],字串,要解壓縮到那個路徑,預設為當前位置"./".
12676
	#$conf["extract"]="";
12677
	#備註:
12678
	#建議加上特定邊碼的支援例如、單
12679
	*/
12680
	public static function unzip(&$conf=array()){
226 liveuser 12681
 
3 liveuser 12682
		#初始化要回傳的結果
12683
		$result=array();
12684
 
12685
		#取得當前執行的函數名稱
12686
		$result["function"]=__FUNCTION__;
12687
 
12688
		#如果沒有參數
12689
		if(func_num_args()==0){
226 liveuser 12690
 
3 liveuser 12691
			#設置執行失敗
12692
			$result["status"]="false";
226 liveuser 12693
 
3 liveuser 12694
			#設置執行錯誤訊息
12695
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 12696
 
3 liveuser 12697
			#回傳結果
12698
			return $result;
226 liveuser 12699
 
3 liveuser 12700
			}#if end
226 liveuser 12701
 
3 liveuser 12702
		#取得參數
12703
		$result["argu"]=$conf;
12704
 
12705
		#如果 $conf 不為陣列
12706
		if(gettype($conf)!=="array"){
226 liveuser 12707
 
3 liveuser 12708
			#設置執行失敗
12709
			$result["status"]="false";
226 liveuser 12710
 
3 liveuser 12711
			#設置執行錯誤訊息
12712
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 12713
 
3 liveuser 12714
			#如果傳入的參數為 null
12715
			if($conf===null){
226 liveuser 12716
 
3 liveuser 12717
				#設置執行錯誤訊息
12718
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 12719
 
3 liveuser 12720
				}#if end
12721
 
12722
			#回傳結果
12723
			return $result;
226 liveuser 12724
 
3 liveuser 12725
			}#if end
226 liveuser 12726
 
3 liveuser 12727
		#檢查參數
12728
		#函式說明:
12729
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
12730
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12731
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12732
		#$result["function"],當前執行的函式名稱.
12733
		#$result["argu"],設置給予的參數.
12734
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12735
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12736
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12737
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
12738
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
12739
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12740
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12741
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12742
		#必填寫的參數:
12743
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 12744
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 12745
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12746
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12747
		#可以省略的參數:
12748
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12749
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("zip","fileArgu");
12750
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
12751
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
12752
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
12753
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
12754
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
12755
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("zip","fileArgu");
12756
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
12757
		#$conf["canBeEmpty"]=array();
12758
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
12759
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("extract");
12760
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12761
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("extract");
226 liveuser 12762
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 12763
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
12764
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12765
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("./");
12766
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
12767
		#$conf["disallowAllSkipableVarIsEmpty"]="";
12768
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
12769
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
12770
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12771
		#$conf["arrayCountEqualCheck"][]=array();
12772
		#參考資料來源:
12773
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12774
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
12775
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 12776
 
3 liveuser 12777
		#如果檢查參數失敗
12778
		if($checkArguments["status"]==="false"){
226 liveuser 12779
 
3 liveuser 12780
			#設置執行不正常
12781
			$result["status"]="false";
226 liveuser 12782
 
3 liveuser 12783
			#設置錯誤訊息
12784
			$result["error"]=$checkArguments;
226 liveuser 12785
 
3 liveuser 12786
			#回傳結果
12787
			return $result;
226 liveuser 12788
 
3 liveuser 12789
			}#if end
226 liveuser 12790
 
3 liveuser 12791
		#如果檢查參數不通過
12792
		if($checkArguments["passed"]==="false"){
226 liveuser 12793
 
3 liveuser 12794
			#設置執行不正常
12795
			$result["status"]="false";
226 liveuser 12796
 
3 liveuser 12797
			#設置錯誤訊息
12798
			$result["error"]=$checkArguments;
226 liveuser 12799
 
3 liveuser 12800
			#回傳結果
12801
			return $result;
226 liveuser 12802
 
3 liveuser 12803
			}#if end
226 liveuser 12804
 
3 liveuser 12805
		#檢查要解壓縮的檔案是否存在
12806
		#函式說明:
12807
		#檢查多個檔案與資料夾是否存在.
12808
		#回傳的結果:
12809
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
12810
		#$result["error"],錯誤訊息陣列.
12811
		#$resutl["function"],當前執行的涵式名稱.
12812
		#$result["argu"],使用的參數.
12813
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
12814
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
12815
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
12816
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
12817
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
12818
		#必填參數:
12819
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
12820
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["zip"]);
12821
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
12822
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
12823
		#可省略參數
12824
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
12825
		#$conf["disableWebSearch"]="false";
12826
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
12827
		#$conf["userDir"]="true";
12828
		#參考資料來源:
12829
		#http://php.net/manual/en/function.file-exists.php
12830
		#http://php.net/manual/en/control-structures.foreach.php
12831
		#備註:
12832
		#函數file_exists檢查的路徑為檔案系統的路徑
12833
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
12834
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 12835
 
3 liveuser 12836
		#如果檢查檔案是否存在失敗
12837
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 12838
 
3 liveuser 12839
			#設置執行不正常
12840
			$result["status"]="false";
226 liveuser 12841
 
3 liveuser 12842
			#設置錯誤訊息
12843
			$result["error"]=$checkMultiFileExist;
226 liveuser 12844
 
3 liveuser 12845
			#回傳結果
12846
			return $result;
226 liveuser 12847
 
3 liveuser 12848
			}#if end
226 liveuser 12849
 
3 liveuser 12850
		#如果要解壓縮的檔案不存在
12851
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 12852
 
3 liveuser 12853
			#設置執行不正常
12854
			$result["status"]="false";
226 liveuser 12855
 
3 liveuser 12856
			#設置錯誤訊息
12857
			$result["error"]=$checkMultiFileExist;
226 liveuser 12858
 
3 liveuser 12859
			#回傳結果
12860
			return $result;
226 liveuser 12861
 
3 liveuser 12862
			}#if end
226 liveuser 12863
 
3 liveuser 12864
		#函式說明:
12865
		#呼叫shell執行系統命令,並取得回傳的內容.
12866
		#回傳結果:
12867
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12868
		#$result["error"],錯誤訊息陣列.
12869
		#$result["function"],當前執行的函數名稱.
12870
		#$result["argu"],使用的參數.
12871
		#$result["cmd"],執行的指令內容.
12872
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
12873
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
12874
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
12875
		#$result["running"],是否還在執行.
12876
		#$result["pid"],pid
12877
		#必填參數:
12878
		#$conf["command"],字串,要執行的指令與.
12879
		$conf["external::callShell"]["command"]="unzip";
12880
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 12881
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 12882
		#可省略參數:
12883
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
12884
		$conf["external::callShell"]["argu"]=array("-d",$conf["extract"],"-o","-q",$conf["zip"]);
12885
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
12886
		#$conf["arguIsAddr"]=array();
12887
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
12888
		#$conf["enablePrintDescription"]="true";
12889
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
12890
		#$conf["printDescription"]="";
12891
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
12892
		$conf["external::callShell"]["escapeshellarg"]="true";
12893
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
12894
		#$conf["username"]="";
12895
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
12896
		#$conf["password"]="";
12897
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
12898
		#$conf["useScript"]="";
12899
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
12900
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
12901
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
12902
		#$conf["inBackGround"]="";
12903
		#備註:
12904
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
12905
		#參考資料:
12906
		#exec=>http://php.net/manual/en/function.exec.php
12907
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
12908
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
12909
		$callShell=external::callShell($conf["external::callShell"]);
12910
		unset($conf["external::callShell"]);
226 liveuser 12911
 
3 liveuser 12912
		#如果執行cmd失敗
12913
		if($callShell["status"]==="false"){
226 liveuser 12914
 
3 liveuser 12915
			#設置執行不正常
12916
			$result["status"]="false";
226 liveuser 12917
 
3 liveuser 12918
			#設置錯誤訊息
12919
			$result["error"]=$callShell;
226 liveuser 12920
 
3 liveuser 12921
			#回傳結果
12922
			return $result;
226 liveuser 12923
 
3 liveuser 12924
			}#if end
226 liveuser 12925
 
3 liveuser 12926
		#函式說明:
12927
		#呼叫shell執行系統命令,並取得回傳的內容.
12928
		#回傳的結果:
12929
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12930
		#$result["error"],錯誤訊息陣列.
12931
		#$result["function"],當前執行的函數名稱.
12932
		#$result["argu"],使用的參數.
12933
		#$result["cmd"],執行的指令內容.
12934
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
12935
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
12936
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
12937
		#$result["running"],是否還在執行.
12938
		#$result["pid"],pid
12939
		#必填的參數
12940
		#$conf["command"],字串,要執行的指令與.
12941
		$conf["external::callShell"]["command"]="unzip";
12942
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 12943
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 12944
		#可省略參數:
12945
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
12946
		$conf["external::callShell"]["argu"]=array("-v",$conf["zip"]);
12947
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
12948
		#$conf["arguIsAddr"]=array();
12949
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
12950
		#$conf["enablePrintDescription"]="true";
12951
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
12952
		#$conf["printDescription"]="";
12953
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
12954
		$conf["external::callShell"]["escapeshellarg"]="true";
12955
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
12956
		#$conf["username"]="";
12957
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
12958
		#$conf["password"]="";
12959
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
12960
		#$conf["useScript"]="";
12961
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
12962
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
12963
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
12964
		#$conf["inBackGround"]="";
12965
		#備註:
12966
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
12967
		#參考資料:
12968
		#exec=>http://php.net/manual/en/function.exec.php
12969
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
12970
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
12971
		$callShell=external::callShell($conf["external::callShell"]);
12972
		unset($conf["external::callShell"]);
226 liveuser 12973
 
3 liveuser 12974
		#如果執行cmd失敗
12975
		if($callShell["status"]==="false"){
226 liveuser 12976
 
3 liveuser 12977
			#設置執行不正常
12978
			$result["status"]="false";
226 liveuser 12979
 
3 liveuser 12980
			#設置錯誤訊息
12981
			$result["error"]=$callShell;
226 liveuser 12982
 
3 liveuser 12983
			#回傳結果
12984
			return $result;
226 liveuser 12985
 
12986
			}#if end
12987
 
3 liveuser 12988
		#取得輸出的內容陣列
12989
		$unzipInfo=$callShell["output"];
226 liveuser 12990
 
3 liveuser 12991
		/*
226 liveuser 12992
 
3 liveuser 12993
		 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
12994
		--------  ------  ------- ---- ---------- ----- --------  ----
12995
		 4194304  Defl:X  2507269  40% 05-04-2002 17:30 9386a740  PS2 Bios 30004R V6 Pal.bin
12996
			   4  Defl:X        6 -50% 05-15-2005 06:45 054a6ec2  PS2 Bios 30004R V6 Pal.MEC
12997
			1024  Defl:X       22  98% 06-25-2005 14:55 3493bb06  PS2 Bios 30004R V6 Pal.NVM
12998
		  199680  Defl:X    70524  65% 06-02-2004 16:50 2c3bcd32  rom1.bin
12999
		 4194304  Defl:X  2637496  37% 02-20-2005 21:12 6f8e3c29  SCPH-70004_BIOS_V12_PAL_200.BIN
13000
		 3145728  Defl:X  3138427   0% 02-20-2005 21:12 bf3cbc65  SCPH-70004_BIOS_V12_PAL_200.EROM
13001
			1024  Defl:X      706  31% 02-20-2005 21:12 a8d51ead  SCPH-70004_BIOS_V12_PAL_200.NVM
13002
		  524288  Defl:X   149924  71% 02-20-2005 21:12 0e8797c0  SCPH-70004_BIOS_V12_PAL_200.ROM1
13003
		  524288  Defl:X   149924  71% 02-20-2005 21:12 0e8797c0  SCPH-70004_BIOS_V12_PAL_200.ROM2
13004
		 4194304  Defl:X  2213105  47% 10-18-2000 06:06 b7ef81a9  scph10000.bin
13005
			1024  Defl:X       11  99% 01-01-2005 00:42 efb5af2e  scph10000.NVM
13006
		 4194304  Defl:X  2511182  40% 06-27-2003 10:51 a19e0bf5  scph39001.bin
13007
			   4  Defl:X        6 -50% 05-14-2005 16:00 054a6ec2  scph39001.MEC
13008
			1024  Defl:X       20  98% 05-31-2005 16:09 e14a6cd6  scph39001.NVM
13009
		--------          -------  ---                            -------
13010
		21175304         13378622  37%                            14 files
226 liveuser 13011
 
3 liveuser 13012
		*/
226 liveuser 13013
 
3 liveuser 13014
		#取得行數
13015
		$lineCount=count($unzipInfo);
226 liveuser 13016
 
3 liveuser 13017
		#取得標題
13018
		#函式說明:
13019
		#將固定格式的字串分開,並回傳分開的結果。
13020
		#回傳結果:
13021
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13022
		#$result["error"],錯誤訊息陣列
13023
		#$result["function"],當前執行的函數名稱.
13024
		#$result["oriStr"],要分割的原始字串內容
13025
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
13026
		#$result["dataCounts"],爲總共分成幾段
13027
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
13028
		#必填參數:
13029
		$conf["stringProcess::spiltString"]["stringIn"]=$unzipInfo[1];#要處理的字串。
13030
		$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
13031
		#可省略參數:
13032
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
13033
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
13034
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
13035
		unset($conf["stringProcess::spiltString"]);
226 liveuser 13036
 
3 liveuser 13037
		#如果分割字串失敗
13038
		if($spiltString["status"]==="false"){
226 liveuser 13039
 
3 liveuser 13040
			#設置執行不正常
13041
			$result["status"]="false";
226 liveuser 13042
 
3 liveuser 13043
			#設置錯誤訊息
13044
			$result["error"]=$spiltString;
226 liveuser 13045
 
3 liveuser 13046
			#回傳結果
13047
			return $result;
226 liveuser 13048
 
3 liveuser 13049
			}#if end
226 liveuser 13050
 
3 liveuser 13051
		#如果沒有分割用的關鍵字
13052
		if($spiltString["found"]==="false"){
226 liveuser 13053
 
3 liveuser 13054
			#設置執行不正常
13055
			$result["status"]="false";
226 liveuser 13056
 
3 liveuser 13057
			#設置錯誤訊息
13058
			$result["error"]=$spiltString;
226 liveuser 13059
 
3 liveuser 13060
			#回傳結果
13061
			return $result;
226 liveuser 13062
 
3 liveuser 13063
			}#if end
226 liveuser 13064
 
3 liveuser 13065
		#取得標題欄位
226 liveuser 13066
		$titles=$spiltString["dataArray"];
13067
 
3 liveuser 13068
		#取得標題欄位數目
13069
		$titleCount=$spiltString["dataCounts"];
226 liveuser 13070
 
3 liveuser 13071
		#針對每列輸出
13072
		for($i=3;$i<$lineCount-2;$i++){
226 liveuser 13073
 
3 liveuser 13074
			#取得各欄位的內容
13075
			#函式說明:
13076
			#將固定格式的字串分開,並回傳分開的結果。
13077
			#回傳結果:
13078
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13079
			#$result["error"],錯誤訊息陣列
13080
			#$result["function"],當前執行的函數名稱.
13081
			#$result["oriStr"],要分割的原始字串內容
13082
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
13083
			#$result["dataCounts"],爲總共分成幾段
13084
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
13085
			#必填參數:
13086
			$conf["stringProcess::spiltString"]["stringIn"]=$unzipInfo[$i];#要處理的字串。
13087
			$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
13088
			#可省略參數:
13089
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
13090
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
13091
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
13092
			unset($conf["stringProcess::spiltString"]);
226 liveuser 13093
 
3 liveuser 13094
			#如果分割字串失敗
13095
			if($spiltString["status"]==="false"){
226 liveuser 13096
 
3 liveuser 13097
				#設置執行不正常
13098
				$result["status"]="false";
226 liveuser 13099
 
3 liveuser 13100
				#設置錯誤訊息
13101
				$result["error"]=$spiltString;
226 liveuser 13102
 
3 liveuser 13103
				#回傳結果
13104
				return $result;
226 liveuser 13105
 
3 liveuser 13106
				}#if end
226 liveuser 13107
 
3 liveuser 13108
			#如果沒有分割用的關鍵字
13109
			if($spiltString["found"]==="false"){
226 liveuser 13110
 
3 liveuser 13111
				#設置執行不正常
13112
				$result["status"]="false";
226 liveuser 13113
 
3 liveuser 13114
				#設置錯誤訊息
13115
				$result["error"]=$spiltString;
226 liveuser 13116
 
3 liveuser 13117
				#回傳結果
13118
				return $result;
226 liveuser 13119
 
3 liveuser 13120
				}#if end
226 liveuser 13121
 
3 liveuser 13122
			#取得各欄位的內容
13123
			$cols=$spiltString["dataArray"];
226 liveuser 13124
 
3 liveuser 13125
			#取得欄位的數目
13126
			$colsCount=$spiltString["dataCounts"];
226 liveuser 13127
 
3 liveuser 13128
			#如果實際抓出的內容欄位數量大於標題欄位數量,代表檔案/目錄名稱含有空格
13129
			if($colsCount>$titleCount){
226 liveuser 13130
 
3 liveuser 13131
				#新的檔案名稱
13132
				$newFileName="";
226 liveuser 13133
 
3 liveuser 13134
				#針對每個多出的欄位
13135
				for($j=$titleCount;$j<$colsCount;$j++){
226 liveuser 13136
 
3 liveuser 13137
					#串接屬於檔案名稱的部分
13138
					$newFileName=$newFileName.$cols[$j];
226 liveuser 13139
 
3 liveuser 13140
					#如果不是最後一個項目
13141
					if($j!==$colsCount-1){
226 liveuser 13142
 
3 liveuser 13143
						#增加空格
13144
						$newFileName=$newFileName." ";
226 liveuser 13145
 
3 liveuser 13146
						}#if end
226 liveuser 13147
 
3 liveuser 13148
					}#for end
226 liveuser 13149
 
3 liveuser 13150
				#取代成對的檔案名稱
13151
				$cols[$titleCount-1]=$newFileName;
226 liveuser 13152
 
3 liveuser 13153
				}#if end
226 liveuser 13154
 
3 liveuser 13155
			#針對每個欄位
13156
			for($j=0;$j<$titleCount;$j++){
226 liveuser 13157
 
3 liveuser 13158
				#取得欄位內容
13159
				$result["content"]["each"][$titles[$j]][]=$cols[$j];
226 liveuser 13160
 
3 liveuser 13161
				}#for end
226 liveuser 13162
 
3 liveuser 13163
			}#for end
226 liveuser 13164
 
3 liveuser 13165
		#取得 total 的輸出內容
13166
		#函式說明:
13167
		#將固定格式的字串分開,並回傳分開的結果。
13168
		#回傳結果:
13169
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13170
		#$result["error"],錯誤訊息陣列
13171
		#$result["function"],當前執行的函數名稱.
13172
		#$result["oriStr"],要分割的原始字串內容
13173
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
13174
		#$result["dataCounts"],爲總共分成幾段
13175
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
13176
		#必填參數:
13177
		$conf["stringProcess::spiltString"]["stringIn"]=$unzipInfo[$lineCount-1];#要處理的字串。
13178
		$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
13179
		#可省略參數:
13180
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
13181
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
13182
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
13183
		unset($conf["stringProcess::spiltString"]);
226 liveuser 13184
 
3 liveuser 13185
		#如果分割字串失敗
13186
		if($spiltString["status"]==="false"){
226 liveuser 13187
 
3 liveuser 13188
			#設置執行不正常
13189
			$result["status"]="false";
226 liveuser 13190
 
3 liveuser 13191
			#設置錯誤訊息
13192
			$result["error"]=$spiltString;
226 liveuser 13193
 
3 liveuser 13194
			#回傳結果
13195
			return $result;
226 liveuser 13196
 
3 liveuser 13197
			}#if end
226 liveuser 13198
 
3 liveuser 13199
		#如果沒有分割用的關鍵字
13200
		if($spiltString["found"]==="false"){
226 liveuser 13201
 
3 liveuser 13202
			#設置執行不正常
13203
			$result["status"]="false";
226 liveuser 13204
 
3 liveuser 13205
			#設置錯誤訊息
13206
			$result["error"]=$spiltString;
226 liveuser 13207
 
3 liveuser 13208
			#回傳結果
13209
			return $result;
226 liveuser 13210
 
3 liveuser 13211
			}#if end
226 liveuser 13212
 
3 liveuser 13213
		#取得各欄位的內容
13214
		$cols=$spiltString["dataArray"];
226 liveuser 13215
 
3 liveuser 13216
		#取得總共的檔案長度
13217
		$result["content"]["total"][$titles[0]]=$cols[0];
226 liveuser 13218
 
3 liveuser 13219
		#取得壓縮時的總共檔案長度
13220
		$result["content"]["total"][$titles[2]]=$cols[1];
226 liveuser 13221
 
3 liveuser 13222
		#取得壓縮時的總共檔案長度
13223
		$result["content"]["total"][$titles[3]]=$cols[2];
226 liveuser 13224
 
3 liveuser 13225
		#取得解壓縮出了多少檔案跟目錄
13226
		$result["content"]["total"]["count"]=explode(" ",$cols[3])[0];
226 liveuser 13227
 
3 liveuser 13228
		#設置執行正常
13229
		$result["status"]="true";
226 liveuser 13230
 
3 liveuser 13231
		#回傳結果
13232
		return $result;
226 liveuser 13233
 
3 liveuser 13234
		}#function unzip end
226 liveuser 13235
 
3 liveuser 13236
	/*
13237
	#函式說明:
13238
	#接收Range: bytes=0-499格式的header, 輸出檔案的片段或完整檔案.
13239
	#回傳結果:
13240
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
13241
	#$result["error"],錯誤訊息.
13242
	#$result["function"],當前執行的函式名稱.
13243
	#必填參數:
13244
	#$conf["filePath"],字串,檔案的路徑.
13245
	$conf["filePath"]="";
13246
	#可省略參數:
13247
	#$conf["fileName"],字串,顯示的檔案名稱,預設為basename($conf["filePath"]);
13248
	#$conf["fileName"]="";
13249
	#參考資料:
13250
	#https://gdfan1114.wordpress.com/2015/01/14/php-%E5%AF%A6%E4%BD%9C%E6%94%AF%E6%8F%B4-http-%E7%BA%8C%E5%82%B3%E5%8A%9F%E8%83%BD/
13251
	#http://php.net/manual/en/function.filemtime.php
13252
	#http://php.net/manual/en/function.connection-status.php
13253
	#http://php.net/manual/en/function.fread.php
13254
	#備註:
13255
	#請勿在運行該函式前印出任何內容,這是要給用戶端接收的內容.
13256
	*/
13257
	public static function partDownload(&$conf=array()){
226 liveuser 13258
 
3 liveuser 13259
		#初始化要回傳的結果
13260
		$result=array();
13261
 
13262
		#取得當前執行的函數名稱
13263
		$result["function"]=__FUNCTION__;
13264
 
13265
		#如果沒有參數
13266
		if(func_num_args()==0){
226 liveuser 13267
 
3 liveuser 13268
			#設置執行失敗
13269
			$result["status"]="false";
226 liveuser 13270
 
3 liveuser 13271
			#設置執行錯誤訊息
13272
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 13273
 
3 liveuser 13274
			#回傳結果
13275
			return $result;
226 liveuser 13276
 
3 liveuser 13277
		}#if end
226 liveuser 13278
 
3 liveuser 13279
		#取得參數
13280
		$result["argu"]=$conf;
13281
 
13282
		#如果 $conf 不為陣列
13283
		if(gettype($conf)!=="array"){
226 liveuser 13284
 
3 liveuser 13285
			#設置執行失敗
13286
			$result["status"]="false";
226 liveuser 13287
 
3 liveuser 13288
			#設置執行錯誤訊息
13289
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 13290
 
3 liveuser 13291
			#如果傳入的參數為 null
13292
			if($conf===null){
226 liveuser 13293
 
3 liveuser 13294
				#設置執行錯誤訊息
13295
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 13296
 
3 liveuser 13297
				}#if end
13298
 
13299
			#回傳結果
13300
			return $result;
226 liveuser 13301
 
3 liveuser 13302
			}#if end
226 liveuser 13303
 
3 liveuser 13304
		#檢查參數
13305
		#函式說明:
13306
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
13307
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13308
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13309
		#$result["function"],當前執行的函式名稱.
13310
		#$result["argu"],設置給予的參數.
13311
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
13312
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
13313
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
13314
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
13315
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
13316
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
13317
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
13318
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
13319
		#必填寫的參數:
13320
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 13321
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 13322
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
13323
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
13324
		#可以省略的參數:
13325
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
13326
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePath");
13327
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
13328
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
13329
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
13330
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
13331
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
13332
		#$conf["canNotBeEmpty"]=array();
13333
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
13334
		#$conf["canBeEmpty"]=array();
13335
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
13336
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("fileName");
13337
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
13338
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileName");
226 liveuser 13339
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 13340
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
13341
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
13342
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
13343
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
13344
		#$conf["disallowAllSkipableVarIsEmpty"]="";
13345
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
13346
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
13347
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
13348
		#$conf["arrayCountEqualCheck"][]=array();
13349
		#參考資料來源:
13350
		#array_keys=>http://php.net/manual/en/function.array-keys.php
13351
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
13352
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 13353
 
3 liveuser 13354
		#如果檢查參數失敗
13355
		if($checkArguments["status"]==="false"){
226 liveuser 13356
 
3 liveuser 13357
			#設置執行失敗
13358
			$result["status"]="false";
226 liveuser 13359
 
3 liveuser 13360
			#設置執行錯誤
13361
			$result["error"]=$checkArguments;
226 liveuser 13362
 
3 liveuser 13363
			#回傳結果
13364
			return $result;
226 liveuser 13365
 
3 liveuser 13366
			}#if end
226 liveuser 13367
 
3 liveuser 13368
		#如果檢查參數不通過
13369
		if($checkArguments["passed"]==="false"){
226 liveuser 13370
 
3 liveuser 13371
			#設置執行失敗
13372
			$result["status"]="false";
226 liveuser 13373
 
3 liveuser 13374
			#設置執行錯誤
13375
			$result["error"]=$checkArguments;
226 liveuser 13376
 
3 liveuser 13377
			#回傳結果
13378
			return $result;
226 liveuser 13379
 
3 liveuser 13380
			}#if end
226 liveuser 13381
 
3 liveuser 13382
		#如果沒有設置 $conf["fileName"]
13383
		if(!isset($conf["fileName"])){
226 liveuser 13384
 
3 liveuser 13385
			#取得檔案名稱
13386
			$filename=basename($conf["filePath"]);
226 liveuser 13387
 
3 liveuser 13388
			}#if end
226 liveuser 13389
 
3 liveuser 13390
		#反之
13391
		else{
226 liveuser 13392
 
3 liveuser 13393
			#取得設定好的檔案名稱
13394
			$filename=&$conf["fileName"];
226 liveuser 13395
 
3 liveuser 13396
			}#else end
226 liveuser 13397
 
3 liveuser 13398
		#取得檔案路徑
13399
		$location=$conf["filePath"];
13400
 
13401
		#取得mimetype
13402
		$mimetype=mime_content_type($location);
226 liveuser 13403
 
3 liveuser 13404
		#如果檔案不存在
13405
		if(!file_exists($location)){
226 liveuser 13406
 
3 liveuser 13407
			#提示找不到檔案
13408
			header("HTTP/1.1 404 Not Found");
226 liveuser 13409
 
3 liveuser 13410
			#設置執行失敗
13411
			$result["status"]="false";
226 liveuser 13412
 
3 liveuser 13413
			#設置錯誤訊息
13414
			$result["error"][]="檔案 ".$location." 不存在.";
226 liveuser 13415
 
3 liveuser 13416
			#回傳結果
13417
			return $result;
226 liveuser 13418
 
3 liveuser 13419
			}#if end
13420
 
13421
		#取得檔案的bytes長度
13422
		$size  = filesize($location);
226 liveuser 13423
 
3 liveuser 13424
		#取得檔案的最後變更日期
13425
		$time  = date('r', filemtime($location));
13426
 
13427
		#讀取檔案的2元碼內容
13428
		$fm = @fopen($location, 'rb');
226 liveuser 13429
 
3 liveuser 13430
		#如果開啟檔案失敗
13431
		if(!$fm){
226 liveuser 13432
 
3 liveuser 13433
			#提示錯誤
13434
			header("HTTP/1.1 505 Internal server error");
226 liveuser 13435
 
3 liveuser 13436
			#設置執行失敗
13437
			$result["status"]="false";
226 liveuser 13438
 
3 liveuser 13439
			#設置錯誤訊息
13440
			$result["error"][]="開啟檔案 ".$location." 失敗.";
226 liveuser 13441
 
3 liveuser 13442
			#回傳結果
13443
			return $result;
226 liveuser 13444
 
3 liveuser 13445
			}#if end
13446
 
13447
		#初始化要提供的bytes長度起始點
13448
		$begin  = 0;
226 liveuser 13449
 
3 liveuser 13450
		#初始化要提供的bytes長度結束點
13451
		$end  = $size - 1;
13452
 
13453
		#如果有接收到 'HTTP_RANGE' 的 header 訊息
13454
		if(isset($_SERVER['HTTP_RANGE'])){
226 liveuser 13455
 
3 liveuser 13456
			#接收到的範例
226 liveuser 13457
			#Range: bytes=0-499
13458
 
3 liveuser 13459
			#取得要求的bytes位置範圍
13460
			sscanf($_SERVER['HTTP_RANGE'], "bytes=%d-%d",$begin,$end);
226 liveuser 13461
 
3 liveuser 13462
			#如果 $begin 或 $end  有缺
13463
			if(!isset($begin) || !isset($end)){
226 liveuser 13464
 
3 liveuser 13465
				#設置執行失敗
13466
				$result["status"]="false";
226 liveuser 13467
 
3 liveuser 13468
				#設置錯誤訊息
13469
				$result["error"][]="header \"Range\" 的數值格式為 \"bytes=0-499\"";
226 liveuser 13470
 
3 liveuser 13471
				#回傳結果
13472
				return $result;
226 liveuser 13473
 
3 liveuser 13474
				}#if end
226 liveuser 13475
 
3 liveuser 13476
			#如果 $begin 沒有小於等於 $end
13477
			if(!($begin<=$end)){
226 liveuser 13478
 
3 liveuser 13479
				#設置執行失敗
13480
				$result["status"]="false";
226 liveuser 13481
 
3 liveuser 13482
				#設置錯誤訊息
13483
				$result["error"][]="header \"Range\" 的數值格式為 \"bytes=0-499\"";
226 liveuser 13484
 
3 liveuser 13485
				#回傳結果
13486
				return $result;
226 liveuser 13487
 
3 liveuser 13488
				}#if end
226 liveuser 13489
 
3 liveuser 13490
			}#if end
226 liveuser 13491
 
3 liveuser 13492
		#提示 200 ok
13493
		header('HTTP/1.1 200 OK');
226 liveuser 13494
 
3 liveuser 13495
		#提示 mimetype
13496
		header("Content-Type: $mimetype");
226 liveuser 13497
 
3 liveuser 13498
		#要先驗證cache中的資料,取得的內容放在快取的時間為0
13499
		header('Cache-Control: public, must-revalidate, max-age=0');
226 liveuser 13500
 
3 liveuser 13501
		#提示不要cache
226 liveuser 13502
		header('Pragma: no-cache');
13503
 
3 liveuser 13504
		#提示接收的 Ranges 單位為 bytes
13505
		header('Accept-Ranges: bytes');
226 liveuser 13506
 
3 liveuser 13507
		#數值傳輸的內容長度為多少
13508
		header('Content-Length:' . (($end - $begin) + 1));
226 liveuser 13509
 
3 liveuser 13510
		#提示內容為檔案的哪邊到哪邊與總共的長度
13511
		header("Content-Range: bytes $begin-$end/$size");
226 liveuser 13512
 
3 liveuser 13513
		#提示檔案的名稱
13514
		header("Content-Disposition: inline; filename=$filename");
226 liveuser 13515
 
3 liveuser 13516
		#提示用2元碼傳輸
13517
		header("Content-Transfer-Encoding: binary");
226 liveuser 13518
 
3 liveuser 13519
		#提示檔案最後變更日期
13520
		header("Last-Modified: $time");
13521
 
13522
		#初始化當前位置
13523
		$cur  = $begin;
226 liveuser 13524
 
13525
		#指定讀取的起始點為 $begin
3 liveuser 13526
		fseek($fm, $begin, 0);
13527
 
13528
		#讀取內容, 若不是檔案結尾, 且當前位置($cur)小於等於 本次要提供的長度結尾($end), 且connection_status為0
13529
		while(!feof($fm) && $cur<=$end && (connection_status()===0)){
226 liveuser 13530
 
3 liveuser 13531
			#一次最多印出 1024*16bytes 的長度,若剩下長度不足則只印出剩下的長度.
13532
			echo fread($fm, min(1024 * 16, ($end - $cur) + 1));
226 liveuser 13533
 
3 liveuser 13534
			#更改位置
13535
			$cur += 1024 * 16;
226 liveuser 13536
 
3 liveuser 13537
			}#while end
226 liveuser 13538
 
3 liveuser 13539
		}#function partDownload end
226 liveuser 13540
 
3 liveuser 13541
	/*
13542
	#函式說明:
226 liveuser 13543
	#尋找檔案.
3 liveuser 13544
	#回傳結果:
13545
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13546
	#$result["error"],錯誤訊息.
13547
	#$result["warning"],警告訊息陣列.
13548
	#$result["function"],當前執行的函數名稱.
13549
	#$result["argu"],所使用的參數.
13550
	#$result["found"],是否有找到可以轉換的檔案,"true"代表有;"false"代表沒有.
13551
	#$result["content"],找到的檔案陣列.
13552
	#必填參數:
13553
	#$conf["keyWord"],字串,要搜尋的檔案關鍵字,可用"*"符號,例如"*.qcow2",就代表檔案名成為"qcow2"結尾的檔案.
13554
	$conf["keyWord"]="";
13555
	#$conf["path"],字串陣列,虛擬硬碟檔案的搜尋路徑,預設為當前路徑.
13556
	$conf["path"]=array();
13557
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13558
	$conf["fileArgu"]=__FILE__;
13559
	#參考資料:
13560
	#http://php.net/manual/en/function.glob.php
13561
	#備註:
13562
	#無.
13563
	*/
13564
	public static function findFile(&$conf=array()){
226 liveuser 13565
 
3 liveuser 13566
		#初始化要回傳的結果
13567
		$result=array();
13568
 
13569
		#取得當前執行的函數名稱
13570
		$result["function"]=__FUNCTION__;
13571
 
13572
		#如果沒有參數
13573
		if(func_num_args()==0){
226 liveuser 13574
 
3 liveuser 13575
			#設置執行失敗
13576
			$result["status"]="false";
226 liveuser 13577
 
3 liveuser 13578
			#設置執行錯誤訊息
13579
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 13580
 
3 liveuser 13581
			#回傳結果
13582
			return $result;
13583
 
226 liveuser 13584
			}#if end
13585
 
3 liveuser 13586
		#取得參數
13587
		$result["argu"]=$conf;
13588
 
13589
		#如果 $conf 不為陣列
13590
		if(gettype($conf)!=="array"){
226 liveuser 13591
 
3 liveuser 13592
			#設置執行失敗
13593
			$result["status"]="false";
226 liveuser 13594
 
3 liveuser 13595
			#設置執行錯誤訊息
13596
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 13597
 
3 liveuser 13598
			#如果傳入的參數為 null
13599
			if($conf===null){
226 liveuser 13600
 
3 liveuser 13601
				#設置執行錯誤訊息
13602
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 13603
 
3 liveuser 13604
				}#if end
13605
 
13606
			#回傳結果
13607
			return $result;
226 liveuser 13608
 
3 liveuser 13609
			}#if end
226 liveuser 13610
 
3 liveuser 13611
		#函式說明:
13612
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
13613
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13614
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13615
		#$result["function"],當前執行的函式名稱.
13616
		#$result["argu"],設置給予的參數.
13617
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
13618
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
13619
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
13620
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
13621
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
13622
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
13623
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
13624
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
13625
		#必填寫的參數:
13626
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 13627
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 13628
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
13629
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
13630
		#可以省略的參數:
13631
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
13632
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","keyWord","fileArgu");
13633
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
13634
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string","string");
13635
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
13636
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
13637
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
13638
		#$conf["canNotBeEmpty"]=array();
13639
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
13640
		#$conf["canBeEmpty"]=array();
13641
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
13642
		#$conf["skipableVariableCanNotBeEmpty"]=array();
13643
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
13644
		#$conf["skipableVariableName"]=array();
226 liveuser 13645
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 13646
		#$conf["skipableVariableType"]=array();
13647
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
13648
		#$conf["skipableVarDefaultValue"]=array("");
13649
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
13650
		#$conf["disallowAllSkipableVarIsEmpty"]="";
13651
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
13652
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
13653
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
13654
		#$conf["arrayCountEqualCheck"][]=array();
13655
		#參考資料來源:
13656
		#array_keys=>http://php.net/manual/en/function.array-keys.php
13657
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
13658
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 13659
 
3 liveuser 13660
		#如果檢查參數失敗
13661
		if($checkArguments["status"]==="false"){
226 liveuser 13662
 
3 liveuser 13663
			#設置執行失敗
13664
			$result["status"]="false";
226 liveuser 13665
 
3 liveuser 13666
			#設置執行失敗訊息
13667
			$result["error"]=$checkArguments;
226 liveuser 13668
 
3 liveuser 13669
			#回傳結果
13670
			return $result;
226 liveuser 13671
 
3 liveuser 13672
			}#if end
226 liveuser 13673
 
3 liveuser 13674
		#如果檢查參數不通過
13675
		if($checkArguments["passed"]==="false"){
226 liveuser 13676
 
3 liveuser 13677
			#設置執行失敗
13678
			$result["status"]="false";
226 liveuser 13679
 
3 liveuser 13680
			#設置執行失敗訊息
13681
			$result["error"]=$checkArguments;
226 liveuser 13682
 
3 liveuser 13683
			#回傳結果
13684
			return $result;
226 liveuser 13685
 
3 liveuser 13686
			}#if end
226 liveuser 13687
 
3 liveuser 13688
		#檢查要搜尋的路徑是否都存在
13689
		#函式說明:
13690
		#s檢查多個檔案與資料夾是否存在.
13691
		#回傳的結果:
13692
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
13693
		#$result["error"],錯誤訊息陣列.
13694
		#$resutl["function"],當前執行的涵式名稱.
13695
		#$result["argu"],使用的參數.
13696
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
13697
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
13698
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
13699
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
13700
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
13701
		#必填參數:
13702
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
13703
		$conf["self::checkMultiFileExist"]["fileArray"]=$conf["path"];
13704
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13705
		$conf["self::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
13706
		#可省略參數
13707
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
13708
		#$conf["disableWebSearch"]="false";
13709
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
13710
		#$conf["userDir"]="true";
13711
		#參考資料來源:
13712
		#http://php.net/manual/en/function.file-exists.php
13713
		#http://php.net/manual/en/control-structures.foreach.php
13714
		#備註:
13715
		#函數file_exists檢查的路徑為檔案系統的路徑
13716
		$checkMultiFileExist=self::checkMultiFileExist($conf["self::checkMultiFileExist"]);
13717
		unset($conf["self::checkMultiFileExist"]);
226 liveuser 13718
 
3 liveuser 13719
		#如果檢查目錄存在失敗
13720
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 13721
 
3 liveuser 13722
			#設置執行失敗
13723
			$result["status"]="false";
226 liveuser 13724
 
3 liveuser 13725
			#設置執行失敗訊息
13726
			$result["error"]=$checkMultiFileExist;
226 liveuser 13727
 
3 liveuser 13728
			#回傳結果
13729
			return $result;
226 liveuser 13730
 
13731
			}#if end
13732
 
3 liveuser 13733
		#如果目錄不存在
13734
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 13735
 
3 liveuser 13736
			#設置執行失敗
13737
			$result["status"]="false";
226 liveuser 13738
 
3 liveuser 13739
			#設置執行失敗訊息
13740
			$result["error"]=$checkMultiFileExist;
226 liveuser 13741
 
3 liveuser 13742
			#回傳結果
13743
			return $result;
226 liveuser 13744
 
3 liveuser 13745
			}#if end
226 liveuser 13746
 
3 liveuser 13747
		#如果有路徑不存在
13748
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 13749
 
3 liveuser 13750
			#設置執行失敗
13751
			$result["status"]="false";
226 liveuser 13752
 
3 liveuser 13753
			#設置執行失敗訊息
13754
			$result["error"]=$checkMultiFileExist;
226 liveuser 13755
 
3 liveuser 13756
			#設置提示有路徑不存在的訊息
13757
			$result["warning"][]="參數path的路徑沒有每個都存在";
226 liveuser 13758
 
3 liveuser 13759
			#回傳結果
13760
			return $result;
226 liveuser 13761
 
3 liveuser 13762
			}#if end
226 liveuser 13763
 
3 liveuser 13764
		#預設沒有找到檔案
226 liveuser 13765
		$result["found"]="false";
13766
 
3 liveuser 13767
		#針對每個要搜尋的路徑
13768
		foreach($conf["path"] as $path){
226 liveuser 13769
 
3 liveuser 13770
			#函式說明:
13771
			#用find指令尋找檔案
13772
			#回傳結果:
13773
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13774
			#$result["error"],錯誤訊息.
13775
			#$result["function"],當前執行的函數名稱.
13776
			#$result["argu"],所使用的參數.
13777
			#$result["found"],是否有找到符合的檔案,"true"代表有;"false"代表沒有.
13778
			#$result["content"],找到的檔案陣列.
13779
			#必填參數:
13780
			#$conf["keyWord"],字串,要搜尋的檔案關鍵字,可用"*"符號,例如"*.qcow2",就代表檔案名成為"qcow2"結尾的檔案.
226 liveuser 13781
			$conf["cmd::find"]["keyWord"]=$conf["keyWord"];
3 liveuser 13782
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13783
			$conf["cmd::find"]["fileArgu"]=$conf["fileArgu"];
13784
			#可省略參數:
13785
			#$conf["path"],字串,搜尋的路徑,預設為"/".
13786
			$conf["cmd::find"]["path"]=$path;
13787
			#$conf["fileOnly"],字串,"true"代表只要找檔案,"false"代表.
13788
			$conf["cmd::find"]["fileOnly"]="true";
13789
			#參考資料:
13790
			#http://php.net/manual/en/function.glob.php
13791
			$find=cmd::find($conf["cmd::find"]);
13792
			unset($conf["cmd::find"]);
226 liveuser 13793
 
3 liveuser 13794
			#如果尋找檔案失敗
13795
			if($find["status"]==="false"){
226 liveuser 13796
 
3 liveuser 13797
				#設置執行失敗
13798
				$result["status"]="false";
226 liveuser 13799
 
3 liveuser 13800
				#設置執行失敗訊息
13801
				$result["error"]=$find;
226 liveuser 13802
 
3 liveuser 13803
				#回傳結果
13804
				return $result;
226 liveuser 13805
 
3 liveuser 13806
				}#if end
226 liveuser 13807
 
3 liveuser 13808
			#如果有找到符合的檔案
13809
			if($find["found"]==="true"){
226 liveuser 13810
 
3 liveuser 13811
				#設置有找到檔案
13812
				$result["found"]="true";
226 liveuser 13813
 
3 liveuser 13814
				#針對每個找到的檔案
13815
				foreach($find["content"] as $filtedFile){
226 liveuser 13816
 
3 liveuser 13817
					#設置有找到的檔案
13818
					$result["content"][]=$filtedFile;
226 liveuser 13819
 
3 liveuser 13820
					}#foreach end
226 liveuser 13821
 
3 liveuser 13822
				}#if end
226 liveuser 13823
 
13824
			}#foreach end
13825
 
3 liveuser 13826
		#設置執行正常
13827
		$result["status"]="true";
226 liveuser 13828
 
3 liveuser 13829
		#回傳結果
13830
		return $result;
226 liveuser 13831
 
3 liveuser 13832
		}#function findFile end
13833
 
13834
	/*
13835
	#函式說明:
13836
	#判斷檔案位於哪個分割區
13837
	#回傳結果:
13838
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13839
	#$result["error"],錯誤訊息.
13840
	#$result["function"],當前執行的函數名稱.
13841
	#$result["argu"],所使用的參數.
13842
	#$result["content"],找到的檔案所屬分割區資訊.
13843
	#必填參數:
13844
	#$conf["file"],字串,檔案的路徑與名稱.
13845
	$conf["file"]="";
13846
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13847
	$conf["fileArgu"]=__FILE__;
13848
	#可省略參數:
13849
	#無.
13850
	#參考資料:
13851
	#無.
13852
	#備註:
13853
	#無.
13854
	*/
13855
	public static function addrInMountPoint(&$conf=array()){
226 liveuser 13856
 
3 liveuser 13857
		#初始化要回傳的結果
13858
		$result=array();
13859
 
13860
		#取得當前執行的函數名稱
13861
		$result["function"]=__FUNCTION__;
13862
 
13863
		#如果沒有參數
13864
		if(func_num_args()==0){
226 liveuser 13865
 
3 liveuser 13866
			#設置執行失敗
13867
			$result["status"]="false";
226 liveuser 13868
 
3 liveuser 13869
			#設置執行錯誤訊息
13870
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 13871
 
3 liveuser 13872
			#回傳結果
13873
			return $result;
13874
 
226 liveuser 13875
			}#if end
13876
 
3 liveuser 13877
		#取得參數
13878
		$result["argu"]=$conf;
13879
 
13880
		#如果 $conf 不為陣列
13881
		if(gettype($conf)!=="array"){
226 liveuser 13882
 
3 liveuser 13883
			#設置執行失敗
13884
			$result["status"]="false";
226 liveuser 13885
 
3 liveuser 13886
			#設置執行錯誤訊息
13887
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 13888
 
3 liveuser 13889
			#如果傳入的參數為 null
13890
			if($conf===null){
226 liveuser 13891
 
3 liveuser 13892
				#設置執行錯誤訊息
13893
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 13894
 
3 liveuser 13895
				}#if end
13896
 
13897
			#回傳結果
13898
			return $result;
226 liveuser 13899
 
3 liveuser 13900
			}#if end
226 liveuser 13901
 
3 liveuser 13902
		#函式說明:
13903
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
13904
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13905
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13906
		#$result["function"],當前執行的函式名稱.
13907
		#$result["argu"],設置給予的參數.
13908
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
13909
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
13910
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
13911
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
13912
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
13913
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
13914
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
13915
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
13916
		#必填寫的參數:
13917
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 13918
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 13919
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
13920
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
13921
		#可以省略的參數:
13922
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
13923
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
13924
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
13925
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
13926
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
13927
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
13928
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
13929
		#$conf["canNotBeEmpty"]=array();
13930
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
13931
		#$conf["canBeEmpty"]=array();
13932
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
13933
		#$conf["skipableVariableCanNotBeEmpty"]=array();
13934
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
13935
		#$conf["skipableVariableName"]=array();
226 liveuser 13936
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 13937
		#$conf["skipableVariableType"]=array();
13938
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
13939
		#$conf["skipableVarDefaultValue"]=array("");
13940
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
13941
		#$conf["disallowAllSkipableVarIsEmpty"]="";
13942
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
13943
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
13944
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
13945
		#$conf["arrayCountEqualCheck"][]=array();
13946
		#參考資料來源:
13947
		#array_keys=>http://php.net/manual/en/function.array-keys.php
13948
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
13949
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 13950
 
3 liveuser 13951
		#如果檢查參數失敗
13952
		if($checkArguments["status"]==="false"){
226 liveuser 13953
 
3 liveuser 13954
			#設置執行失敗
13955
			$result["status"]="false";
226 liveuser 13956
 
3 liveuser 13957
			#設置執行失敗訊息
13958
			$result["error"]=$checkArguments;
226 liveuser 13959
 
3 liveuser 13960
			#回傳結果
13961
			return $result;
226 liveuser 13962
 
3 liveuser 13963
			}#if end
226 liveuser 13964
 
3 liveuser 13965
		#如果檢查參數不通過
13966
		if($checkArguments["passed"]==="false"){
226 liveuser 13967
 
3 liveuser 13968
			#設置執行失敗
13969
			$result["status"]="false";
226 liveuser 13970
 
3 liveuser 13971
			#設置執行失敗訊息
13972
			$result["error"]=$checkArguments;
226 liveuser 13973
 
3 liveuser 13974
			#回傳結果
13975
			return $result;
226 liveuser 13976
 
3 liveuser 13977
			}#if end
226 liveuser 13978
 
3 liveuser 13979
		#函式說明:
13980
		#透過lsblk指令的輸出取得已經掛載的blk.
13981
		#回傳結果:
13982
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13983
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13984
		#$result["function"],當前執行的函式名稱.
13985
		#$result["content"],lsblk的輸出內容.
13986
		#必填參數:
13987
		#$conf["fileArgu"],字串,變數__FILE__的內容.
13988
		$conf["cmd::lsblk"]["fileArgu"]=$conf["fileArgu"];
13989
		#可省略參數:
226 liveuser 13990
		#無.
3 liveuser 13991
		$lsblk=cmd::lsblk($conf["cmd::lsblk"]);
13992
		unset($conf["cmd::lsblk"]);
226 liveuser 13993
 
3 liveuser 13994
		#如果執行失敗
13995
		if($lsblk["status"]==="false"){
226 liveuser 13996
 
3 liveuser 13997
			#設置執行失敗
13998
			$result["status"]="false";
226 liveuser 13999
 
3 liveuser 14000
			#設置執行失敗訊息
14001
			$result["error"]=$lsblk;
226 liveuser 14002
 
3 liveuser 14003
			#回傳結果
14004
			return $result;
226 liveuser 14005
 
3 liveuser 14006
			}#if end
226 liveuser 14007
 
3 liveuser 14008
		#將 $conf["file"] 轉換成絕對路徑
14009
		#函式說明:
14010
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
14011
		#回傳結果:
14012
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
14013
		#$result["error"],錯誤訊息陣列.
226 liveuser 14014
		#$result["function"],函數名稱.
3 liveuser 14015
		#$result["argu"],使用的參數.
14016
		#$result["content"],網址,若是在命令列執行,則為"null".
14017
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
14018
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
14019
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
14020
		#必填參數:
14021
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
14022
		$conf["fileAccess::getInternetAddress"]["address"]=$conf["file"];
14023
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
14024
		$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
14025
		#可省略參數:
14026
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
14027
		#$conf["userDir"]="true";
14028
		$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
14029
		unset($conf["fileAccess::getInternetAddress"]);
226 liveuser 14030
 
3 liveuser 14031
		#如果執行失敗
14032
		if($getInternetAddress["status"]==="false"){
226 liveuser 14033
 
3 liveuser 14034
			#設置執行失敗
14035
			$result["status"]="false";
226 liveuser 14036
 
3 liveuser 14037
			#設置執行失敗訊息
14038
			$result["error"]=$getInternetAddress;
226 liveuser 14039
 
3 liveuser 14040
			#回傳結果
14041
			return $result;
226 liveuser 14042
 
14043
			}#if end
14044
 
3 liveuser 14045
		#使用絕對位置作為輸入字串
14046
		#函式說明:
14047
		#尋找字串是否存在對應的關鍵字,且符合的最常關鍵字為何?
14048
		#回傳結果:
14049
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14050
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14051
		#$result["function"],當前執行的函式名稱.
14052
		#$result["argu"],所使用的參數.
14053
		#$result["founded"],是否有找到關鍵字,"true"代表有找到,"false"代表沒有找到.
14054
		#$result["content"],最符合的字串完整內容.
14055
		#必填參數:
14056
		#$conf["input"],字串,要比對的字串陣列.
14057
		$conf["search::findLikelyStr"]["input"]=$getInternetAddress["fileSystemAbsoulutePosition"];
14058
		#$conf["keyWord"],字串陣列,要搜尋的關鍵字.
14059
		$conf["search::findLikelyStr"]["keyWord"]=$lsblk["content"]["MOUNTPOINT"];
14060
		$findLikelyStr=search::findLikelyStr($conf["search::findLikelyStr"]);
14061
		unset($conf["search::findLikelyStr"]);
226 liveuser 14062
 
3 liveuser 14063
		#如果執行失敗
14064
		if($findLikelyStr["status"]==="false"){
226 liveuser 14065
 
3 liveuser 14066
			#設置執行失敗
14067
			$result["status"]="false";
226 liveuser 14068
 
3 liveuser 14069
			#設置執行失敗訊息
14070
			$result["error"]=$findLikelyStr;
226 liveuser 14071
 
3 liveuser 14072
			#回傳結果
14073
			return $result;
226 liveuser 14074
 
3 liveuser 14075
			}#if end
226 liveuser 14076
 
3 liveuser 14077
		#如果找不到歸屬的分割區
14078
		if($findLikelyStr["found"]==="false"){
226 liveuser 14079
 
3 liveuser 14080
			#設置執行失敗
14081
			$result["status"]="false";
226 liveuser 14082
 
3 liveuser 14083
			#設置執行失敗訊息
14084
			$result["error"]=$findLikelyStr;
226 liveuser 14085
 
3 liveuser 14086
			#回傳結果
14087
			return $result;
226 liveuser 14088
 
3 liveuser 14089
			}#if end
226 liveuser 14090
 
3 liveuser 14091
		#設置歸屬的分割區資訊
14092
		$result["content"]=$findLikelyStr["content"];
226 liveuser 14093
 
3 liveuser 14094
		#設置執行正常
14095
		$result["status"]="true";
226 liveuser 14096
 
3 liveuser 14097
		#回傳結果
14098
		return $result;
226 liveuser 14099
 
3 liveuser 14100
		}#function addrInMountPoint end
14101
 
14102
	/*
14103
	#函式說明:
14104
	#取得檔案的副檔名
14105
	#回傳結果:
14106
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14107
	#$result["error"],錯誤訊息.
14108
	#$result["function"],當前執行的函數名稱.
226 liveuser 14109
	#$result["argu"],所使用的參數.
3 liveuser 14110
	#$result["content"],副檔名.
14111
	#$result["name"],不含副檔的名稱.
14112
	#$result["fullName"],含副檔的名稱.
14113
	#$result["path"],檔案所處的路徑.
14114
	#必填參數:
14115
	#$conf["file"],字串,檔案的路徑與名稱.
14116
	$conf["file"]="";
14117
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14118
	$conf["fileArgu"]=__FILE__;
14119
	#可省略參數:
14120
	#無.
14121
	#參考資料:
14122
	#無.
14123
	#備註:
14124
	#無.
14125
	*/
14126
	public static function getExtension(&$conf=array()){
226 liveuser 14127
 
3 liveuser 14128
		#初始化要回傳的結果
14129
		$result=array();
14130
 
14131
		#取得當前執行的函數名稱
14132
		$result["function"]=__FUNCTION__;
14133
 
14134
		#如果沒有參數
14135
		if(func_num_args()==0){
226 liveuser 14136
 
3 liveuser 14137
			#設置執行失敗
14138
			$result["status"]="false";
226 liveuser 14139
 
3 liveuser 14140
			#設置執行錯誤訊息
14141
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 14142
 
3 liveuser 14143
			#回傳結果
14144
			return $result;
14145
 
226 liveuser 14146
			}#if end
14147
 
3 liveuser 14148
		#取得參數
14149
		$result["argu"]=$conf;
14150
 
14151
		#如果 $conf 不為陣列
14152
		if(gettype($conf)!=="array"){
226 liveuser 14153
 
3 liveuser 14154
			#設置執行失敗
14155
			$result["status"]="false";
226 liveuser 14156
 
3 liveuser 14157
			#設置執行錯誤訊息
14158
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 14159
 
3 liveuser 14160
			#如果傳入的參數為 null
14161
			if($conf===null){
226 liveuser 14162
 
3 liveuser 14163
				#設置執行錯誤訊息
14164
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 14165
 
3 liveuser 14166
				}#if end
14167
 
14168
			#回傳結果
14169
			return $result;
226 liveuser 14170
 
3 liveuser 14171
			}#if end
226 liveuser 14172
 
3 liveuser 14173
		#函式說明:
14174
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
14175
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14176
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14177
		#$result["function"],當前執行的函式名稱.
14178
		#$result["argu"],設置給予的參數.
14179
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
14180
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
14181
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
14182
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
14183
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
14184
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
14185
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
14186
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
14187
		#必填寫的參數:
14188
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 14189
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 14190
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
14191
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
14192
		#可以省略的參數:
14193
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
14194
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
14195
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
14196
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
14197
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
14198
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
14199
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
14200
		#$conf["canNotBeEmpty"]=array();
14201
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
14202
		#$conf["canBeEmpty"]=array();
14203
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
14204
		#$conf["skipableVariableCanNotBeEmpty"]=array();
14205
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
14206
		#$conf["skipableVariableName"]=array();
226 liveuser 14207
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 14208
		#$conf["skipableVariableType"]=array();
14209
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
14210
		#$conf["skipableVarDefaultValue"]=array("");
14211
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
14212
		#$conf["disallowAllSkipableVarIsEmpty"]="";
14213
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
14214
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
14215
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
14216
		#$conf["arrayCountEqualCheck"][]=array();
14217
		#參考資料來源:
14218
		#array_keys=>http://php.net/manual/en/function.array-keys.php
14219
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
14220
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 14221
 
3 liveuser 14222
		#如果檢查參數失敗
14223
		if($checkArguments["status"]==="false"){
226 liveuser 14224
 
3 liveuser 14225
			#設置執行失敗
14226
			$result["status"]="false";
226 liveuser 14227
 
3 liveuser 14228
			#設置執行失敗訊息
14229
			$result["error"]=$checkArguments;
226 liveuser 14230
 
3 liveuser 14231
			#回傳結果
14232
			return $result;
226 liveuser 14233
 
3 liveuser 14234
			}#if end
226 liveuser 14235
 
3 liveuser 14236
		#如果檢查參數不通過
14237
		if($checkArguments["passed"]==="false"){
226 liveuser 14238
 
3 liveuser 14239
			#設置執行失敗
14240
			$result["status"]="false";
226 liveuser 14241
 
3 liveuser 14242
			#設置執行失敗訊息
14243
			$result["error"]=$checkArguments;
226 liveuser 14244
 
3 liveuser 14245
			#回傳結果
14246
			return $result;
226 liveuser 14247
 
3 liveuser 14248
			}#if end
226 liveuser 14249
 
3 liveuser 14250
		#初始化檔案的路徑
14251
		$result["path"]="./";
226 liveuser 14252
 
3 liveuser 14253
		#用 "/" 來分割字串
14254
		#函式說明:
14255
		#將固定格式的字串分開,並回傳分開的結果。
14256
		#回傳結果:
14257
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14258
		#$result["error"],錯誤訊息陣列
14259
		#$result["function"],當前執行的函數名稱.
14260
		#$result["oriStr"],要分割的原始字串內容
14261
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
14262
		#$result["dataCounts"],爲總共分成幾段
14263
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
14264
		#必填參數:
14265
		$conf["stringProcess::spiltString"]["stringIn"]=$conf["file"];#要處理的字串。
14266
		$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
14267
		#可省略參數:
14268
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
14269
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
14270
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
14271
		unset($conf["stringProcess::spiltString"]);
226 liveuser 14272
 
3 liveuser 14273
		#如果檢查參數失敗
14274
		if($spiltString["status"]==="false"){
226 liveuser 14275
 
3 liveuser 14276
			#設置執行失敗
14277
			$result["status"]="false";
226 liveuser 14278
 
3 liveuser 14279
			#設置執行失敗訊息
14280
			$result["error"]=$spiltString;
226 liveuser 14281
 
3 liveuser 14282
			#回傳結果
14283
			return $result;
226 liveuser 14284
 
3 liveuser 14285
			}#if end
226 liveuser 14286
 
3 liveuser 14287
		#初始化含副檔名的檔案名稱
14288
		$result["fullName"]=$conf["file"];
226 liveuser 14289
 
3 liveuser 14290
		#如果有"/"存在
14291
		if($spiltString["found"]==="true"){
226 liveuser 14292
 
3 liveuser 14293
			#取得含副檔名的檔案名稱
14294
			$result["fullName"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
226 liveuser 14295
 
3 liveuser 14296
			#取得檔案的路徑
14297
			$result["path"]=substr($conf["file"],0,strlen($conf["file"])-strlen($result["fullName"]));
226 liveuser 14298
 
3 liveuser 14299
			}#if end
226 liveuser 14300
 
3 liveuser 14301
		#用 "." 來分割字串
14302
		#函式說明:
14303
		#將固定格式的字串分開,並回傳分開的結果。
14304
		#回傳結果:
14305
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14306
		#$result["error"],錯誤訊息陣列
14307
		#$result["function"],當前執行的函數名稱.
14308
		#$result["oriStr"],要分割的原始字串內容
14309
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
14310
		#$result["dataCounts"],爲總共分成幾段
14311
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
14312
		#必填參數:
14313
		$conf["stringProcess::spiltString"]["stringIn"]=$result["fullName"];#要處理的字串。
14314
		$conf["stringProcess::spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
14315
		#可省略參數:
14316
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
14317
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
14318
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
14319
		unset($conf["stringProcess::spiltString"]);
226 liveuser 14320
 
3 liveuser 14321
		#如果檢查參數失敗
14322
		if($spiltString["status"]==="false"){
226 liveuser 14323
 
3 liveuser 14324
			#設置執行失敗
14325
			$result["status"]="false";
226 liveuser 14326
 
3 liveuser 14327
			#設置執行失敗訊息
14328
			$result["error"]=$spiltString;
226 liveuser 14329
 
3 liveuser 14330
			#回傳結果
14331
			return $result;
226 liveuser 14332
 
3 liveuser 14333
			}#if end
226 liveuser 14334
 
3 liveuser 14335
		#預設副檔名為 ""
14336
		$result["content"]="";
226 liveuser 14337
 
3 liveuser 14338
		#預設不含副檔名的檔案名稱
14339
		$result["name"]=$result["fullName"];
226 liveuser 14340
 
3 liveuser 14341
		#如果有"."存在
14342
		if($spiltString["found"]==="true"){
226 liveuser 14343
 
3 liveuser 14344
			#取得含副檔名
14345
			$result["content"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
226 liveuser 14346
 
3 liveuser 14347
			#取得不含副檔名的檔案名稱
226 liveuser 14348
			$result["name"]=substr($result["fullName"],0,strlen($result["fullName"])-strlen($result["content"])-1);
14349
 
3 liveuser 14350
			}#if end
226 liveuser 14351
 
3 liveuser 14352
		#設置執行正常
14353
		$result["status"]="true";
226 liveuser 14354
 
3 liveuser 14355
		#回傳結果
14356
		return $result;
226 liveuser 14357
 
3 liveuser 14358
		}#function getExtension end
14359
 
14360
	/*
14361
	#函式說明:
14362
	#從檔案尾部開始讀取
14363
	#回傳結果:
14364
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14365
	#$result["error"],錯誤訊息.
14366
	#$result["function"],當前執行的函數名稱.
226 liveuser 14367
	#$result["argu"],所使用的參數.
3 liveuser 14368
	#$result["content"],讀取到的內容陣列.
14369
	#$result["totalLineCount"],檔案的總共行數.
14370
	#$result["lines"],取得輸出的行數.
14371
	#$result["lineNum"],取得當前行數.
14372
	#必填參數:
14373
	#$conf["file"],字串,檔案的路徑與名稱.
14374
	$conf["file"]="";
14375
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14376
	$conf["fileArgu"]=__FILE__;
14377
	#可省略參數:
14378
	#$conf["web"],字串,"true"代表位網頁系統,"false"為檔案系統,預設為"false".
14379
	#$conf["web"]="false";
14380
	#$conf["line2start"],字串,從第幾列開始,預設為總行書減去linesPerTime+1.
14381
	#$conf["line2start"]="";
14382
	#$conf["linesPerTime"],字串,一次最多讀取幾列,預設爲10列.
226 liveuser 14383
	#$conf["linesPerTime"]="10";
3 liveuser 14384
	#參考資料:
14385
	#無.
14386
	#備註:
14387
	#無.
14388
	*/
14389
	public static function tail(&$conf){
14390
 
14391
		#初始化要回傳的結果
14392
		$result=array();
14393
 
14394
		#取得當前執行的函數名稱
14395
		$result["function"]=__FUNCTION__;
14396
 
14397
		#如果沒有參數
14398
		if(func_num_args()==0){
226 liveuser 14399
 
3 liveuser 14400
			#設置執行失敗
14401
			$result["status"]="false";
226 liveuser 14402
 
3 liveuser 14403
			#設置執行錯誤訊息
14404
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 14405
 
3 liveuser 14406
			#回傳結果
14407
			return $result;
14408
 
226 liveuser 14409
			}#if end
14410
 
3 liveuser 14411
		#取得參數
14412
		$result["argu"]=$conf;
14413
 
14414
		#如果 $conf 不為陣列
14415
		if(gettype($conf)!=="array"){
226 liveuser 14416
 
3 liveuser 14417
			#設置執行失敗
14418
			$result["status"]="false";
226 liveuser 14419
 
3 liveuser 14420
			#設置執行錯誤訊息
14421
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 14422
 
3 liveuser 14423
			#如果傳入的參數為 null
14424
			if($conf===null){
226 liveuser 14425
 
3 liveuser 14426
				#設置執行錯誤訊息
14427
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 14428
 
3 liveuser 14429
				}#if end
14430
 
14431
			#回傳結果
14432
			return $result;
226 liveuser 14433
 
3 liveuser 14434
			}#if end
226 liveuser 14435
 
3 liveuser 14436
		#函式說明:
14437
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
14438
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14439
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14440
		#$result["function"],當前執行的函式名稱.
14441
		#$result["argu"],設置給予的參數.
14442
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
14443
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
14444
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
14445
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
14446
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
14447
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
14448
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
14449
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
14450
		#必填寫的參數:
14451
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 14452
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 14453
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
14454
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
14455
		#可以省略的參數:
14456
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
14457
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
14458
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
14459
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
14460
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
14461
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
14462
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
14463
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file","fileArgu");
14464
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
14465
		#$conf["canBeEmpty"]=array();
14466
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
14467
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web","line2start","linesPerTime");
14468
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
14469
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web","line2start","linesPerTime");
226 liveuser 14470
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 14471
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
14472
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
14473
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",null,"10");
14474
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
14475
		#$conf["disallowAllSkipableVarIsEmpty"]="";
14476
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
14477
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
14478
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
14479
		#$conf["arrayCountEqualCheck"][]=array();
14480
		#參考資料來源:
14481
		#array_keys=>http://php.net/manual/en/function.array-keys.php
14482
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
14483
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 14484
 
3 liveuser 14485
		#如果檢查參數失敗
14486
		if($checkArguments["status"]==="false"){
226 liveuser 14487
 
3 liveuser 14488
			#設置執行失敗
14489
			$result["status"]="false";
226 liveuser 14490
 
3 liveuser 14491
			#設置執行失敗訊息
14492
			$result["error"]=$checkArguments;
226 liveuser 14493
 
3 liveuser 14494
			#回傳結果
14495
			return $result;
226 liveuser 14496
 
3 liveuser 14497
			}#if end
226 liveuser 14498
 
3 liveuser 14499
		#如果檢查參數不通過
14500
		if($checkArguments["passed"]==="false"){
226 liveuser 14501
 
3 liveuser 14502
			#設置執行失敗
14503
			$result["status"]="false";
226 liveuser 14504
 
3 liveuser 14505
			#設置執行失敗訊息
14506
			$result["error"]=$checkArguments;
226 liveuser 14507
 
3 liveuser 14508
			#回傳結果
14509
			return $result;
226 liveuser 14510
 
3 liveuser 14511
			}#if end
14512
 
14513
		#檢查檔案是否存在
14514
		#函式說明:
14515
		#檢查多個檔案與資料夾是否存在.
14516
		#回傳的結果:
14517
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
14518
		#$result["error"],錯誤訊息陣列.
14519
		#$resutl["function"],當前執行的涵式名稱.
14520
		#$result["argu"],使用的參數.
14521
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
14522
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
14523
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
14524
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
14525
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
14526
		#必填參數:
14527
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
14528
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
14529
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14530
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
14531
		#可省略參數
14532
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
14533
		#$conf["disableWebSearch"]="false";
14534
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
14535
		#$conf["userDir"]="true";
14536
		#$conf["web"],字串,"true"代表位網頁系統,"false"為檔案系統,預設為"false".
14537
		$conf["fileAccess::checkMultiFileExist"]["web"]=$conf["web"];
14538
		#參考資料來源:
14539
		#http://php.net/manual/en/function.file-exists.php
14540
		#http://php.net/manual/en/control-structures.foreach.php
14541
		#備註:
14542
		#函數file_exists檢查的路徑為檔案系統的路徑
14543
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
14544
		unset($conf["fileAccess::checkMultiFileExist"]);
14545
 
14546
		#如果執行失敗
14547
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 14548
 
3 liveuser 14549
			#設置執行失敗
14550
			$result["status"]="false";
226 liveuser 14551
 
3 liveuser 14552
			#設置執行失敗訊息
14553
			$result["error"]=$checkMultiFileExist;
226 liveuser 14554
 
3 liveuser 14555
			#回傳結果
14556
			return $result;
226 liveuser 14557
 
3 liveuser 14558
			}#if end
226 liveuser 14559
 
3 liveuser 14560
		#如果檔案無法存取
14561
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 14562
 
3 liveuser 14563
			#設置執行失敗
14564
			$result["status"]="false";
226 liveuser 14565
 
3 liveuser 14566
			#設置執行失敗訊息
14567
			$result["error"]=$checkMultiFileExist;
226 liveuser 14568
 
3 liveuser 14569
			#回傳結果
14570
			return $result;
226 liveuser 14571
 
3 liveuser 14572
			}#if end
14573
 
14574
		#取得檔案的行數
14575
		#函式說明:
14576
		#呼叫shell執行系統命令,並取得回傳的內容.
14577
		#回傳的結果:
14578
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14579
		#$result["error"],錯誤訊息陣列.
14580
		#$result["function"],當前執行的函數名稱.
14581
		#$result["argu"],使用的參數.
14582
		#$result["cmd"],執行的指令內容.
14583
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
14584
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
14585
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
14586
		#$result["running"],是否還在執行.
14587
		#$result["pid"],pid.
14588
		#$result["statusCode"],執行結束後的代碼.
14589
		#必填的參數
14590
		#$conf["command"],字串,要執行的指令與.
14591
		$conf["external::callShell"]["command"]="cat";
14592
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 14593
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 14594
		#可省略參數:
14595
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
14596
		$conf["external::callShell"]["argu"]=array($conf["file"],"|","wc","-l");
14597
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
226 liveuser 14598
		#$conf["arguIsAddr"]=array();
3 liveuser 14599
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
14600
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
14601
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
14602
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
14603
		#$conf["enablePrintDescription"]="true";
14604
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
14605
		#$conf["printDescription"]="";
14606
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
14607
		$conf["external::callShell"]["escapeshellarg"]="true";
14608
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
14609
		#$conf["username"]="";
14610
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
14611
		#$conf["password"]="";
14612
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
14613
		#$conf["useScript"]="";
14614
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
14615
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
14616
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
14617
		#$conf["inBackGround"]="";
14618
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
14619
		#$conf["getErr"]="false";
14620
		#備註:
14621
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
14622
		#參考資料:
14623
		#exec=>http://php.net/manual/en/function.exec.php
14624
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
14625
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
14626
		$callShell=external::callShell($conf["external::callShell"]);
14627
		unset($conf["external::callShell"]);
14628
 
14629
		#如果檢查參數失敗
14630
		if($callShell["status"]==="false"){
226 liveuser 14631
 
3 liveuser 14632
			#設置執行失敗
14633
			$result["status"]="false";
226 liveuser 14634
 
3 liveuser 14635
			#設置執行失敗訊息
14636
			$result["error"]=$callShell;
226 liveuser 14637
 
3 liveuser 14638
			#回傳結果
14639
			return $result;
226 liveuser 14640
 
3 liveuser 14641
			}#if end
226 liveuser 14642
 
3 liveuser 14643
		#取得檔案總行數
14644
		$result["totalLineCount"]=$callShell["output"][0];
226 liveuser 14645
 
3 liveuser 14646
		#如果未設置 $conf["line2start"]
14647
		if(!isset($conf["line2start"])){
226 liveuser 14648
 
3 liveuser 14649
			#$conf["line2start"]為總行數減去一次要看的行數減1
14650
			$conf["line2start"]=$result["totalLineCount"]-$conf["linesPerTime"]+1;
226 liveuser 14651
 
14652
			}#if end
14653
 
14654
		#如果開始行數小於1
3 liveuser 14655
		if($conf["line2start"]<1){
226 liveuser 14656
 
3 liveuser 14657
			#$conf["line2start"]為總行數減去一次要看的行數減1
14658
			$conf["line2start"]=$result["totalLineCount"]-$conf["linesPerTime"]+1;
226 liveuser 14659
 
3 liveuser 14660
			}#if end
226 liveuser 14661
 
14662
		#如果開始行數小於1
3 liveuser 14663
		if($conf["line2start"]<1){
226 liveuser 14664
 
3 liveuser 14665
			#$conf["line2start"]為1
14666
			$conf["line2start"]=1;
226 liveuser 14667
 
3 liveuser 14668
			}#if end
226 liveuser 14669
 
3 liveuser 14670
		#取得指定範圍的行數
14671
		#取得檔案的行數
14672
		#函式說明:
14673
		#呼叫shell執行系統命令,並取得回傳的內容.
14674
		#回傳的結果:
14675
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14676
		#$result["error"],錯誤訊息陣列.
14677
		#$result["function"],當前執行的函數名稱.
14678
		#$result["argu"],使用的參數.
14679
		#$result["cmd"],執行的指令內容.
14680
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
14681
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
14682
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
14683
		#$result["running"],是否還在執行.
14684
		#$result["pid"],pid.
14685
		#$result["statusCode"],執行結束後的代碼.
14686
		#必填的參數
14687
		#$conf["command"],字串,要執行的指令與.
14688
		$conf["external::callShell"]["command"]="sed";
14689
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 14690
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 14691
		#可省略參數:
14692
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
14693
		$conf["external::callShell"]["argu"]=array("-n",$conf["line2start"].",".($conf["line2start"]+$conf["linesPerTime"]-1)."p",$conf["file"]);
14694
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
226 liveuser 14695
		#$conf["arguIsAddr"]=array();
3 liveuser 14696
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
14697
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
14698
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
14699
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
14700
		#$conf["enablePrintDescription"]="true";
14701
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
14702
		#$conf["printDescription"]="";
14703
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
14704
		$conf["external::callShell"]["escapeshellarg"]="true";
14705
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
14706
		#$conf["username"]="";
14707
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
14708
		#$conf["password"]="";
14709
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
14710
		#$conf["useScript"]="";
14711
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
14712
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
14713
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
14714
		#$conf["inBackGround"]="";
14715
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
14716
		#$conf["getErr"]="false";
14717
		#備註:
14718
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
14719
		#參考資料:
14720
		#exec=>http://php.net/manual/en/function.exec.php
14721
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
14722
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
14723
		$callShell=external::callShell($conf["external::callShell"]);
14724
		unset($conf["external::callShell"]);
14725
 
14726
		#如果檢查參數失敗
14727
		if($callShell["status"]==="false"){
226 liveuser 14728
 
3 liveuser 14729
			#設置執行失敗
14730
			$result["status"]="false";
226 liveuser 14731
 
3 liveuser 14732
			#設置執行失敗訊息
14733
			$result["error"]=$callShell;
226 liveuser 14734
 
3 liveuser 14735
			#回傳結果
14736
			return $result;
226 liveuser 14737
 
3 liveuser 14738
			}#if end
14739
 
14740
		#取得輸出的行數
14741
		$result["lines"]=count($callShell["output"]);
14742
 
14743
		#取得目前的輸出內容
14744
		$result["content"]=$callShell["output"];
14745
 
14746
		#取得當前行數
14747
		$result["lineNum"]=$conf["line2start"]+$result["lines"]-1;
14748
 
226 liveuser 14749
		#如果當前行號小於總行數
3 liveuser 14750
		if($result["lineNum"]<$result["totalLineCount"]){
14751
 
14752
			#設置還有剩餘的內容
14753
			$result["left"]="true";
226 liveuser 14754
 
3 liveuser 14755
			}#if end
14756
 
226 liveuser 14757
		#反之
3 liveuser 14758
		else{
14759
 
14760
			#設置無剩餘的內容
14761
			$result["left"]="false";
14762
 
14763
			}#else end
14764
 
14765
		#設置執行正常
14766
		$result["status"]="true";
14767
 
14768
		#回傳結果
14769
		return $result;
14770
 
14771
		}#function tail end
226 liveuser 14772
 
3 liveuser 14773
	/*
14774
	#函式說明:
14775
	#解析PHP檔案裡面的變數.
14776
	#回傳結果:
14777
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14778
	#$result["error"],錯誤訊息.
14779
	#$result["function"],當前執行的函數名稱.
226 liveuser 14780
	#$result["argu"],所使用的參數.
3 liveuser 14781
	#$result["content"],找到的變數內容陣列,若有多個變數則會用array來表示.
14782
	#必填參數:
14783
	#$conf["file"],字串,檔案的路徑與名稱.
14784
	$conf["file"]="";
14785
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14786
	$conf["fileArgu"]=__FILE__;
14787
	#$conf["varName"],字串陣列,要搜尋的變數名稱,例如要搜尋變數$email則輸入"email".
14788
	$conf["varName"]=array();
14789
	#可省略參數:
14790
	#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false",預設為"false".
14791
	#$conf["web"]="true";
14792
	#參考資料:
14793
	#https://www.php.net/manual/en/function.parse-str.php
14794
	#備註:
14795
	#無.
14796
	*/
14797
	public static function parseVaraiableInPHPfile(&$conf){
226 liveuser 14798
 
3 liveuser 14799
		#初始化要回傳的結果
14800
		$result=array();
14801
 
14802
		#取得當前執行的函數名稱
14803
		$result["function"]=__FUNCTION__;
14804
 
14805
		#如果沒有參數
14806
		if(func_num_args()==0){
226 liveuser 14807
 
3 liveuser 14808
			#設置執行失敗
14809
			$result["status"]="false";
226 liveuser 14810
 
3 liveuser 14811
			#設置執行錯誤訊息
14812
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 14813
 
3 liveuser 14814
			#回傳結果
14815
			return $result;
14816
 
226 liveuser 14817
			}#if end
14818
 
3 liveuser 14819
		#取得參數
14820
		$result["argu"]=$conf;
14821
 
14822
		#如果 $conf 不為陣列
14823
		if(gettype($conf)!=="array"){
226 liveuser 14824
 
3 liveuser 14825
			#設置執行失敗
14826
			$result["status"]="false";
226 liveuser 14827
 
3 liveuser 14828
			#設置執行錯誤訊息
14829
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 14830
 
3 liveuser 14831
			#如果傳入的參數為 null
14832
			if($conf===null){
226 liveuser 14833
 
3 liveuser 14834
				#設置執行錯誤訊息
14835
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 14836
 
3 liveuser 14837
				}#if end
14838
 
14839
			#回傳結果
14840
			return $result;
226 liveuser 14841
 
3 liveuser 14842
			}#if end
226 liveuser 14843
 
3 liveuser 14844
		#函式說明:
14845
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
14846
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14847
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14848
		#$result["function"],當前執行的函式名稱.
14849
		#$result["argu"],設置給予的參數.
14850
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
14851
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
14852
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
14853
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
14854
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
14855
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
14856
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
14857
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
14858
		#必填寫的參數:
14859
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 14860
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 14861
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
14862
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
14863
		#可以省略的參數:
14864
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
14865
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu","varName");
14866
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
14867
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array");
14868
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
14869
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
14870
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
14871
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file","fileArgu","varName");
14872
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
14873
		#$conf["canBeEmpty"]=array();
14874
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
14875
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web");
14876
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
14877
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
226 liveuser 14878
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 14879
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
14880
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
14881
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
14882
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
14883
		#$conf["disallowAllSkipableVarIsEmpty"]="";
14884
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
14885
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
14886
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
14887
		#$conf["arrayCountEqualCheck"][]=array();
14888
		#參考資料來源:
14889
		#array_keys=>http://php.net/manual/en/function.array-keys.php
14890
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
14891
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 14892
 
3 liveuser 14893
		#如果檢查參數失敗
14894
		if($checkArguments["status"]==="false"){
226 liveuser 14895
 
3 liveuser 14896
			#設置執行失敗
14897
			$result["status"]="false";
226 liveuser 14898
 
3 liveuser 14899
			#設置執行失敗訊息
14900
			$result["error"]=$checkArguments;
226 liveuser 14901
 
3 liveuser 14902
			#回傳結果
14903
			return $result;
226 liveuser 14904
 
3 liveuser 14905
			}#if end
226 liveuser 14906
 
3 liveuser 14907
		#如果檢查參數不通過
14908
		if($checkArguments["passed"]==="false"){
226 liveuser 14909
 
3 liveuser 14910
			#設置執行失敗
14911
			$result["status"]="false";
226 liveuser 14912
 
3 liveuser 14913
			#設置執行失敗訊息
14914
			$result["error"]=$checkArguments;
226 liveuser 14915
 
3 liveuser 14916
			#回傳結果
14917
			return $result;
226 liveuser 14918
 
3 liveuser 14919
			}#if end
226 liveuser 14920
 
3 liveuser 14921
		#初始化儲存解析出來的變數內容
14922
		$result["content"]=array();
226 liveuser 14923
 
3 liveuser 14924
		#讀取檔案
14925
		#函式說明:
14926
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
14927
		#回傳的變數說明:
14928
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
14929
		#$result["error"],錯誤訊息提示.
14930
		#$result["warning"],警告訊息.
14931
		#$result["function"],當前執行的函數名稱.
14932
		#$result["fileContent"],爲檔案的內容陣列.
14933
		#$result["lineCount"],爲檔案內容總共的行數.
14934
		#$result["fullContent"],為檔案的完整內容.
14935
		#$result["base64data"],為檔案的base64內容.
14936
		#$result["mimeType"],為檔案的mime type.
14937
		#必填參數:
14938
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
14939
		$conf["ileAccess::getFileContent"]["filePositionAndName"]=$conf["file"];
14940
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14941
		$conf["ileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
14942
		#可省略參數:
14943
		#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
14944
		$conf["ileAccess::getFileContent"]["web"]=$conf["web"];
14945
		#參考資料:
14946
		#file(),取得檔案內容的行數.
14947
		#file=>http:#php.net/manual/en/function.file.php
14948
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
14949
		#filesize=>http://php.net/manual/en/function.filesize.php
14950
		$getFileContent=fileAccess::getFileContent($conf["ileAccess::getFileContent"]);
14951
		unset($conf["ileAccess::getFileContent"]);
14952
 
14953
		#如果讀取檔案失敗
14954
		if($getFileContent["status"]==="false"){
226 liveuser 14955
 
3 liveuser 14956
			#設置執行失敗
14957
			$result["status"]="false";
226 liveuser 14958
 
3 liveuser 14959
			#設置執行失敗訊息
14960
			$result["error"]=$getFileContent;
226 liveuser 14961
 
3 liveuser 14962
			#回傳結果
14963
			return $result;
226 liveuser 14964
 
3 liveuser 14965
			}#if end
226 liveuser 14966
 
3 liveuser 14967
		#針對每列檔案內容
14968
		foreach($getFileContent["fileContent"] as $line){
226 liveuser 14969
 
3 liveuser 14970
			#針對每個要搜尋的變數
14971
			foreach($conf["varName"] as $keyWord){
226 liveuser 14972
 
3 liveuser 14973
				#如果關鍵字小於被搜尋的字串長度
14974
				if( strlen($line) < strlen($keyWord)+1 ){
226 liveuser 14975
 
3 liveuser 14976
					#跳過
14977
					continue;
226 liveuser 14978
 
3 liveuser 14979
					}#if end
226 liveuser 14980
 
3 liveuser 14981
				#函式說明:
14982
				#取得符合特定字首與字尾的字串
14983
				#回傳結果:
14984
				#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
14985
				#$result["function"],當前執行的函數名稱.
14986
				#$result["error"],錯誤訊息陣列.
14987
				#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
14988
				#$result["returnString"],爲符合字首條件的字串內容。
14989
				#$result["argu"],使用的參數.
14990
				#必填參數:
14991
				#$conf["checkString"],字串,要檢查的字串.
14992
				$conf["search::getMeetConditionsString"]["checkString"]=$line;
14993
				#可省略參數:
14994
				#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
14995
				$conf["search::getMeetConditionsString"]["frontWord"]="$".$keyWord;
14996
				#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
14997
				$conf["search::getMeetConditionsString"]["tailWord"]=";";
14998
				#參考資料:
14999
				#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
15000
				$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
15001
				unset($conf["search::getMeetConditionsString"]);
226 liveuser 15002
 
3 liveuser 15003
				#如果失敗
15004
				if($getMeetConditionsString["status"]==="false"){
15005
 
15006
					#設置執行失敗
15007
					$result["status"]="false";
226 liveuser 15008
 
3 liveuser 15009
					#設置執行失敗訊息
15010
					$result["error"]=$getMeetConditionsString;
226 liveuser 15011
 
3 liveuser 15012
					#回傳結果
15013
					return $result;
226 liveuser 15014
 
15015
					}#if end
15016
 
3 liveuser 15017
				#如果有找到關鍵字
15018
				if($getMeetConditionsString["founded"]==="true"){
226 liveuser 15019
 
3 liveuser 15020
					#剔除變數名稱
15021
					#函式說明:
15022
					#將字串特定關鍵字與其前面的內容剔除
15023
					#回傳結果:
15024
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15025
					#$result["error"],錯誤訊息陣列.
15026
					#$result["warning"],警告訊息鎮列.
15027
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
15028
					#$result["function"],當前執行的函數名稱.
15029
					#$result["oriStr"],要處理的原始字串內容.
226 liveuser 15030
					#$result["content"],處理好的的字串內容.
3 liveuser 15031
					#必填參數:
15032
					#$conf["stringIn"],字串,要處理的字串.
15033
					$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$line;
15034
					#$conf["keyWord"],字串,特定字串.
15035
					$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="$".$keyWord;
15036
					#可省略參數:
15037
					#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,直到沒有關鍵字為止.
15038
					#$conf["recursive"]="true";
15039
					#參考資料:
15040
					#無.
15041
					#備註:
15042
					#無.
15043
					$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
15044
					unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 15045
 
3 liveuser 15046
					#如果執行失敗
15047
					if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 15048
 
3 liveuser 15049
						#設置執行失敗
15050
						$result["status"]="false";
226 liveuser 15051
 
3 liveuser 15052
						#設置執行失敗訊息
15053
						$result["error"]=$delStrBeforeKeyWord;
226 liveuser 15054
 
3 liveuser 15055
						#回傳結果
15056
						return $result;
226 liveuser 15057
 
3 liveuser 15058
						}#if end
226 liveuser 15059
 
3 liveuser 15060
					#如果沒有找到應該存在的php變數
15061
					if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 15062
 
3 liveuser 15063
						#設置執行失敗
15064
						$result["status"]="false";
226 liveuser 15065
 
3 liveuser 15066
						#設置執行失敗訊息
15067
						$result["error"]=$delStrBeforeKeyWord;
226 liveuser 15068
 
3 liveuser 15069
						#回傳結果
15070
						return $result;
226 liveuser 15071
 
3 liveuser 15072
						}#if end
226 liveuser 15073
 
3 liveuser 15074
					#剔除 "=" 前面的內容
15075
					#函式說明:
15076
					#將字串特定關鍵字與其前面的內容剔除
15077
					#回傳結果:
15078
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15079
					#$result["error"],錯誤訊息陣列.
15080
					#$result["warning"],警告訊息鎮列.
15081
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
15082
					#$result["function"],當前執行的函數名稱.
15083
					#$result["oriStr"],要處理的原始字串內容.
226 liveuser 15084
					#$result["content"],處理好的的字串內容.
3 liveuser 15085
					#必填參數:
15086
					#$conf["stringIn"],字串,要處理的字串.
15087
					$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$delStrBeforeKeyWord["content"];
15088
					#$conf["keyWord"],字串,特定字串.
15089
					$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="=";
15090
					#可省略參數:
15091
					#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,直到沒有關鍵字為止.
15092
					#$conf["recursive"]="true";
15093
					#參考資料:
15094
					#無.
15095
					#備註:
15096
					#無.
15097
					$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
15098
					unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 15099
 
3 liveuser 15100
					#如果執行失敗
15101
					if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 15102
 
3 liveuser 15103
						#設置執行失敗
15104
						$result["status"]="false";
226 liveuser 15105
 
3 liveuser 15106
						#設置執行失敗訊息
15107
						$result["error"]=$delStrBeforeKeyWord;
226 liveuser 15108
 
3 liveuser 15109
						#回傳結果
15110
						return $result;
226 liveuser 15111
 
3 liveuser 15112
						}#if end
226 liveuser 15113
 
3 liveuser 15114
					#如果沒有找“=”關鍵字
15115
					if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 15116
 
3 liveuser 15117
						#跳過
15118
						continue;
226 liveuser 15119
 
3 liveuser 15120
						}#if end
226 liveuser 15121
 
3 liveuser 15122
					#剔除 value 前面的空白
15123
					#函式說明:
15124
					#將字串特定關鍵字與其前面的內容剔除
15125
					#回傳結果:
15126
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15127
					#$result["error"],錯誤訊息陣列.
15128
					#$result["warning"],警告訊息鎮列.
15129
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
15130
					#$result["function"],當前執行的函數名稱.
15131
					#$result["oriStr"],要處理的原始字串內容.
226 liveuser 15132
					#$result["content"],處理好的的字串內容.
3 liveuser 15133
					#必填參數:
15134
					#$conf["stringIn"],字串,要處理的字串.
15135
					$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$delStrBeforeKeyWord["content"];
15136
					#$conf["keyWord"],字串,特定字串.
15137
					$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=" ";
15138
					#可省略參數:
15139
					#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,直到沒有關鍵字為止.
15140
					$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
15141
					#參考資料:
15142
					#無.
15143
					#備註:
15144
					#無.
15145
					$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
15146
					unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 15147
 
3 liveuser 15148
					#如果執行失敗
15149
					if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 15150
 
3 liveuser 15151
						#設置執行失敗
15152
						$result["status"]="false";
226 liveuser 15153
 
3 liveuser 15154
						#設置執行失敗訊息
15155
						$result["error"]=$delStrBeforeKeyWord;
226 liveuser 15156
 
3 liveuser 15157
						#回傳結果
15158
						return $result;
226 liveuser 15159
 
3 liveuser 15160
						}#if end
226 liveuser 15161
 
3 liveuser 15162
					#取得找到的變數
15163
					eval("\$result[\"content\"][\"".$keyWord."\"][]=".$delStrBeforeKeyWord["content"]);
226 liveuser 15164
 
3 liveuser 15165
					}#if end
226 liveuser 15166
 
3 liveuser 15167
				}#foreach end
226 liveuser 15168
 
3 liveuser 15169
			}#foreach end
226 liveuser 15170
 
3 liveuser 15171
		#設置執行正常
15172
		$result["status"]="true";
226 liveuser 15173
 
3 liveuser 15174
		#回傳結果
15175
		return $result;
226 liveuser 15176
 
3 liveuser 15177
		}#function parseVaraiableInPHPfile end
15178
 
15179
	/*
15180
	#函式說明:
15181
	#開啟特定目錄,取得底下的檔案路徑清單.
15182
	#回傳結果:
15183
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15184
	#$result["error"],錯誤訊息.
15185
	#$result["function"],當前執行的函數名稱.
15186
	#$result["argu"],所使用的參數.
15187
	#$result["content"],讀取到的內容陣列.
15188
	#$result["content"][$i],第$i+1個結果.
15189
	#$result["content"][$i]["name"],第$i+1個名稱.
15190
	#$result["content"][$i]["dir"],第$i+1個檔案是否為資料夾.
15191
	#$result["content"][$i]["info"],第$i+1個檔案的額外資訊.
15192
	#$result["content"][$i]["size"],第$i+1個檔案的大小(bytes).
15193
	#必填參數:
15194
	#$conf["path"],字串,要取得檔案資訊的所屬路徑.
15195
	$conf["path"]="";
15196
	#可省略參數:
15197
	#無.
15198
	#參考資料
15199
	#無.
15200
	#備註:
15201
	#無.
15202
	*/
15203
	public static function listInfo(&$conf){
226 liveuser 15204
 
3 liveuser 15205
		#初始化要回傳的結果
15206
		$result=array();
15207
 
15208
		#取得當前執行的函數名稱
15209
		$result["function"]=__FUNCTION__;
15210
 
15211
		#如果沒有參數
15212
		if(func_num_args()==0){
226 liveuser 15213
 
3 liveuser 15214
			#設置執行失敗
15215
			$result["status"]="false";
226 liveuser 15216
 
3 liveuser 15217
			#設置執行錯誤訊息
15218
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 15219
 
3 liveuser 15220
			#回傳結果
15221
			return $result;
15222
 
226 liveuser 15223
			}#if end
15224
 
3 liveuser 15225
		#取得參數
15226
		$result["argu"]=$conf;
15227
 
15228
		#如果 $conf 不為陣列
15229
		if(gettype($conf)!=="array"){
226 liveuser 15230
 
3 liveuser 15231
			#設置執行失敗
15232
			$result["status"]="false";
226 liveuser 15233
 
3 liveuser 15234
			#設置執行錯誤訊息
15235
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 15236
 
3 liveuser 15237
			#如果傳入的參數為 null
15238
			if($conf===null){
226 liveuser 15239
 
3 liveuser 15240
				#設置執行錯誤訊息
15241
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 15242
 
3 liveuser 15243
				}#if end
15244
 
15245
			#回傳結果
15246
			return $result;
226 liveuser 15247
 
3 liveuser 15248
			}#if end
226 liveuser 15249
 
3 liveuser 15250
		#函式說明:
15251
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
15252
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15253
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
15254
		#$result["function"],當前執行的函式名稱.
15255
		#$result["argu"],設置給予的參數.
15256
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
15257
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
15258
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
15259
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
15260
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
15261
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
15262
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
15263
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
15264
		#必填寫的參數:
15265
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 15266
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 15267
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
15268
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
15269
		#可以省略的參數:
15270
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
15271
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path");
15272
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
15273
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
15274
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
15275
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
15276
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
15277
		$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
15278
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
15279
		#$conf["canBeEmpty"]=array();
15280
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
15281
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web");
15282
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
15283
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
226 liveuser 15284
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 15285
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
15286
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
15287
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
15288
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
15289
		#$conf["disallowAllSkipableVarIsEmpty"]="";
15290
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
15291
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
15292
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
15293
		#$conf["arrayCountEqualCheck"][]=array();
15294
		#參考資料來源:
15295
		#array_keys=>http://php.net/manual/en/function.array-keys.php
15296
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
15297
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 15298
 
3 liveuser 15299
		#如果檢查參數失敗
15300
		if($checkArguments["status"]==="false"){
226 liveuser 15301
 
3 liveuser 15302
			#設置執行失敗
15303
			$result["status"]="false";
226 liveuser 15304
 
3 liveuser 15305
			#設置執行失敗訊息
15306
			$result["error"]=$checkArguments;
226 liveuser 15307
 
3 liveuser 15308
			#回傳結果
15309
			return $result;
226 liveuser 15310
 
3 liveuser 15311
			}#if end
226 liveuser 15312
 
3 liveuser 15313
		#如果檢查參數不通過
15314
		if($checkArguments["passed"]==="false"){
226 liveuser 15315
 
3 liveuser 15316
			#設置執行失敗
15317
			$result["status"]="false";
226 liveuser 15318
 
3 liveuser 15319
			#設置執行失敗訊息
15320
			$result["error"]=$checkArguments;
226 liveuser 15321
 
3 liveuser 15322
			#回傳結果
15323
			return $result;
226 liveuser 15324
 
3 liveuser 15325
			}#if end
226 liveuser 15326
 
3 liveuser 15327
		#初始化儲存解析出來的變數內容
15328
		$result["content"]=array();
226 liveuser 15329
 
3 liveuser 15330
		#取得特定位置的資訊
15331
		$pathInfo=@dir($conf["path"]);
226 liveuser 15332
 
3 liveuser 15333
		#如果取得路徑資訊失敗
15334
		if($pathInfo===false){
226 liveuser 15335
 
3 liveuser 15336
			#設置執行失敗
15337
			$result["status"]="false";
226 liveuser 15338
 
3 liveuser 15339
			#設置執行失敗訊息
15340
			$result["error"][]="無法存取路徑(".$conf["path"].")";
226 liveuser 15341
 
3 liveuser 15342
			#回傳結果
15343
			return $result;
226 liveuser 15344
 
3 liveuser 15345
			}#if end
226 liveuser 15346
 
3 liveuser 15347
		#讀取底下一個檔案,暫存到 $tmpItem 裡面,且當結果不為 false 時進入迴圈.
15348
		while(false !== $tmpItem = $pathInfo->read()){
226 liveuser 15349
 
3 liveuser 15350
			#宣告儲存資訊的變數
15351
			$item=array();
226 liveuser 15352
 
3 liveuser 15353
			#儲存名稱
15354
			$item["name"]=$tmpItem;
226 liveuser 15355
 
3 liveuser 15356
			#預設不為資料夾
15357
			$item["dir"]="false";
226 liveuser 15358
 
3 liveuser 15359
			#若為資料夾
15360
			if(is_dir($conf["path"]."/".$tmpItem)){
226 liveuser 15361
 
3 liveuser 15362
				#設置為"true"
15363
				$item["dir"]="true";
226 liveuser 15364
 
3 liveuser 15365
				}#if end
226 liveuser 15366
 
3 liveuser 15367
			#取得檔案識別器
15368
			$finfo = finfo_open(FILEINFO_MIME);
226 liveuser 15369
 
3 liveuser 15370
			#取得 info
15371
			$item["info"]=@finfo_file($finfo,$conf["path"]."/".$tmpItem);
15372
 
15373
			#取得檔案大小
15374
			$item["size"]=filesize($conf["path"]."/".$tmpItem);
15375
 
15376
			#close connection
15377
			finfo_close($finfo);
226 liveuser 15378
 
3 liveuser 15379
			#記錄該檔案資訊
15380
			$result["content"][]=$item;
226 liveuser 15381
 
3 liveuser 15382
			}#while end
226 liveuser 15383
 
3 liveuser 15384
		#設置執行正常
15385
		$result["status"]="true";
226 liveuser 15386
 
3 liveuser 15387
		#回傳結果
15388
		return $result;
226 liveuser 15389
 
3 liveuser 15390
		}#function listInfo end
15391
 
15392
	/*
15393
	#函式說明:
15394
	#取得目錄底下的詳細資訊.
15395
	#回傳結果:
15396
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15397
	#$result["error"],錯誤訊息.
15398
	#$result["function"],當前執行的函數名稱.
15399
	#$result["size"],該清單的大小,單位為bytes.
15400
	#$result["dataCount"],該清單的長度.
15401
	#$result["path"],字串,檢視的路徑,必為"/"結尾.
15402
	#$result["content"],指定目錄底下的所有檔案資訊.
15403
	#$result["content"][$i]["nType&permission"],第$i個節點類型、權限.
15404
	#$result["content"][$i]["nType"],第$i個節點類型,"-"代表檔案,"d"代表資料夾.
15405
	#$result["content"][$i]["permission"],第$i個節點權限.
15406
	#$result["content"][$i]["ownByUser"],第$i個節點擁有者賬號.
15407
	#$result["content"][$i]["ownByGroup"],第$i個節點擁有者群組.
15408
	#$result["content"][$i]["bytes"],第$i個節點大小.
15409
	#$result["content"][$i]["date"],第$i個節點最後變更日期.
15410
	#$result["content"][$i]["time"],第$i個節點最後異動時間.
15411
	#$result["content"][$i]["timeDetail"],第$i個節點最後異動詳細時間.
15412
	#$result["content"][$i]["timezone"],第$i個節點的時區.
15413
	#$result["content"][$i]["name"],第$i個節點的名稱.
15414
	#$result["content"][$i]["secondName"],第$i個節點為檔案時,若有附檔名,會記錄在這.
15415
	#$result["content"][$i]["mimeType"],第$i個節點為檔案且可以讀取時,會有 mime type 可取得.
15416
	#必填參數:
15417
	#$conf["path"],字串,要檢視的路徑,若非"/"結尾,會自動補上.
15418
	$conf["path"]="";
15419
	#可省略參數:
15420
	#無.
15421
	#參考資料:
15422
	#https://www.businessweekly.com.tw/careers/Blog/14307
15423
	#備註:
15424
	#無.
15425
	*/
15426
	public static function ls(&$conf){
226 liveuser 15427
 
3 liveuser 15428
		#初始化要回傳的結果
15429
		$result=array();
15430
 
15431
		#取得當前執行的函數名稱
15432
		$result["function"]=__FUNCTION__;
15433
 
15434
		#如果沒有參數
15435
		if(func_num_args()==0){
15436
 
15437
			#設置執行失敗
15438
			$result["status"]="false";
15439
 
15440
			#設置執行錯誤訊息
15441
			$result["error"]="函數".$result["function"]."需要參數";
15442
 
15443
			#回傳結果
15444
			return $result;
15445
 
15446
			}#if end
15447
 
15448
		#取得參數
15449
		$result["argu"]=$conf;
15450
 
15451
		#如果 $conf 不為陣列
15452
		if(gettype($conf)!=="array"){
15453
 
15454
			#設置執行失敗
15455
			$result["status"]="false";
15456
 
15457
			#設置執行錯誤訊息
15458
			$result["error"][]="\$conf變數須為陣列形態";
15459
 
15460
			#如果傳入的參數為 null
15461
			if(is_null($conf)){
15462
 
15463
				#設置執行錯誤訊息
15464
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
15465
 
15466
				}#if end
15467
 
15468
			#回傳結果
15469
			return $result;
15470
 
15471
			}#if end
226 liveuser 15472
 
3 liveuser 15473
		#函式說明:
15474
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
15475
		#回傳結果:
15476
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15477
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
15478
		#$result["simpleError"],簡單表示的錯誤訊息.
15479
		#$result["function"],當前執行的函式名稱.
15480
		#$result["argu"],設置給予的參數.
15481
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
15482
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
15483
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
15484
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
15485
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
15486
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
15487
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
15488
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
15489
		#必填參數:
15490
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
15491
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
15492
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
15493
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
15494
		#可省略參數:
15495
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
15496
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path");
15497
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
15498
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
15499
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
15500
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
15501
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
15502
		#$conf["canNotBeEmpty"]=array();
15503
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
15504
		#$conf["canBeEmpty"]=array();
15505
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
15506
		#$conf["skipableVariableCanNotBeEmpty"]=array();
15507
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
15508
		#$conf["skipableVariableName"]=array();
15509
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
15510
		#$conf["skipableVariableType"]=array();
15511
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
15512
		#$conf["skipableVarDefaultValue"]=array("");
15513
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
15514
		#$conf["disallowAllSkipableVarIsEmpty"]="";
15515
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
15516
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
15517
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
15518
		#$conf["arrayCountEqualCheck"][]=array();
15519
		#參考資料:
15520
		#array_keys=>http://php.net/manual/en/function.array-keys.php
15521
		#備註:
15522
		#無.
15523
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
15524
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 15525
 
3 liveuser 15526
		#如果執行失敗
15527
		if($checkArguments["status"]==="false"){
226 liveuser 15528
 
3 liveuser 15529
			#設置執行錯誤
15530
			$result["status"]="false";
226 liveuser 15531
 
3 liveuser 15532
			#設置錯誤訊息
15533
			$result["error"]=$checkArguments;
226 liveuser 15534
 
3 liveuser 15535
			#回傳結果
15536
			return $result;
226 liveuser 15537
 
3 liveuser 15538
			}#if end
226 liveuser 15539
 
3 liveuser 15540
		#如果參數檢查不通過
15541
		if($checkArguments["passed"]==="false"){
226 liveuser 15542
 
3 liveuser 15543
			#設置執行錯誤
15544
			$result["status"]="false";
226 liveuser 15545
 
3 liveuser 15546
			#設置錯誤訊息
15547
			$result["error"]=$checkArguments;
226 liveuser 15548
 
3 liveuser 15549
			#回傳結果
15550
			return $result;
226 liveuser 15551
 
3 liveuser 15552
			}#if end
226 liveuser 15553
 
3 liveuser 15554
		#確認 $conf["path"] 是否為 "/" 結尾
15555
		#函式說明:
15556
		#取得符合特定字首與字尾的字串
15557
		#回傳結果:
15558
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
15559
		#$result["function"],當前執行的函數名稱.
15560
		#$result["error"],錯誤訊息陣列.
15561
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
15562
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
15563
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
15564
		#$result["argu"],使用的參數.
15565
		#必填參數:
15566
		#$conf["checkString"],字串,要檢查的字串.
15567
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["path"];
15568
		#可省略參數:
15569
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
15570
		#$conf["frontWord"]="";
15571
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
15572
		$conf["search::getMeetConditionsString"]["tailWord"]="/";
15573
		#參考資料:
15574
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
15575
		#備註:
15576
		#無.
15577
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
15578
		unset($conf["search::getMeetConditionsString"]);
226 liveuser 15579
 
3 liveuser 15580
		#如果執行失敗
15581
		if($getMeetConditionsString["status"]==="false"){
226 liveuser 15582
 
3 liveuser 15583
			#設置執行錯誤
15584
			$result["status"]="false";
226 liveuser 15585
 
3 liveuser 15586
			#設置錯誤訊息
15587
			$result["error"]=$getMeetConditionsString;
226 liveuser 15588
 
3 liveuser 15589
			#回傳結果
15590
			return $result;
226 liveuser 15591
 
3 liveuser 15592
			}#if end
226 liveuser 15593
 
3 liveuser 15594
		#如果沒有 "/" 結尾
15595
		if($getMeetConditionsString["founded"]==="false"){
226 liveuser 15596
 
3 liveuser 15597
			#於結尾加上 "/"
15598
			$conf["path"]=$conf["path"]."/";
226 liveuser 15599
 
3 liveuser 15600
			}#if end
226 liveuser 15601
 
3 liveuser 15602
		#記錄真正的路徑
15603
		$result["path"]=$conf["path"];
226 liveuser 15604
 
3 liveuser 15605
		#函式說明:
15606
		#呼叫shell執行系統命令,並取得回傳的內容.
15607
		#回傳結果:
15608
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15609
		#$result["error"],錯誤訊息陣列.
15610
		#$result["function"],當前執行的函數名稱.
15611
		#$result["argu"],使用的參數.
15612
		#$result["cmd"],執行的指令內容.
15613
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
15614
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
15615
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
15616
		#$result["running"],是否還在執行.
15617
		#$result["pid"],pid.
15618
		#$result["statusCode"],執行結束後的代碼.
15619
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
15620
		#必填參數:
15621
		#$conf["command"],字串,要執行的指令.
15622
		$conf["external::callShell"]["command"]="ls";
15623
		#$conf["fileArgu"],字串,變數__FILE__的內容.
15624
		$conf["external::callShell"]["fileArgu"]=__FILE__;
15625
		#可省略參數:
15626
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
15627
		$conf["external::callShell"]["argu"]=array("-al","--full-time","-t","-B",$conf["path"]);
15628
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
15629
		#$conf["arguIsAddr"]=array();
15630
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
15631
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
15632
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
15633
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
15634
		#$conf["enablePrintDescription"]="true";
15635
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
15636
		#$conf["printDescription"]="";
15637
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
15638
		$conf["external::callShell"]["escapeshellarg"]="true";
15639
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
15640
		#$conf["thereIsShellVar"]=array();
15641
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
15642
		#$conf["username"]="";
15643
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
15644
		#$conf["password"]="";
15645
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
15646
		#$conf["useScript"]="";
15647
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
15648
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
15649
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
15650
		#$conf["inBackGround"]="";
15651
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
15652
		#$conf["getErr"]="false";
15653
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
15654
		#$conf["doNotRun"]="false";
15655
		#參考資料:
15656
		#exec=>http://php.net/manual/en/function.exec.php
15657
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
15658
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
15659
		#備註:
15660
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
15661
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
15662
		$callShell=external::callShell($conf["external::callShell"]);
15663
		unset($conf["external::callShell"]);
226 liveuser 15664
 
3 liveuser 15665
		#debug
15666
		#var_dump(__FILE__,__LINE__,$callShell);
226 liveuser 15667
 
3 liveuser 15668
		#如果執行失敗
15669
		if($callShell["status"]==="false"){
226 liveuser 15670
 
3 liveuser 15671
			#設置執行錯誤
15672
			$result["status"]="false";
226 liveuser 15673
 
3 liveuser 15674
			#設置錯誤訊息
15675
			$result["error"]=$callShell;
226 liveuser 15676
 
3 liveuser 15677
			#回傳結果
15678
			return $result;
226 liveuser 15679
 
3 liveuser 15680
			}#if end
226 liveuser 15681
 
3 liveuser 15682
		#初始化儲存檔案資訊為空
15683
		$result["content"]=array();
226 liveuser 15684
 
3 liveuser 15685
		#針對每行輸出
15686
		foreach($callShell["output"] as $index=>$line){
226 liveuser 15687
 
3 liveuser 15688
			#如果是第一筆
15689
			if($index===0){
226 liveuser 15690
 
3 liveuser 15691
				#取得資料筆數
15692
				$result["dataCount"]=explode(" ",$line)[0];
226 liveuser 15693
 
3 liveuser 15694
				#換下一輪
15695
				continue;
226 liveuser 15696
 
3 liveuser 15697
				}#if end
226 liveuser 15698
 
3 liveuser 15699
			#函式說明:
15700
			#將固定格式的字串分開,並回傳分開的結果.
15701
			#回傳結果:
15702
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15703
			#$result["error"],錯誤訊息陣列
15704
			#$result["function"],當前執行的函數名稱.
15705
			#$result["argu"],使用的參數.
15706
			#$result["oriStr"],要分割的原始字串內容
15707
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
15708
			#$result["dataCounts"],爲總共分成幾段
15709
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
15710
			#必填參數:
15711
			#$conf["stringIn"],字串,要處理的字串.
15712
			$conf["stringProcess::spiltString"]["stringIn"]=$line;
15713
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
15714
			$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";
15715
			#可省略參數:
15716
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
15717
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
15718
			#參考資料:
15719
			#無.
15720
			#備註:
15721
			#無.
15722
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
15723
			unset($conf["stringProcess::spiltString"]);
226 liveuser 15724
 
3 liveuser 15725
			#如果執行失敗
15726
			if($spiltString["status"]==="false"){
226 liveuser 15727
 
3 liveuser 15728
				#設置執行錯誤
15729
				$result["status"]="false";
226 liveuser 15730
 
3 liveuser 15731
				#設置錯誤訊息
15732
				$result["error"]=$spiltString;
226 liveuser 15733
 
3 liveuser 15734
				#回傳結果
15735
				return $result;
226 liveuser 15736
 
3 liveuser 15737
				}#if end
226 liveuser 15738
 
3 liveuser 15739
			#如果沒有分割用的" "
15740
			if($spiltString["found"]==="false"){
226 liveuser 15741
 
3 liveuser 15742
				#設置執行錯誤
15743
				$result["status"]="false";
226 liveuser 15744
 
3 liveuser 15745
				#設置錯誤訊息
15746
				$result["error"]=$spiltString;
226 liveuser 15747
 
3 liveuser 15748
				#回傳結果
15749
				return $result;
226 liveuser 15750
 
3 liveuser 15751
				}#if end
226 liveuser 15752
 
3 liveuser 15753
			#如果分割好的數量小於8
15754
			if($spiltString["dataCounts"]<8){
226 liveuser 15755
 
3 liveuser 15756
				#設置執行錯誤
15757
				$result["status"]="false";
226 liveuser 15758
 
3 liveuser 15759
				#設置錯誤訊息
15760
				$result["error"]=$spiltString;
226 liveuser 15761
 
3 liveuser 15762
				#回傳結果
15763
				return $result;
226 liveuser 15764
 
3 liveuser 15765
				}#if end
226 liveuser 15766
 
3 liveuser 15767
			#初始化要儲存的檔案資訊陣列
15768
			$fileInfo=array();
226 liveuser 15769
 
3 liveuser 15770
			#取得 節點類型、權限
15771
			$fileInfo["nType&permission"]=$spiltString["dataArray"][0];
226 liveuser 15772
 
3 liveuser 15773
			#剔除結尾的 "."
15774
			$fileInfo["nType&permission"]=substr($fileInfo["nType&permission"],0,strlen($fileInfo["nType&permission"])-1);
226 liveuser 15775
 
3 liveuser 15776
			#取得節點類型
15777
			$fileInfo["nType"]=$fileInfo["nType&permission"][0];
226 liveuser 15778
 
3 liveuser 15779
			#取得節點權限
15780
			$fileInfo["permission"]=substr($fileInfo["nType&permission"],1);
226 liveuser 15781
 
3 liveuser 15782
			#取得擁有者賬號
15783
			$fileInfo["ownByUser"]=$spiltString["dataArray"][2];
226 liveuser 15784
 
3 liveuser 15785
			#取得群組擁有者群組
15786
			$fileInfo["ownByGroup"]=$spiltString["dataArray"][3];
226 liveuser 15787
 
3 liveuser 15788
			#取得size
15789
			$fileInfo["bytes"]=$spiltString["dataArray"][4];
226 liveuser 15790
 
15791
			#取得最後異動日期
3 liveuser 15792
			$fileInfo["date"]=$spiltString["dataArray"][5];
226 liveuser 15793
 
3 liveuser 15794
			#取得最後異動時間
15795
			$fileInfo["time"]=explode(".",$spiltString["dataArray"][6])[0];
226 liveuser 15796
 
3 liveuser 15797
			#取得最後異動的詳細時間
15798
			$fileInfo["timeDetail"]=$spiltString["dataArray"][6];
226 liveuser 15799
 
3 liveuser 15800
			#取得timezone資訊
15801
			$fileInfo["timezone"]=$spiltString["dataArray"][7];
226 liveuser 15802
 
3 liveuser 15803
			#函式說明:
15804
			#將固定格式的字串分開,並回傳分開的結果.
15805
			#回傳結果:
15806
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15807
			#$result["error"],錯誤訊息陣列
15808
			#$result["function"],當前執行的函數名稱.
15809
			#$result["argu"],使用的參數.
15810
			#$result["oriStr"],要分割的原始字串內容
15811
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
15812
			#$result["dataCounts"],爲總共分成幾段
15813
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
15814
			#必填參數:
15815
			#$conf["stringIn"],字串,要處理的字串.
15816
			$conf["stringProcess::spiltString"]["stringIn"]=$line;
15817
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
15818
			$conf["stringProcess::spiltString"]["spiltSymbol"]=$fileInfo["date"]." ".$fileInfo["timeDetail"]." ".$fileInfo["timezone"];
15819
			#可省略參數:
15820
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
15821
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
15822
			#參考資料:
15823
			#無.
15824
			#備註:
15825
			#無.
15826
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
15827
			unset($conf["stringProcess::spiltString"]);
226 liveuser 15828
 
3 liveuser 15829
			#如果執行失敗
15830
			if($spiltString["status"]==="false"){
226 liveuser 15831
 
3 liveuser 15832
				#設置執行錯誤
15833
				$result["status"]="false";
226 liveuser 15834
 
3 liveuser 15835
				#設置錯誤訊息
15836
				$result["error"]=$spiltString;
226 liveuser 15837
 
3 liveuser 15838
				#回傳結果
15839
				return $result;
226 liveuser 15840
 
3 liveuser 15841
				}#if end
226 liveuser 15842
 
3 liveuser 15843
			#如果沒有分割用的" "
15844
			if($spiltString["found"]==="false"){
226 liveuser 15845
 
3 liveuser 15846
				#設置執行錯誤
15847
				$result["status"]="false";
226 liveuser 15848
 
3 liveuser 15849
				#設置錯誤訊息
15850
				$result["error"]=$spiltString;
226 liveuser 15851
 
3 liveuser 15852
				#回傳結果
15853
				return $result;
226 liveuser 15854
 
3 liveuser 15855
				}#if end
226 liveuser 15856
 
3 liveuser 15857
			#如果分割好的數量小於8
15858
			if($spiltString["dataCounts"]<2){
226 liveuser 15859
 
3 liveuser 15860
				#設置執行錯誤
15861
				$result["status"]="false";
226 liveuser 15862
 
3 liveuser 15863
				#設置錯誤訊息
15864
				$result["error"]=$spiltString;
226 liveuser 15865
 
3 liveuser 15866
				#回傳結果
15867
				return $result;
226 liveuser 15868
 
3 liveuser 15869
				}#if end
226 liveuser 15870
 
3 liveuser 15871
			#取得節點名稱,剔除開頭的空白.
15872
			$fileInfo["name"]=substr($spiltString["dataArray"][1],1);
226 liveuser 15873
 
3 liveuser 15874
			#排除 "." 跟 ".."
15875
			if($fileInfo["name"]==="." || $fileInfo["name"]===".."){
226 liveuser 15876
 
3 liveuser 15877
				#跳過
15878
				continue;
226 liveuser 15879
 
3 liveuser 15880
				}#if end
226 liveuser 15881
 
3 liveuser 15882
			#如果是檔案
15883
			if($fileInfo["nType"]==="-"){
226 liveuser 15884
 
3 liveuser 15885
				#取得mime type
15886
				$fileInfo["mimeType"]=@mime_content_type($conf["path"].$fileInfo["name"]);
226 liveuser 15887
 
3 liveuser 15888
				#如果讀取失敗
15889
				if($fileInfo["mimeType"]===false){
226 liveuser 15890
 
3 liveuser 15891
					#通常為沒有權限
226 liveuser 15892
 
3 liveuser 15893
					#跳過該檔案
15894
					continue;
226 liveuser 15895
 
3 liveuser 15896
					}#if end
226 liveuser 15897
 
3 liveuser 15898
				#確認檔案名稱中間含是否有 "."
15899
				#函式說明:
15900
				#取得關鍵字在字串的哪個位置(字首,字尾,中間)
15901
				#回傳結果:
15902
				#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
15903
				#$result["error"],錯誤訊息陣列.
15904
				#$result["function"],當前執行的函數名稱.
15905
				#$result["found"],是否有關鍵字存在,若為"true",代表存在;反之為"false".
15906
				#$result["argu"],傳入的參數.
15907
				#$result["head"],關鍵字是否在字串的開頭,"true"代表是,"false"代表不是.
15908
				#$result["tail"],關鍵字是否在字串的尾端,"true"代表是,"false"代表不是.
15909
				#$result["center"],關鍵字是否在字串的中間,"true"代表是,"false"代表不是.
15910
				#$result["indexS"],關鍵字在被搜尋字串的哪個位置開始.
15911
				#$result["indexE"],關鍵字在被搜尋字串的哪個位置結束.
15912
				#必填參數:
15913
				#$conf["inputStr"],字串,被搜尋的字串.
15914
				$conf["search::findKeyWordPosition"]["inputStr"]=$fileInfo["name"];
15915
				#$conf["keyWord"],字串,關鍵字.
15916
				$conf["search::findKeyWordPosition"]["keyWord"]=".";
15917
				#可省略參數:
15918
				#無.
15919
				#參考資料:
15920
				#http://php.net/manual/en/function.strpos.php
15921
				#備註:
15922
				#無.
15923
				$findKeyWordPosition=search::findKeyWordPosition($conf["search::findKeyWordPosition"]);
15924
				unset($conf["search::findKeyWordPosition"]);
226 liveuser 15925
 
3 liveuser 15926
				#如果執行失敗
15927
				if($findKeyWordPosition["status"]==="false"){
226 liveuser 15928
 
3 liveuser 15929
					#設置執行錯誤
15930
					$result["status"]="false";
226 liveuser 15931
 
3 liveuser 15932
					#設置錯誤訊息
15933
					$result["error"]=$spiltString;
226 liveuser 15934
 
3 liveuser 15935
					#回傳結果
15936
					return $result;
226 liveuser 15937
 
3 liveuser 15938
					}#if end
226 liveuser 15939
 
3 liveuser 15940
				#如果含有 "." 存在
15941
				if($findKeyWordPosition["found"]==="true"){
226 liveuser 15942
 
3 liveuser 15943
					#如果 "." 是在中間,不是在尾巴.
15944
					if($findKeyWordPosition["center"]==="true" && $findKeyWordPosition["tail"]==="false"){
226 liveuser 15945
 
3 liveuser 15946
						#取得 "." 之後的內容
15947
						#函式說明:
15948
						#將字串特定關鍵字與其前面的內容剔除
15949
						#回傳結果:
15950
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15951
						#$result["error"],錯誤訊息陣列.
15952
						#$result["warning"],警告訊息鎮列.
15953
						#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
15954
						#$result["function"],當前執行的函數名稱.
15955
						#$result["argu"],使用的參數.
15956
						#$result["oriStr"],要處理的原始字串內容.
15957
						#$result["content"],處理好的的字串內容.
15958
						#$result["deleted"],被移除的內容.
15959
						#必填參數:
15960
						#$conf["stringIn"],字串,要處理的字串.
15961
						$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$fileInfo["name"];
15962
						#$conf["keyWord"],字串,特定字串.
15963
						$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=".";
15964
						#可省略參數:
15965
						#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
15966
						$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
15967
						#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
15968
						#$conf["lastResult"]=$delStrBeforeKeyWord;
15969
						#參考資料:
15970
						#無.
15971
						#備註:
15972
						#無.
15973
						$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
15974
						unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 15975
 
3 liveuser 15976
						#如果執行失敗
15977
						if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 15978
 
3 liveuser 15979
							#設置執行錯誤
15980
							$result["status"]="false";
226 liveuser 15981
 
3 liveuser 15982
							#設置錯誤訊息
15983
							$result["error"]=$spiltString;
226 liveuser 15984
 
3 liveuser 15985
							#回傳結果
15986
							return $result;
226 liveuser 15987
 
3 liveuser 15988
							}#if end
226 liveuser 15989
 
3 liveuser 15990
						#如果該存在的 "." 不存在
15991
						if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 15992
 
3 liveuser 15993
							#設置執行錯誤
15994
							$result["status"]="false";
226 liveuser 15995
 
3 liveuser 15996
							#設置錯誤訊息
15997
							$result["error"]=$spiltString;
226 liveuser 15998
 
3 liveuser 15999
							#回傳結果
16000
							return $result;
226 liveuser 16001
 
3 liveuser 16002
							}#if end
226 liveuser 16003
 
3 liveuser 16004
						#取得附檔名
16005
						$fileInfo["secondName"]=$delStrBeforeKeyWord["content"];
226 liveuser 16006
 
3 liveuser 16007
						}#if end
226 liveuser 16008
 
3 liveuser 16009
					}#if end
226 liveuser 16010
 
3 liveuser 16011
				}#if end
226 liveuser 16012
 
3 liveuser 16013
			#儲存檔案資訊
16014
			$result["content"][]=$fileInfo;
226 liveuser 16015
 
3 liveuser 16016
			}#foreach end
226 liveuser 16017
 
3 liveuser 16018
		#設置清單的長度
16019
		$result["dataCount"]=count($result["content"]);
226 liveuser 16020
 
3 liveuser 16021
		#設置執行正常
16022
		$result["status"]="true";
226 liveuser 16023
 
3 liveuser 16024
		#回傳結果
16025
		return $result;
226 liveuser 16026
 
3 liveuser 16027
		}#function ls end
16028
 
16029
	/*
16030
	#函式說明:
16031
	#將 ~ 轉換為家目錄路徑
16032
	#回傳結果:
16033
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16034
	#$result["error"],錯誤訊息.
16035
	#$result["function"],當前執行的函數名稱.
16036
	#$result["content"],轉換好的內容.
16037
	#必填參數:
16038
	#$conf["fileArgu"],字串,變數__FILE__的內容.
16039
	$conf["fileArgu"]=__FILE__;
16040
	#可省略參數:
16041
	#無.
16042
	#參考資料:
16043
	#https://www.businessweekly.com.tw/careers/Blog/14307
16044
	#備註:
16045
	#無.
16046
	*/
16047
	public static function tildeToPath(&$conf){
226 liveuser 16048
 
3 liveuser 16049
		#初始化要回傳的結果
16050
		$result=array();
16051
 
16052
		#取得當前執行的函數名稱
16053
		$result["function"]=__FUNCTION__;
16054
 
16055
		#如果沒有參數
16056
		if(func_num_args()==0){
226 liveuser 16057
 
3 liveuser 16058
			#設置執行失敗
16059
			$result["status"]="false";
226 liveuser 16060
 
3 liveuser 16061
			#設置執行錯誤訊息
16062
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 16063
 
3 liveuser 16064
			#回傳結果
16065
			return $result;
226 liveuser 16066
 
220 liveuser 16067
			}#if end
3 liveuser 16068
 
16069
		#取得參數
16070
		$result["argu"]=$conf;
16071
 
16072
		#如果 $conf 不為陣列
16073
		if(gettype($conf)!=="array"){
226 liveuser 16074
 
3 liveuser 16075
			#設置執行失敗
16076
			$result["status"]="false";
226 liveuser 16077
 
3 liveuser 16078
			#設置執行錯誤訊息
16079
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 16080
 
3 liveuser 16081
			#如果傳入的參數為 null
16082
			if($conf===null){
226 liveuser 16083
 
3 liveuser 16084
				#設置執行錯誤訊息
16085
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 16086
 
3 liveuser 16087
				}#if end
16088
 
16089
			#回傳結果
16090
			return $result;
226 liveuser 16091
 
3 liveuser 16092
			}#if end
226 liveuser 16093
 
3 liveuser 16094
		#函式說明:
16095
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
16096
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16097
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
16098
		#$result["function"],當前執行的函式名稱.
16099
		#$result["argu"],設置給予的參數.
16100
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
16101
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
16102
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
16103
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
16104
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
16105
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
16106
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
16107
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
16108
		#必填寫的參數:
16109
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 16110
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 16111
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
16112
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
16113
		#可以省略的參數:
16114
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
16115
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
16116
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
16117
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
16118
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
16119
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
16120
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
16121
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
16122
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
16123
		#$conf["canBeEmpty"]=array();
16124
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
16125
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web");
16126
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
16127
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
226 liveuser 16128
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 16129
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
16130
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
16131
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
16132
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
16133
		#$conf["disallowAllSkipableVarIsEmpty"]="";
16134
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
16135
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
16136
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
16137
		#$conf["arrayCountEqualCheck"][]=array();
16138
		#參考資料來源:
16139
		#array_keys=>http://php.net/manual/en/function.array-keys.php
16140
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
16141
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 16142
 
3 liveuser 16143
		#如果檢查參數失敗
16144
		if($checkArguments["status"]==="false"){
226 liveuser 16145
 
3 liveuser 16146
			#設置執行失敗
16147
			$result["status"]="false";
226 liveuser 16148
 
3 liveuser 16149
			#設置執行失敗訊息
16150
			$result["error"]=$checkArguments;
226 liveuser 16151
 
3 liveuser 16152
			#回傳結果
16153
			return $result;
226 liveuser 16154
 
3 liveuser 16155
			}#if end
226 liveuser 16156
 
3 liveuser 16157
		#如果檢查參數不通過
16158
		if($checkArguments["passed"]==="false"){
226 liveuser 16159
 
3 liveuser 16160
			#設置執行失敗
16161
			$result["status"]="false";
226 liveuser 16162
 
3 liveuser 16163
			#設置執行失敗訊息
16164
			$result["error"]=$checkArguments;
226 liveuser 16165
 
3 liveuser 16166
			#回傳結果
16167
			return $result;
226 liveuser 16168
 
3 liveuser 16169
			}#if end
16170
 
16171
		#函式說明:
16172
		#呼叫shell執行系統命令,並取得回傳的內容.
16173
		#回傳結果:
16174
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16175
		#$result["error"],錯誤訊息陣列.
16176
		#$result["function"],當前執行的函數名稱.
16177
		#$result["argu"],使用的參數.
16178
		#$result["cmd"],執行的指令內容.
16179
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
16180
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
16181
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
16182
		#$result["running"],是否還在執行.
16183
		#$result["pid"],pid.
16184
		#$result["statusCode"],執行結束後的代碼.
16185
		#必填參數:
16186
		#$conf["command"],字串,要執行的指令與.
16187
		$conf["external::callShell"]["command"]="echo";
16188
		#$conf["fileArgu"],字串,變數__FILE__的內容.
16189
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
16190
		#可省略參數:
16191
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
16192
		$conf["external::callShell"]["argu"]=array("~");
16193
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
16194
		#$conf["arguIsAddr"]=array();
16195
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
16196
		#$conf["plainArgu"]=array();
16197
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
16198
		#$conf["useApostrophe"]=array();
16199
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
16200
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
16201
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
16202
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
16203
		#$conf["enablePrintDescription"]="true";
16204
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
16205
		#$conf["printDescription"]="";
16206
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
16207
		$conf["external::callShell"]["escapeshellarg"]="true";
16208
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
16209
		#$conf["thereIsShellVar"]=array();
16210
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
16211
		#$conf["username"]="";
16212
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
16213
		#$conf["password"]="";
16214
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
16215
		#$conf["useScript"]="";
16216
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
16217
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
16218
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
16219
		#$conf["inBackGround"]="";
16220
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
16221
		#$conf["getErr"]="false";
16222
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
16223
		#$conf["doNotRun"]="false";
16224
		#參考資料:
16225
		#exec=>http://php.net/manual/en/function.exec.php
16226
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
16227
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
16228
		#備註:
16229
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
16230
		$callShell=external::callShell($conf["external::callShell"]);
16231
		unset($conf["external::callShell"]);
16232
 
16233
		#如果執行失敗
16234
		if($callShell["status"]==="false"){
226 liveuser 16235
 
3 liveuser 16236
			#設置執行失敗
16237
			$result["status"]="false";
226 liveuser 16238
 
3 liveuser 16239
			#設置執行失敗訊息
16240
			$result["error"]=$callShell;
226 liveuser 16241
 
3 liveuser 16242
			#回傳結果
16243
			return $result;
226 liveuser 16244
 
3 liveuser 16245
			}#if end
226 liveuser 16246
 
3 liveuser 16247
		#如果沒有預期的輸出
16248
		if(!isset($callShell["output"][0])){
226 liveuser 16249
 
3 liveuser 16250
			#設置執行失敗
16251
			$result["status"]="false";
226 liveuser 16252
 
3 liveuser 16253
			#設置執行失敗訊息
16254
			$result["error"][]="沒有得到預期的輸出";
226 liveuser 16255
 
3 liveuser 16256
			#設置執行失敗訊息
16257
			$result["error"][]=$callShell;
226 liveuser 16258
 
3 liveuser 16259
			#回傳結果
16260
			return $result;
226 liveuser 16261
 
3 liveuser 16262
			}#if end
226 liveuser 16263
 
3 liveuser 16264
		#取得輸出
16265
		$result["content"]=$callShell["output"][0];
226 liveuser 16266
 
3 liveuser 16267
		#設置執行正常
16268
		$result["status"]="true";
226 liveuser 16269
 
3 liveuser 16270
		#回傳結果
16271
		return $result;
226 liveuser 16272
 
3 liveuser 16273
		}#function tildeToPath end
16274
 
16275
	/*
16276
	#函式說明:
16277
	#建立軟連結.
16278
	#回傳結果:
16279
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16280
	#$result["error"],錯誤訊息.
16281
	#$result["function"],當前執行的函數名稱.
16282
	#$result["content"],軟連結的資訊.
16283
	#$result["cmd"],執行的指令陣列.
16284
	#必填參數:
16285
	#$conf["fileArgu"],字串,變數__FILE__的內容.
16286
	$conf["fileArgu"]=__FILE__;
16287
	#$conf["linkTo"],字串,軟連結要指向哪邊.
16288
	$conf["linkTo"]="";
16289
	#可省略參數:
16290
	#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
16291
	#$conf["path"]="";
16292
	#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
16293
	#$conf["name"]="";
16294
	#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
16295
	#$conf["overWrite"]="true";
16296
	#參考資料:
16297
	#無.
16298
	#備註:
16299
	#無.
16300
	*/
16301
	public static function createLink(&$conf){
226 liveuser 16302
 
3 liveuser 16303
		#初始化要回傳的結果
16304
		$result=array();
16305
 
16306
		#取得當前執行的函數名稱
16307
		$result["function"]=__FUNCTION__;
16308
 
16309
		#如果沒有參數
16310
		if(func_num_args()==0){
226 liveuser 16311
 
3 liveuser 16312
			#設置執行失敗
16313
			$result["status"]="false";
226 liveuser 16314
 
3 liveuser 16315
			#設置執行錯誤訊息
16316
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 16317
 
3 liveuser 16318
			#回傳結果
16319
			return $result;
226 liveuser 16320
 
220 liveuser 16321
			}#if end
3 liveuser 16322
 
16323
		#取得參數
16324
		$result["argu"]=$conf;
16325
 
16326
		#如果 $conf 不為陣列
16327
		if(gettype($conf)!=="array"){
226 liveuser 16328
 
3 liveuser 16329
			#設置執行失敗
16330
			$result["status"]="false";
226 liveuser 16331
 
3 liveuser 16332
			#設置執行錯誤訊息
16333
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 16334
 
3 liveuser 16335
			#如果傳入的參數為 null
16336
			if($conf===null){
226 liveuser 16337
 
3 liveuser 16338
				#設置執行錯誤訊息
16339
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 16340
 
3 liveuser 16341
				}#if end
16342
 
16343
			#回傳結果
16344
			return $result;
226 liveuser 16345
 
3 liveuser 16346
			}#if end
226 liveuser 16347
 
3 liveuser 16348
		#函式說明:
16349
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
16350
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16351
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
16352
		#$result["function"],當前執行的函式名稱.
16353
		#$result["argu"],設置給予的參數.
16354
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
16355
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
16356
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
16357
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
16358
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
16359
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
16360
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
16361
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
16362
		#必填寫的參數:
16363
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 16364
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 16365
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
16366
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
16367
		#可以省略的參數:
16368
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
16369
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","linkTo");
16370
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
16371
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
16372
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
16373
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
16374
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
16375
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
16376
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
16377
		#$conf["canBeEmpty"]=array();
16378
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
16379
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("path","name","overWrite");
16380
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
16381
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("path","name","overWrite");
226 liveuser 16382
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 16383
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
16384
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
16385
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"false");
16386
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
16387
		#$conf["disallowAllSkipableVarIsEmpty"]="";
16388
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
16389
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
16390
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
16391
		#$conf["arrayCountEqualCheck"][]=array();
16392
		#參考資料來源:
16393
		#array_keys=>http://php.net/manual/en/function.array-keys.php
16394
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
16395
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 16396
 
3 liveuser 16397
		#如果檢查參數失敗
16398
		if($checkArguments["status"]==="false"){
226 liveuser 16399
 
3 liveuser 16400
			#設置執行失敗
16401
			$result["status"]="false";
226 liveuser 16402
 
3 liveuser 16403
			#設置執行失敗訊息
16404
			$result["error"]=$checkArguments;
226 liveuser 16405
 
3 liveuser 16406
			#回傳結果
16407
			return $result;
226 liveuser 16408
 
3 liveuser 16409
			}#if end
226 liveuser 16410
 
3 liveuser 16411
		#如果檢查參數不通過
16412
		if($checkArguments["passed"]==="false"){
226 liveuser 16413
 
3 liveuser 16414
			#設置執行失敗
16415
			$result["status"]="false";
226 liveuser 16416
 
3 liveuser 16417
			#設置執行失敗訊息
16418
			$result["error"]=$checkArguments;
226 liveuser 16419
 
3 liveuser 16420
			#回傳結果
16421
			return $result;
226 liveuser 16422
 
3 liveuser 16423
			}#if end
16424
 
16425
		#如果是相對位置
16426
		if(!(strpos($conf["linkTo"],"/")===0)){
226 liveuser 16427
 
3 liveuser 16428
			#將 $conf["linkTo"] 轉換為針對產生位置的相對位置.
16429
			#函式說明:
16430
			#將多個路徑字串變成相對於當前路徑的相對路徑字串
16431
			#回傳結果:
16432
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
16433
			#$result["error"],錯誤訊息陣列.
226 liveuser 16434
			#$result["function"],函數名稱.
3 liveuser 16435
			#$result["argu"],使用的參數.
16436
			#$result["content"],字串陣列,多個轉換好的相對路徑字串.
16437
			#必填參數:
16438
			#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
16439
			$conf["fileAccess::getRelativePath"]["path"]=array($conf["linkTo"]);
16440
			#$conf["fileArgu"],字串,當前路徑.
16441
			$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
16442
			#可省略參數:
16443
			#$conf["baseFrom"],字串,指定要依據哪個位置為起點的起始位置,預設不指定,代表使用當前路徑.
16444
			$conf["fileAccess::getRelativePath"]["baseFrom"]=$conf["path"];
16445
			#參考資料:
16446
			#無.
16447
			#備註:
16448
			#無.
16449
			$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
16450
			unset($conf["fileAccess::getRelativePath"]);
16451
 
16452
			#如果執行失敗
16453
			if($getRelativePath["status"]==="false"){
226 liveuser 16454
 
3 liveuser 16455
				#設置執行失敗
16456
				$result["status"]="false";
226 liveuser 16457
 
3 liveuser 16458
				#設置執行失敗訊息
16459
				$result["error"]=$getRelativePath;
226 liveuser 16460
 
3 liveuser 16461
				#回傳結果
16462
				return $result;
226 liveuser 16463
 
3 liveuser 16464
				}#if end
16465
 
16466
			/*
16467
			#break point
16468
			var_dump($conf);
16469
			var_dump($getRelativePath);
16470
			exit;
16471
			*/
16472
 
16473
			#取得執行的指令
16474
			$result["cmd"][]=$getRelativePath["cmd"];
16475
 
16476
			#取得正確的相對位置
16477
			$conf["linkTo"]=$getRelativePath["content"][0];
226 liveuser 16478
 
3 liveuser 16479
			}#if end
16480
 
16481
		#初始化給 ln 指令的參數
16482
		$paramsForLn=array("-s",$conf["linkTo"]);
16483
 
16484
		#函式說明:
16485
		#將字串特定關鍵字與其前面的內容剔除
16486
		#回傳結果:
16487
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16488
		#$result["error"],錯誤訊息陣列.
16489
		#$result["warning"],警告訊息鎮列.
16490
		#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
16491
		#$result["function"],當前執行的函數名稱.
16492
		#$result["oriStr"],要處理的原始字串內容.
226 liveuser 16493
		#$result["content"],處理好的的字串內容.
3 liveuser 16494
		#必填參數:
16495
		#$conf["stringIn"],字串,要處理的字串.
16496
		$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$conf["linkTo"];
16497
		#$conf["keyWord"],字串,特定字串.
16498
		$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="/";
16499
		#可省略參數:
16500
		#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
16501
		$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
16502
		#參考資料:
16503
		#無.
16504
		#備註:
16505
		#無.
16506
		$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
16507
		unset($conf["stringProcess::delStrBeforeKeyWord"]);
16508
 
16509
		#var_dump(__LINE__." ".print_r($delStrBeforeKeyWord,true));
16510
 
16511
		#如果執行失敗
16512
		if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 16513
 
3 liveuser 16514
			#設置執行失敗
16515
			$result["status"]="false";
226 liveuser 16516
 
3 liveuser 16517
			#設置執行失敗訊息
16518
			$result["error"]=$delStrBeforeKeyWord;
226 liveuser 16519
 
3 liveuser 16520
			#回傳結果
16521
			return $result;
226 liveuser 16522
 
3 liveuser 16523
			}#if end
226 liveuser 16524
 
3 liveuser 16525
		#如果沒有找到 "/"
16526
		if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 16527
 
3 liveuser 16528
			#設置 預設的 軟連名稱
16529
			$softLink=$conf["linkTo"];
226 liveuser 16530
 
3 liveuser 16531
			}#if end
16532
 
16533
		#反之有 "/"
16534
		else{
226 liveuser 16535
 
3 liveuser 16536
			#設置 預設的 軟連結名稱
16537
			$softLink=$delStrBeforeKeyWord["content"];
226 liveuser 16538
 
3 liveuser 16539
			}#else end
16540
 
16541
		/*
16542
		#break point
16543
		var_dump(__LINE__." ".$softLink);
16544
		exit;
16545
		*/
16546
 
16547
		#預設欲建立的軟連結名稱
16548
		$createdSoftLink=$softLink;
16549
 
16550
		#如果有設置 path
16551
		if(isset($conf["path"])){
226 liveuser 16552
 
3 liveuser 16553
			#確認 path 存在
16554
			#函式說明:
16555
			#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
16556
			#回傳結果:
16557
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
16558
			#$result["error"],錯誤訊息陣列
16559
			#$result["warning"],警告訊息陣列
16560
			#必填參數:
16561
			#$conf["dirPositionAndName"]="";#新建的位置與名稱
16562
			$conf["fileAccess::createNewFolder"]["dirPositionAndName"]=$conf["path"];
16563
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
16564
			$conf["fileAccess::createNewFolder"]["fileArgu"]=$conf["fileArgu"];
16565
			#可省略參數:
16566
			#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
16567
			#$conf["dirPermission"]="";
16568
			#參考資料:
16569
			#mkdir=>http://php.net/manual/en/function.mkdir.php
16570
			#chmod=>http://php.net/manual/en/function.chmod.php
16571
			#參考資料:
16572
			#無.
16573
			#備註:
16574
			#同 function createFolderAfterCheck.
16575
			$createNewFolder=fileAccess::createNewFolder($conf["fileAccess::createNewFolder"]);
16576
			unset($conf["fileAccess::createNewFolder"]);
226 liveuser 16577
 
3 liveuser 16578
			#如果執行失敗
16579
			if($createNewFolder["status"]==="false"){
226 liveuser 16580
 
3 liveuser 16581
				#設置執行失敗
16582
				$result["status"]="false";
226 liveuser 16583
 
3 liveuser 16584
				#設置執行失敗訊息
16585
				$result["error"]=$createNewFolder;
226 liveuser 16586
 
3 liveuser 16587
				#回傳結果
16588
				return $result;
226 liveuser 16589
 
3 liveuser 16590
				}#if end
226 liveuser 16591
 
3 liveuser 16592
			#var_dump(__LINE__." ".print_r($conf,true));
226 liveuser 16593
 
3 liveuser 16594
			#預設要加 slash
16595
			$slash="/";
226 liveuser 16596
 
3 liveuser 16597
			#如果 path 為 "/" 結尾
16598
			if($conf["path"][strlen($conf["path"])-1]==="/"){
226 liveuser 16599
 
3 liveuser 16600
				#不用 slash
16601
				$slash="";
226 liveuser 16602
 
3 liveuser 16603
				}#if end
226 liveuser 16604
 
3 liveuser 16605
			#如果有設置 name
16606
			if(isset($conf["name"])){
226 liveuser 16607
 
3 liveuser 16608
				#指定軟連結要放在哪邊
16609
				$paramsForLn[]=$conf["path"].$slash.$conf["name"];
226 liveuser 16610
 
3 liveuser 16611
				#更新欲建立的軟連結名稱
16612
				$createdSoftLink=$conf["path"].$slash.$conf["name"];
226 liveuser 16613
 
3 liveuser 16614
				/*
16615
				#break point
16616
				var_dump($conf["path"],$softLink,$createdSoftLink);
16617
				exit;
16618
				*/
226 liveuser 16619
 
3 liveuser 16620
				}#if end
226 liveuser 16621
 
3 liveuser 16622
			#反之
16623
			else{
226 liveuser 16624
 
3 liveuser 16625
				#指定軟連結要放在哪邊
16626
				$paramsForLn[]=$conf["path"];
226 liveuser 16627
 
3 liveuser 16628
				#更新欲建立的軟連結名稱
16629
				$createdSoftLink=$conf["path"].$slash.$softLink;
226 liveuser 16630
 
3 liveuser 16631
				/*
16632
				#break point
16633
				var_dump($conf["path"],$softLink,$createdSoftLink);
16634
				exit;
16635
				*/
226 liveuser 16636
 
3 liveuser 16637
				}#else end
226 liveuser 16638
 
3 liveuser 16639
			#var_dump($createdSoftLink);
226 liveuser 16640
 
3 liveuser 16641
			}#if end
226 liveuser 16642
 
3 liveuser 16643
		#反之如果有設置 name
16644
		else if(isset($conf["name"])){
226 liveuser 16645
 
3 liveuser 16646
			#指定軟連結的名稱
16647
			$paramsForLn[]=$conf["name"];
226 liveuser 16648
 
3 liveuser 16649
			#更新欲建立的軟連結名稱
16650
			$createdSoftLink=$conf["name"];
226 liveuser 16651
 
3 liveuser 16652
			#var_dump(__LINE__." ".$createdSoftLink);
226 liveuser 16653
 
3 liveuser 16654
			}#if end
226 liveuser 16655
 
3 liveuser 16656
		/*
16657
		# break point
16658
		var_dump($createdSoftLink);
16659
		exit;
16660
		*/
226 liveuser 16661
 
3 liveuser 16662
		#如果要覆蓋既有的目標
16663
		if($conf["overWrite"]==="true"){
226 liveuser 16664
 
3 liveuser 16665
			#函式說明:
16666
			#移除檔案
16667
			#回傳結果:
16668
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
16669
			#$result["error"],錯誤訊息陣列
16670
			#$result["warning"],警告訊息陣列
16671
			#$result["function"],當前執行的函數名稱
16672
			#必填參數:
16673
			#$conf["fileAddress"],字串,要移除檔案的位置.
16674
			$conf["fileAccess::delFile"]["fileAddress"]=$createdSoftLink;
16675
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
16676
			$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
16677
			#可省略參數:
16678
			#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
16679
			#$conf["commentsArray"]=array("");
16680
			#$conf["allowDelSymlink"],字串,預設為"false",不移除軟連結;"true"代表要移除軟連結.
16681
			$conf["fileAccess::delFile"]["allowDelSymlink"]="true";
16682
			#$conf["allowDelFolder"],字串,預設為"false",不移除目錄;"true"代表要移除目錄.
16683
			$conf["fileAccess::delFile"]["allowDelFolder"]="true";
16684
			#參考資料:
16685
			#無.
16686
			#備註:
16687
			#無.
16688
			$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
226 liveuser 16689
			unset($conf["fileAccess::delFile"]);
16690
 
3 liveuser 16691
			/*
16692
			#break point
16693
			var_dump($delFile);
16694
			exit;
16695
			*/
226 liveuser 16696
 
3 liveuser 16697
			#如果執行失敗
16698
			if($delFile["status"]==="false"){
226 liveuser 16699
 
3 liveuser 16700
				#設置執行失敗
16701
				$result["status"]="false";
226 liveuser 16702
 
3 liveuser 16703
				#設置執行失敗訊息
16704
				$result["error"]=$delFile;
226 liveuser 16705
 
3 liveuser 16706
				#回傳結果
16707
				return $result;
226 liveuser 16708
 
3 liveuser 16709
				}#if end
226 liveuser 16710
 
3 liveuser 16711
			}#if end
16712
 
16713
		#函式說明:
16714
		#呼叫shell執行系統命令,並取得回傳的內容.
16715
		#回傳結果:
16716
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16717
		#$result["error"],錯誤訊息陣列.
16718
		#$result["function"],當前執行的函數名稱.
16719
		#$result["argu"],使用的參數.
16720
		#$result["cmd"],執行的指令內容.
16721
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
16722
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
16723
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
16724
		#$result["running"],是否還在執行.
16725
		#$result["pid"],pid.
16726
		#$result["statusCode"],執行結束後的代碼.
16727
		#必填參數:
16728
		#$conf["command"],字串,要執行的指令與.
16729
		$conf["external::callShell"]["command"]="ln";
16730
		#$conf["fileArgu"],字串,變數__FILE__的內容.
16731
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
16732
		#可省略參數:
16733
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
16734
		$conf["external::callShell"]["argu"]=$paramsForLn;
16735
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
16736
		#$conf["arguIsAddr"]=array();
16737
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
16738
		#$conf["plainArgu"]=array();
16739
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
16740
		#$conf["useApostrophe"]=array();
16741
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
16742
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
16743
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
16744
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
16745
		#$conf["enablePrintDescription"]="true";
16746
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
16747
		#$conf["printDescription"]="";
16748
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
16749
		$conf["external::callShell"]["escapeshellarg"]="true";
16750
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
16751
		#$conf["thereIsShellVar"]=array();
16752
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
16753
		#$conf["username"]="";
16754
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
16755
		#$conf["password"]="";
16756
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
16757
		#$conf["useScript"]="";
16758
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
16759
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
16760
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
16761
		#$conf["inBackGround"]="";
16762
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
16763
		$conf["external::callShell"]["getErr"]="true";
16764
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
16765
		#$conf["doNotRun"]="false";
16766
		#參考資料:
16767
		#exec=>http://php.net/manual/en/function.exec.php
16768
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
16769
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
16770
		#備註:
16771
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
16772
		$callShell=external::callShell($conf["external::callShell"]);
16773
		unset($conf["external::callShell"]);
16774
 
16775
		#如果執行失敗
16776
		if($callShell["status"]==="false"){
226 liveuser 16777
 
3 liveuser 16778
			#設置執行失敗
16779
			$result["status"]="false";
226 liveuser 16780
 
3 liveuser 16781
			#設置執行失敗訊息
16782
			$result["error"]=$callShell;
226 liveuser 16783
 
3 liveuser 16784
			#回傳結果
16785
			return $result;
226 liveuser 16786
 
3 liveuser 16787
			}#if end
226 liveuser 16788
 
3 liveuser 16789
		#保存執行的指令
16790
		$result["cmd"][]=$callShell["cmd"];
226 liveuser 16791
 
3 liveuser 16792
		#初始化給 ls 指令的參數
16793
		$paramsForLs=array("-l",$paramsForLn[count($paramsForLn)-1]);
226 liveuser 16794
 
3 liveuser 16795
		#取得軟連結的資訊
16796
		#函式說明:
16797
		#呼叫shell執行系統命令,並取得回傳的內容.
16798
		#回傳結果:
16799
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16800
		#$result["error"],錯誤訊息陣列.
16801
		#$result["function"],當前執行的函數名稱.
16802
		#$result["argu"],使用的參數.
16803
		#$result["cmd"],執行的指令內容.
16804
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
16805
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
16806
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
16807
		#$result["running"],是否還在執行.
16808
		#$result["pid"],pid.
16809
		#$result["statusCode"],執行結束後的代碼.
16810
		#必填參數:
16811
		#$conf["command"],字串,要執行的指令與.
16812
		$conf["external::callShell"]["command"]="ls";
16813
		#$conf["fileArgu"],字串,變數__FILE__的內容.
16814
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
16815
		#可省略參數:
16816
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
16817
		$conf["external::callShell"]["argu"]=$paramsForLs;
16818
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
16819
		#$conf["arguIsAddr"]=array();
16820
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
16821
		#$conf["plainArgu"]=array();
16822
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
16823
		#$conf["useApostrophe"]=array();
16824
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
16825
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
16826
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
16827
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
16828
		#$conf["enablePrintDescription"]="true";
16829
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
16830
		#$conf["printDescription"]="";
16831
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
16832
		$conf["external::callShell"]["escapeshellarg"]="true";
16833
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
16834
		#$conf["thereIsShellVar"]=array();
16835
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
16836
		#$conf["username"]="";
16837
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
16838
		#$conf["password"]="";
16839
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
16840
		#$conf["useScript"]="";
16841
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
16842
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
16843
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
16844
		#$conf["inBackGround"]="";
16845
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
16846
		$conf["external::callShell"]["getErr"]="true";
16847
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
16848
		#$conf["doNotRun"]="false";
16849
		#參考資料:
16850
		#exec=>http://php.net/manual/en/function.exec.php
16851
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
16852
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
16853
		#備註:
16854
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
16855
		$callShell=external::callShell($conf["external::callShell"]);
16856
		unset($conf["external::callShell"]);
16857
 
16858
		#如果執行失敗
16859
		if($callShell["status"]==="false"){
226 liveuser 16860
 
3 liveuser 16861
			#設置執行失敗
16862
			$result["status"]="false";
226 liveuser 16863
 
3 liveuser 16864
			#設置執行失敗訊息
16865
			$result["error"]=$callShell;
226 liveuser 16866
 
3 liveuser 16867
			#回傳結果
16868
			return $result;
226 liveuser 16869
 
3 liveuser 16870
			}#if end
226 liveuser 16871
 
3 liveuser 16872
		#保存執行的指令
16873
		$result["cmd"][]=$callShell["cmd"];
226 liveuser 16874
 
3 liveuser 16875
		#取得軟連結的資訊
16876
		$result["content"]=$callShell["output"];
226 liveuser 16877
 
3 liveuser 16878
		#設置執行正常
16879
		$result["status"]="true";
226 liveuser 16880
 
3 liveuser 16881
		#回傳結果
16882
		return $result;
226 liveuser 16883
 
3 liveuser 16884
		}#function createLink end
16885
 
16886
	/*
16887
	#函式說明:
16888
	#針對特定目錄下的內容建立軟連結.
16889
	#回傳結果:
16890
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16891
	#$result["error"],錯誤訊息.
16892
	#$result["function"],當前執行的函數名稱.
16893
	#$result["content"],字串陣列,每個建立的軟連結資訊.
16894
	#必填參數:
16895
	#$conf["fileArgu"],字串,變數__FILE__的內容.
16896
	$conf["fileArgu"]=__FILE__;
16897
	#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
16898
	$conf["linkToDir"]="";
16899
	#可省略參數:
16900
	#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
16901
	#$conf["path"]="";
16902
	#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
16903
	#$conf["name"]=array(array("oriName","newName"));
16904
	#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
16905
	#$conf["overWrite"]="true";
16906
	#參考資料:
16907
	#無.
16908
	#備註:
16909
	#無.
16910
	*/
16911
	public static function createMultiLinkInDir(&$conf){
226 liveuser 16912
 
3 liveuser 16913
		#初始化要回傳的結果
16914
		$result=array();
16915
 
16916
		#取得當前執行的函數名稱
16917
		$result["function"]=__FUNCTION__;
16918
 
16919
		#如果沒有參數
16920
		if(func_num_args()==0){
226 liveuser 16921
 
3 liveuser 16922
			#設置執行失敗
16923
			$result["status"]="false";
226 liveuser 16924
 
3 liveuser 16925
			#設置執行錯誤訊息
16926
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 16927
 
3 liveuser 16928
			#回傳結果
16929
			return $result;
226 liveuser 16930
 
220 liveuser 16931
			}#if end
3 liveuser 16932
 
16933
		#取得參數
16934
		$result["argu"]=$conf;
16935
 
16936
		#如果 $conf 不為陣列
16937
		if(gettype($conf)!=="array"){
226 liveuser 16938
 
3 liveuser 16939
			#設置執行失敗
16940
			$result["status"]="false";
226 liveuser 16941
 
3 liveuser 16942
			#設置執行錯誤訊息
16943
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 16944
 
3 liveuser 16945
			#如果傳入的參數為 null
16946
			if($conf===null){
226 liveuser 16947
 
3 liveuser 16948
				#設置執行錯誤訊息
16949
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 16950
 
3 liveuser 16951
				}#if end
16952
 
16953
			#回傳結果
16954
			return $result;
226 liveuser 16955
 
3 liveuser 16956
			}#if end
226 liveuser 16957
 
3 liveuser 16958
		#檢查參數
16959
		#函式說明:
16960
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
16961
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16962
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
16963
		#$result["function"],當前執行的函式名稱.
16964
		#$result["argu"],設置給予的參數.
16965
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
16966
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
16967
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
16968
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
16969
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
16970
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
16971
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
16972
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
16973
		#必填寫的參數:
16974
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
226 liveuser 16975
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 16976
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
16977
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
16978
		#可以省略的參數:
16979
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
16980
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","linkToDir");
16981
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
16982
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
16983
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
16984
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
16985
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
16986
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
16987
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
16988
		#$conf["canBeEmpty"]=array();
16989
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
16990
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("path","name","overWrite");
16991
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
16992
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("path","name","overWrite");
226 liveuser 16993
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 16994
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","string");
16995
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
16996
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(".",null,"false");
16997
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
16998
		#$conf["disallowAllSkipableVarIsEmpty"]="";
16999
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
17000
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
17001
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
17002
		#$conf["arrayCountEqualCheck"][]=array();
17003
		#參考資料來源:
17004
		#array_keys=>http://php.net/manual/en/function.array-keys.php
17005
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
17006
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 17007
 
3 liveuser 17008
		#如果檢查參數失敗
17009
		if($checkArguments["status"]==="false"){
226 liveuser 17010
 
3 liveuser 17011
			#設置執行失敗
17012
			$result["status"]="false";
226 liveuser 17013
 
3 liveuser 17014
			#設置執行失敗訊息
17015
			$result["error"]=$checkArguments;
226 liveuser 17016
 
3 liveuser 17017
			#回傳結果
17018
			return $result;
226 liveuser 17019
 
3 liveuser 17020
			}#if end
226 liveuser 17021
 
3 liveuser 17022
		#如果檢查參數不通過
17023
		if($checkArguments["passed"]==="false"){
226 liveuser 17024
 
3 liveuser 17025
			#設置執行失敗
17026
			$result["status"]="false";
226 liveuser 17027
 
3 liveuser 17028
			#設置執行失敗訊息
17029
			$result["error"]=$checkArguments;
226 liveuser 17030
 
3 liveuser 17031
			#回傳結果
17032
			return $result;
226 liveuser 17033
 
3 liveuser 17034
			}#if end
226 liveuser 17035
 
3 liveuser 17036
		#函式說明:
17037
		#取得目錄底下所有目錄與檔案清單.
17038
		#回傳結果:
17039
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
17040
		#$result["error"],錯誤訊息陣列.
17041
		#$result["function"],函數名稱.
17042
		#$result["content"],陣列,目錄底下的檔案與子目錄.
17043
		#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
17044
		#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
17045
		#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
17046
		#$result["position"],目前的位置.
17047
		#必填參數:
17048
		#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
17049
		$conf["fileAccess::getList"]["position"]=$conf["linkToDir"];
17050
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17051
		$conf["fileAccess::getList"]["fileArgu"]=$conf["fileArgu"];
17052
		#可省略參數:
17053
		#無
17054
		#參考資料:
17055
		#opendir=>http://php.net/manual/en/function.opendir.php
17056
		#is_dir=>http://php.net/manual/en/function.is-dir.php
17057
		#備註:
17058
		#無.
17059
		$getList=fileAccess::getList($conf["fileAccess::getList"]);
17060
		unset($conf["fileAccess::getList"]);
226 liveuser 17061
 
3 liveuser 17062
		#如果檢查參數失敗
17063
		if($getList["status"]==="false"){
226 liveuser 17064
 
3 liveuser 17065
			#設置執行失敗
17066
			$result["status"]="false";
226 liveuser 17067
 
3 liveuser 17068
			#設置執行失敗訊息
17069
			$result["error"]=$getList;
226 liveuser 17070
 
3 liveuser 17071
			#回傳結果
17072
			return $result;
226 liveuser 17073
 
3 liveuser 17074
			}#if end
226 liveuser 17075
 
3 liveuser 17076
		#針對目標目錄底下的所有檔案
17077
		foreach($getList["content"] as $oriName){
226 liveuser 17078
 
3 liveuser 17079
			#如果有設定 $conf["name"]
17080
			if(isset($conf["name"])){
226 liveuser 17081
 
3 liveuser 17082
				#預設不指定新的軟連結名稱
17083
				unset($newSoftLinkName);
226 liveuser 17084
 
3 liveuser 17085
				#針對每個原始目標的名稱
17086
				foreach($conf["name"] as $customName){
226 liveuser 17087
 
3 liveuser 17088
					#如果是指定的目標
17089
					if($oriName["name"]===$customName[0]){
226 liveuser 17090
 
3 liveuser 17091
						#設置新的軟連結名稱
17092
						$newSoftLinkName=$customName[1];
226 liveuser 17093
 
3 liveuser 17094
						}#if end
226 liveuser 17095
 
3 liveuser 17096
					}#foreach end
226 liveuser 17097
 
3 liveuser 17098
				}#if end
226 liveuser 17099
 
3 liveuser 17100
			#建立軟連結
17101
			#函式說明:
17102
			#建立軟連結.
17103
			#回傳結果:
17104
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17105
			#$result["error"],錯誤訊息.
17106
			#$result["function"],當前執行的函數名稱.
17107
			#$result["content"],軟連結的資訊.
17108
			#必填參數:
17109
			#$conf["fileArgu"],字串,變數__FILE__的內容.
17110
			$conf["fileAccess::createLink"]["fileArgu"]=$conf["fileArgu"];
17111
			#$conf["linkTo"],字串,軟連結要指向哪邊.
17112
			$conf["fileAccess::createLink"]["linkTo"]=$conf["linkToDir"]."/".$oriName["name"];
17113
			#可省略參數:
17114
			#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
17115
			$conf["fileAccess::createLink"]["path"]=$conf["path"];
226 liveuser 17116
 
3 liveuser 17117
			#如果有新的軟連結名稱
17118
			if(isset($newSoftLinkName)){
226 liveuser 17119
 
3 liveuser 17120
				#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
17121
				$conf["fileAccess::createLink"]["name"]=$newSoftLinkName;
226 liveuser 17122
 
3 liveuser 17123
				}#if end
226 liveuser 17124
 
3 liveuser 17125
			#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
17126
			$conf["fileAccess::createLink"]["overWrite"]=$conf["overWrite"];
226 liveuser 17127
 
3 liveuser 17128
			#參考資料:
17129
			#無.
17130
			#備註:
17131
			#無.
17132
			$createLink=fileAccess::createLink($conf["fileAccess::createLink"]);
17133
			unset($conf["fileAccess::createLink"]);
226 liveuser 17134
 
3 liveuser 17135
			#var_dump(__LINE__." ".print_r($createLink,true));
226 liveuser 17136
 
3 liveuser 17137
			#如果檢查參數失敗
17138
			if($createLink["status"]==="false"){
226 liveuser 17139
 
3 liveuser 17140
				#設置執行失敗
17141
				$result["status"]="false";
226 liveuser 17142
 
3 liveuser 17143
				#設置執行失敗訊息
17144
				$result["error"]=$createLink;
226 liveuser 17145
 
3 liveuser 17146
				#回傳結果
17147
				return $result;
226 liveuser 17148
 
3 liveuser 17149
				}#if end
226 liveuser 17150
 
3 liveuser 17151
			#儲存建立好的軟連結資訊
17152
			$result["content"][]=$createLink["content"];
226 liveuser 17153
 
3 liveuser 17154
			}#foreach end
226 liveuser 17155
 
3 liveuser 17156
		#設置執行正常
17157
		$result["status"]="true";
226 liveuser 17158
 
3 liveuser 17159
		#回傳結果
17160
		return $result;
226 liveuser 17161
 
3 liveuser 17162
		}#function createMultiLink end
17163
 
17164
	/*
17165
	#函式說明:
17166
	#更新檔案的內容.
17167
	#回傳結果:
17168
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17169
	#$result["error"],錯誤訊息.
17170
	#$result["function"],當前執行的函數名稱.
220 liveuser 17171
	#$result["content"],更新的資訊.
17172
	#$result["content"][$lineIndex]["ori"],原始 $lineIndex+1 行的內容,若為null則代表不存在.
17173
	#$result["content"][$lineIndex]["new"],新 $lineIndex+1 行的內容,若為null則代表不存在.
3 liveuser 17174
	#必填參數:
17175
	#$conf["fileArgu"],字串,變數__FILE__的內容.
17176
	$conf["fileArgu"]=__FILE__;
17177
	#$conf["file"],字串,要更新的檔案位置與名稱.
17178
	$conf["file"]="";
17179
	#可省略參數:
17180
	#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
17181
	#$conf["overWriteWith"]=array();
17182
	#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
17183
	#$conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
17184
	#$conf["replaceLike"],字串,預設為"false",代表要完全符合關鍵字才能進行整行替換;反之為"true".
17185
	#$conf["replaceLike"]="false";
17186
	#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
17187
	#$conf["addToTailWhenNoMatch"]="false";
17188
	#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
17189
	#$conf["addToTailBeforeThat"]="?\>";
220 liveuser 17190
	#$conf["replaceSpecifyLine"],字串陣列,將指定的行取代成指定的內容,元素的key為原始檔案的行索引,若key為$i+1,則代表第$i行;元素的數值就為該行的新內容.
17191
	#$conf["replaceSpecifyLine"]=array();
17192
	#$conf["outputPath"],字串,檔案要輸出到哪個位置,預設不指定,直接取代原始檔案的內容.
17193
	#$conf["outputPath"]="";
3 liveuser 17194
	#參考資料:
17195
	#無.
17196
	#備註:
17197
	#無.
17198
	*/
17199
	public static function updateFile(&$conf){
226 liveuser 17200
 
3 liveuser 17201
		#初始化要回傳的結果
17202
		$result=array();
17203
 
17204
		#取得當前執行的函數名稱
17205
		$result["function"]=__FUNCTION__;
17206
 
17207
		#如果沒有參數
17208
		if(func_num_args()==0){
226 liveuser 17209
 
3 liveuser 17210
			#設置執行失敗
17211
			$result["status"]="false";
226 liveuser 17212
 
3 liveuser 17213
			#設置執行錯誤訊息
17214
			$result["error"]="函數".$result["function"]."需要參數";
226 liveuser 17215
 
3 liveuser 17216
			#回傳結果
17217
			return $result;
226 liveuser 17218
 
220 liveuser 17219
			}#if end
3 liveuser 17220
 
17221
		#取得參數
17222
		$result["argu"]=$conf;
17223
 
17224
		#如果 $conf 不為陣列
17225
		if(gettype($conf)!=="array"){
226 liveuser 17226
 
3 liveuser 17227
			#設置執行失敗
17228
			$result["status"]="false";
226 liveuser 17229
 
3 liveuser 17230
			#設置執行錯誤訊息
17231
			$result["error"][]="\$conf變數須為陣列形態";
226 liveuser 17232
 
3 liveuser 17233
			#如果傳入的參數為 null
17234
			if($conf===null){
226 liveuser 17235
 
3 liveuser 17236
				#設置執行錯誤訊息
17237
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 17238
 
3 liveuser 17239
				}#if end
17240
 
17241
			#回傳結果
17242
			return $result;
226 liveuser 17243
 
3 liveuser 17244
			}#if end
226 liveuser 17245
 
3 liveuser 17246
		#檢查參數
17247
		#函式說明:
17248
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
17249
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17250
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
17251
		#$result["function"],當前執行的函式名稱.
17252
		#$result["argu"],設置給予的參數.
17253
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
17254
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
17255
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
17256
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
17257
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
17258
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
17259
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
17260
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
17261
		#必填寫的參數:
17262
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
220 liveuser 17263
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3 liveuser 17264
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
17265
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
17266
		#可以省略的參數:
17267
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
17268
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","file");
17269
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
17270
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
17271
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
17272
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
17273
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
17274
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
17275
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
17276
		#$conf["canBeEmpty"]=array();
17277
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
220 liveuser 17278
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("overWriteWith","replaceWith","addToTailWhenNoMatch","addToTailBeforeThat","replaceLike","replaceSpecifyLine","outputPath");
3 liveuser 17279
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
220 liveuser 17280
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("overWriteWith","replaceWith","addToTailWhenNoMatch","addToTailBeforeThat","replaceLike","replaceSpecifyLine","outputPath");
226 liveuser 17281
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
220 liveuser 17282
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","array","string","string","string","array","string");
3 liveuser 17283
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
220 liveuser 17284
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"false",null,"false",null,null);
3 liveuser 17285
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
17286
		#$conf["disallowAllSkipableVarIsEmpty"]="";
17287
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
17288
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
17289
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
17290
		#$conf["arrayCountEqualCheck"][]=array();
17291
		#參考資料來源:
17292
		#array_keys=>http://php.net/manual/en/function.array-keys.php
17293
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
17294
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 17295
 
3 liveuser 17296
		#如果檢查參數失敗
17297
		if($checkArguments["status"]==="false"){
226 liveuser 17298
 
3 liveuser 17299
			#設置執行失敗
17300
			$result["status"]="false";
226 liveuser 17301
 
3 liveuser 17302
			#設置執行失敗訊息
17303
			$result["error"]=$checkArguments;
226 liveuser 17304
 
3 liveuser 17305
			#回傳結果
17306
			return $result;
226 liveuser 17307
 
3 liveuser 17308
			}#if end
226 liveuser 17309
 
3 liveuser 17310
		#如果檢查參數不通過
17311
		if($checkArguments["passed"]==="false"){
226 liveuser 17312
 
3 liveuser 17313
			#設置執行失敗
17314
			$result["status"]="false";
226 liveuser 17315
 
3 liveuser 17316
			#設置執行失敗訊息
17317
			$result["error"]=$checkArguments;
226 liveuser 17318
 
3 liveuser 17319
			#回傳結果
17320
			return $result;
226 liveuser 17321
 
3 liveuser 17322
			}#if end
226 liveuser 17323
 
3 liveuser 17324
		#檢查檔案是否存在
17325
		#函式說明:
17326
		#檢查多個檔案與資料夾是否存在.
17327
		#回傳的結果:
17328
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
17329
		#$result["error"],錯誤訊息陣列.
17330
		#$resutl["function"],當前執行的涵式名稱.
17331
		#$result["argu"],使用的參數.
17332
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
17333
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
17334
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
17335
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
17336
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
17337
		#必填參數:
17338
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
17339
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
17340
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17341
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
17342
		#可省略參數:
17343
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
17344
		$conf["disableWebSearch"]="true";
17345
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
17346
		$conf["userDir"]="false";
17347
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
17348
		$conf["web"]="false";
17349
		#參考資料:
17350
		#http://php.net/manual/en/function.file-exists.php
17351
		#http://php.net/manual/en/control-structures.foreach.php
17352
		#備註:
17353
		#函數file_exists檢查的路徑為檔案系統的路徑
17354
		#$result["varName"][$i]結果未實作
17355
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
17356
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 17357
 
3 liveuser 17358
		#如果檢查參數失敗
17359
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 17360
 
3 liveuser 17361
			#設置執行失敗
17362
			$result["status"]="false";
226 liveuser 17363
 
3 liveuser 17364
			#設置執行失敗訊息
17365
			$result["error"]=$checkMultiFileExist;
226 liveuser 17366
 
3 liveuser 17367
			#回傳結果
17368
			return $result;
226 liveuser 17369
 
3 liveuser 17370
			}#if end
226 liveuser 17371
 
3 liveuser 17372
		#如果目標檔案不存在
17373
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 17374
 
3 liveuser 17375
			#設置執行失敗
17376
			$result["status"]="false";
226 liveuser 17377
 
3 liveuser 17378
			#設置執行失敗訊息
17379
			$result["error"]=$checkMultiFileExist;
226 liveuser 17380
 
3 liveuser 17381
			#回傳結果
17382
			return $result;
226 liveuser 17383
 
3 liveuser 17384
			}#if end
226 liveuser 17385
 
220 liveuser 17386
		#預設要寫入的位置為原始檔案
17387
		$file2write=$conf["file"];
226 liveuser 17388
 
220 liveuser 17389
		#如果有設置 outputPath
17390
		if(isset($conf["outputPath"])){
226 liveuser 17391
 
220 liveuser 17392
			#寫入檔案的路徑與名稱
17393
			$file2write=$conf["outputPath"]."/".$conf["file"];
226 liveuser 17394
 
220 liveuser 17395
			}#if end
226 liveuser 17396
 
3 liveuser 17397
		#如果有設置 overWriteWith
17398
		if(isset($conf["overWriteWith"])){
226 liveuser 17399
 
3 liveuser 17400
			#函式說明:
17401
			#將多行字串寫入到檔案
17402
			#回傳結果:
17403
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
17404
			#$result["error"],錯誤訊息陣列.
17405
			#$result["function"],當前執行函數的名稱.
17406
			#必填參數:
17407
			#$conf["fileName"],字串,爲要編輯的檔案名稱
220 liveuser 17408
			$conf["fileAccess::writeMultiLine"]["fileName"]=$file2write;
3 liveuser 17409
			#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
17410
			$conf["fileAccess::writeMultiLine"]["inputString"]=$conf["overWriteWith"];
17411
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17412
			$conf["fileAccess::writeMultiLine"]["fileArgu"]=$conf["fileArgu"];
220 liveuser 17413
			#$conf["fastWrite"],字串,“true”代表要一次寫入多行內容;預設為"false"代表一次寫入一行,比較安全,但行數一多會需要等待多時.
17414
			$conf["fileAccess::writeMultiLine"]["fastWrite"]="true";
3 liveuser 17415
			#可省略參數:
17416
			#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
17417
			#參考資料:
17418
			#無.
17419
			#備註:
17420
			#無.
17421
			$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
17422
			unset($conf["fileAccess::writeMultiLine"]);
226 liveuser 17423
 
3 liveuser 17424
			#如果執行失敗
17425
			if($writeMultiLine["status"]==="false"){
226 liveuser 17426
 
3 liveuser 17427
				#設置執行失敗
17428
				$result["status"]="false";
226 liveuser 17429
 
3 liveuser 17430
				#設置執行失敗訊息
17431
				$result["error"]=$writeMultiLine;
226 liveuser 17432
 
3 liveuser 17433
				#回傳結果
17434
				return $result;
226 liveuser 17435
 
3 liveuser 17436
				}#if end
226 liveuser 17437
 
220 liveuser 17438
			#取得原始檔案的內容
17439
			#函式說明:
17440
			#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
17441
			#回傳的變數說明:
17442
			#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
17443
			#$result["error"],錯誤訊息提示.
17444
			#$result["warning"],警告訊息.
17445
			#$result["function"],當前執行的函數名稱.
17446
			#$result["fileContent"],爲檔案的內容陣列.
17447
			#$result["lineCount"],爲檔案內容總共的行數.
17448
			#$result["fullContent"],為檔案的完整內容.
17449
			#$result["base64data"],為檔案的base64內容.
17450
			#$result["mimeType"],為檔案的mime type.
17451
			#必填參數:
17452
			#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
17453
			$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["file"];
17454
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17455
			$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
17456
			#可省略參數:
17457
			#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
17458
			$conf["fileAccess::getFileContent"]["web"]="false";
17459
			#參考資料:
17460
			#file(),取得檔案內容的行數.
17461
			#file=>http:#php.net/manual/en/function.file.php
17462
			#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
17463
			#filesize=>http://php.net/manual/en/function.filesize.php
17464
			#參考資料:
17465
			#無.
17466
			#備註:
17467
			#無.
17468
			$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
17469
			unset($conf["fileAccess::getFileContent"]);
226 liveuser 17470
 
220 liveuser 17471
			#如果執行失敗
17472
			if($getFileContent["status"]==="false"){
226 liveuser 17473
 
220 liveuser 17474
				#設置執行失敗
17475
				$result["status"]="false";
226 liveuser 17476
 
220 liveuser 17477
				#設置執行失敗訊息
17478
				$result["error"]=$getFileContent;
226 liveuser 17479
 
220 liveuser 17480
				#回傳結果
17481
				return $result;
226 liveuser 17482
 
220 liveuser 17483
				}#if end
226 liveuser 17484
 
220 liveuser 17485
			#無窮迴圈
17486
			for($i=0;$i>=0;$i++){
226 liveuser 17487
 
220 liveuser 17488
				#如果有舊或新的行內容存在
17489
				if( isset($getFileContent["fileContent"][$i]) || isset($conf["overWriteWith"][$i]) ){
226 liveuser 17490
 
220 liveuser 17491
					#初始化暫存舊行內容的變數
17492
					$oriLine=null;
226 liveuser 17493
 
220 liveuser 17494
					#初始化暫存新行內容的變數
17495
					$newLine=null;
226 liveuser 17496
 
220 liveuser 17497
					#如果存在原行內容
17498
					if(isset($getFileContent["fileContent"][$i])){
226 liveuser 17499
 
220 liveuser 17500
						#儲存原行內容
17501
						$oriLine=$getFileContent["fileContent"][$i];
226 liveuser 17502
 
220 liveuser 17503
						}#if end
226 liveuser 17504
 
220 liveuser 17505
					#如果存在新行內容
17506
					if(isset($conf["overWriteWith"][$i])){
226 liveuser 17507
 
220 liveuser 17508
						#儲存新行內容
17509
						$newLine=$conf["overWriteWith"][$i];
226 liveuser 17510
 
220 liveuser 17511
						}#if end
226 liveuser 17512
 
220 liveuser 17513
					#設置更新的資訊
17514
					$result["content"][$i]=array("ori"=>$oriLine,"new"=>$newLine);
226 liveuser 17515
 
220 liveuser 17516
					}#if end
226 liveuser 17517
 
220 liveuser 17518
				#反之
17519
				else{
226 liveuser 17520
 
220 liveuser 17521
					#結束迴圈
17522
					break;
226 liveuser 17523
 
220 liveuser 17524
					}#else end
226 liveuser 17525
 
220 liveuser 17526
				}#for end
226 liveuser 17527
 
3 liveuser 17528
			}#if end
226 liveuser 17529
 
220 liveuser 17530
		#反之如果有設置 "replaceWith"
17531
		else if(isset($conf["replaceWith"])){
226 liveuser 17532
 
3 liveuser 17533
			#取得檔案的內容
17534
			#函式說明:
17535
			#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
17536
			#回傳的變數說明:
17537
			#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
17538
			#$result["error"],錯誤訊息提示.
17539
			#$result["warning"],警告訊息.
17540
			#$result["function"],當前執行的函數名稱.
17541
			#$result["fileContent"],爲檔案的內容陣列.
17542
			#$result["lineCount"],爲檔案內容總共的行數.
17543
			#$result["fullContent"],為檔案的完整內容.
17544
			#$result["base64data"],為檔案的base64內容.
17545
			#$result["mimeType"],為檔案的mime type.
17546
			#必填參數:
17547
			#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
17548
			$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["file"];
17549
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17550
			$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
17551
			#可省略參數:
17552
			#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
17553
			$conf["fileAccess::getFileContent"]["web"]="false";
17554
			#參考資料:
17555
			#file(),取得檔案內容的行數.
17556
			#file=>http:#php.net/manual/en/function.file.php
17557
			#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
17558
			#filesize=>http://php.net/manual/en/function.filesize.php
17559
			#參考資料:
17560
			#無.
17561
			#備註:
17562
			#無.
17563
			$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
17564
			unset($conf["fileAccess::getFileContent"]);
226 liveuser 17565
 
3 liveuser 17566
			#如果執行失敗
17567
			if($getFileContent["status"]==="false"){
226 liveuser 17568
 
3 liveuser 17569
				#設置執行失敗
17570
				$result["status"]="false";
226 liveuser 17571
 
3 liveuser 17572
				#設置執行失敗訊息
17573
				$result["error"]=$getFileContent;
226 liveuser 17574
 
3 liveuser 17575
				#回傳結果
17576
				return $result;
226 liveuser 17577
 
3 liveuser 17578
				}#if end
226 liveuser 17579
 
3 liveuser 17580
			#取得原始檔案的每行內容
17581
			$oriFileContentByLine=&$getFileContent["fileContent"];
226 liveuser 17582
 
3 liveuser 17583
			#針對每個 replaceWith 條件
17584
			foreach($conf["replaceWith"] as $replaceInfo){
226 liveuser 17585
 
3 liveuser 17586
				#預設尚未找到符合的關鍵字
17587
				$foundKeyWord=false;
226 liveuser 17588
 
3 liveuser 17589
				#取得要替換的目標字串
17590
				$oriStr=$replaceInfo[0];
226 liveuser 17591
 
3 liveuser 17592
				#取得要替換成的字串內容
17593
				$newStr=$replaceInfo[1];
226 liveuser 17594
 
3 liveuser 17595
				#針對每行原始內容
17596
				foreach($oriFileContentByLine as $index => $line){
226 liveuser 17597
 
3 liveuser 17598
					#函式說明:
17599
					#檢查字串裡面有無指定的關鍵字
17600
					#回傳結果:
17601
					#$result["status"],"true"代表執行成功,"false"代表執行失敗。
17602
					#$result["error"],錯誤訊息
17603
					#$result["function"],當前執行的函數名稱.
17604
					#$result["argu"],使用的參數.
17605
					#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
17606
					#$result["keyWordCount"],找到的關鍵字數量.
17607
					#必填參數:
17608
					#$conf["keyWord"],字串,想要搜尋的關鍵字.
17609
					$conf["search::findKeyWord"]["keyWord"]=$oriStr;
17610
					#$conf["string"],字串,要被搜尋的字串內容
17611
					$conf["search::findKeyWord"]["string"]=$line;
17612
					#可省略參數:
226 liveuser 17613
 
3 liveuser 17614
					#如果要完全符合關鍵字
17615
					if($conf["replaceLike"]==="false"){
226 liveuser 17616
 
3 liveuser 17617
						#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
17618
						$conf["search::findKeyWord"]["completeEqual"]="true";
226 liveuser 17619
 
3 liveuser 17620
						}#if end
226 liveuser 17621
 
3 liveuser 17622
					#參考資料:
17623
					#無.
17624
					#備註:
17625
					#無.
17626
					$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
17627
					unset($conf["search::findKeyWord"]);
226 liveuser 17628
 
3 liveuser 17629
					#如果執行失敗
17630
					if($findKeyWord["status"]==="false"){
226 liveuser 17631
 
3 liveuser 17632
						#設置執行失敗
17633
						$result["status"]="false";
226 liveuser 17634
 
3 liveuser 17635
						#設置執行失敗訊息
17636
						$result["error"]=$findKeyWord;
226 liveuser 17637
 
3 liveuser 17638
						#回傳結果
17639
						return $result;
226 liveuser 17640
 
3 liveuser 17641
						}#if end
226 liveuser 17642
 
3 liveuser 17643
					#如果有找到關鍵字
17644
					if($findKeyWord["founded"]==="true"){
226 liveuser 17645
 
220 liveuser 17646
						#設置更新的資訊
17647
						$result["content"][$lineIndex]=array("ori"=>$oriFileContentByLine[$index],"new"=>$newStr);
226 liveuser 17648
 
3 liveuser 17649
						#更新該行內容
17650
						$oriFileContentByLine[$index]=$newStr;
226 liveuser 17651
 
3 liveuser 17652
						#設置有找到符合的關鍵字
17653
						$foundKeyWord=true;
226 liveuser 17654
 
3 liveuser 17655
						}#if end
226 liveuser 17656
 
3 liveuser 17657
					}#foreach end
226 liveuser 17658
 
3 liveuser 17659
				#如果沒有找到關鍵字
17660
				if($foundKeyWord===false){
226 liveuser 17661
 
3 liveuser 17662
					#如果要新增內容
17663
					if($conf["addToTailWhenNoMatch"]==="true"){
226 liveuser 17664
 
3 liveuser 17665
						#如果有設置 addToTailBeforeThat
17666
						if(isset($conf["addToTailBeforeThat"])){
226 liveuser 17667
 
3 liveuser 17668
							#預設沒有找到符合的關鍵字
17669
							$foundKeyWord=false;
226 liveuser 17670
 
3 liveuser 17671
							#初始化要記錄要 append 回去的各行內容.
17672
							$linesToAppend=array();
226 liveuser 17673
 
3 liveuser 17674
							#倒敘,針對每行內容
17675
							for($i=count($oriFileContentByLine)-1;$i>=0;$i--){
226 liveuser 17676
 
3 liveuser 17677
								#儲存要 append 回去的行內容
17678
								$linesToAppend[]=$oriFileContentByLine[$i];
226 liveuser 17679
 
3 liveuser 17680
								#如果找到關鍵字了
17681
								if($oriFileContentByLine[$i]===$conf["addToTailBeforeThat"]){
226 liveuser 17682
 
3 liveuser 17683
									#設置有找到符合的關鍵字
17684
									$foundKeyWord=true;
226 liveuser 17685
 
220 liveuser 17686
									#設置更新的資訊
17687
									$result["content"][$lineIndex]=array("ori"=>$oriFileContentByLine[$i],"new"=>$line);
226 liveuser 17688
 
3 liveuser 17689
									#更新該行內容
17690
									$oriFileContentByLine[$i]=$line;
226 liveuser 17691
 
3 liveuser 17692
									#倒敘陣列
17693
									$linesToAppend=array_reverse($linesToAppend);
226 liveuser 17694
 
3 liveuser 17695
									#針對每行要 append 回去的內容
17696
									foreach($linesToAppend as $lineToAppend){
226 liveuser 17697
 
3 liveuser 17698
										#append 行內容
17699
										$oriFileContentByLine[]=$lineToAppend;
226 liveuser 17700
 
220 liveuser 17701
										#設置更新的資訊
17702
										$result["content"][count($oriFileContentByLine)-1]=array("ori"=>null,"new"=>$lineToAppend);
226 liveuser 17703
 
3 liveuser 17704
										}#foreach end
226 liveuser 17705
 
3 liveuser 17706
									}#if end
226 liveuser 17707
 
3 liveuser 17708
								}#for end
226 liveuser 17709
 
3 liveuser 17710
							#如果沒有找到關鍵字
17711
							if($foundKeyWord===false){
226 liveuser 17712
 
3 liveuser 17713
								#設置執行失敗
17714
								$result["status"]="false";
226 liveuser 17715
 
3 liveuser 17716
								#設置錯誤訊息
17717
								$result["error"]="can't find \"".$conf["addToTailBeforeThat"]."\" to insert before it.";
226 liveuser 17718
 
3 liveuser 17719
								#回傳結果
17720
								return $result;
226 liveuser 17721
 
3 liveuser 17722
								}#if end
226 liveuser 17723
 
3 liveuser 17724
							}#if end
226 liveuser 17725
 
3 liveuser 17726
						}#if end
226 liveuser 17727
 
3 liveuser 17728
					}#if end
226 liveuser 17729
 
3 liveuser 17730
				}#foreach end
226 liveuser 17731
 
3 liveuser 17732
			#函式說明:
17733
			#將多行字串寫入到檔案
17734
			#回傳結果:
17735
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
17736
			#$result["error"],錯誤訊息陣列.
17737
			#$result["function"],當前執行函數的名稱.
17738
			#必填參數:
17739
			#$conf["fileName"],字串,爲要編輯的檔案名稱
220 liveuser 17740
			$conf["fileAccess::writeMultiLine"]["fileName"]=$file2write;
3 liveuser 17741
			#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
17742
			$conf["fileAccess::writeMultiLine"]["inputString"]=$oriFileContentByLine;
17743
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17744
			$conf["fileAccess::writeMultiLine"]["fileArgu"]=$conf["fileArgu"];
17745
			#可省略參數:
17746
			#$conf["fileAccess::writeMultiLine"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
220 liveuser 17747
			#$conf["fastWrite"],字串,“true”代表要一次寫入多行內容;預設為"false"代表一次寫入一行,比較安全,但行數一多會需要等待多時.
17748
			$conf["fileAccess::writeMultiLine"]["fastWrite"]="true";
3 liveuser 17749
			#參考資料:
17750
			#無.
17751
			#備註:
17752
			#無.
17753
			$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
17754
			unset($conf["fileAccess::writeMultiLine"]);
226 liveuser 17755
 
3 liveuser 17756
			#如果執行失敗
17757
			if($writeMultiLine["status"]==="false"){
226 liveuser 17758
 
3 liveuser 17759
				#設置執行失敗
17760
				$result["status"]="false";
226 liveuser 17761
 
3 liveuser 17762
				#設置執行失敗訊息
17763
				$result["error"]=$writeMultiLine;
226 liveuser 17764
 
3 liveuser 17765
				#回傳結果
17766
				return $result;
226 liveuser 17767
 
3 liveuser 17768
				}#if end
226 liveuser 17769
 
3 liveuser 17770
			}#if end
226 liveuser 17771
 
220 liveuser 17772
		#反之如果有設置 replaceSpecifyLine
17773
		else if(isset($conf["replaceSpecifyLine"])){
226 liveuser 17774
 
220 liveuser 17775
			#讀取原始檔案內容
17776
			#函式說明:
17777
			#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
17778
			#回傳的變數說明:
17779
			#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
17780
			#$result["error"],錯誤訊息提示.
17781
			#$result["warning"],警告訊息.
17782
			#$result["function"],當前執行的函數名稱.
17783
			#$result["fileContent"],爲檔案的內容陣列.
17784
			#$result["lineCount"],爲檔案內容總共的行數.
17785
			#$result["fullContent"],為檔案的完整內容.
17786
			#$result["base64dataOnly"],檔案的base64data.
17787
			#$result["base64data"],為在網頁上給予src參數的數值.
17788
			#$result["mimeType"],為檔案的mime type.
17789
			#必填參數:
17790
			#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
17791
			$conf["fileAcceess::getFileContent"]["filePositionAndName"]=$conf["file"];
17792
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17793
			$conf["fileAcceess::getFileContent"]["fileArgu"]=__FILE__;
17794
			#可省略參數:
17795
			#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
17796
			#$conf["web"]="true";
17797
			#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
17798
			#$conf["createIfnotExist"]="false";
17799
			#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
17800
			#$conf["autoDeleteSpaceOnEachLineStart"]="false";
17801
			#參考資料:
17802
			#file(),取得檔案內容的行數.
17803
			#file=>http:#php.net/manual/en/function.file.php
17804
			#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
17805
			#filesize=>http://php.net/manual/en/function.filesize.php
17806
			#參考資料:
17807
			#無.
17808
			#備註:
17809
			#無.
17810
			$getFileContent=fileAccess::getFileContent($conf["fileAcceess::getFileContent"]);
17811
			unset($conf["fileAcceess::getFileContent"]);
226 liveuser 17812
 
220 liveuser 17813
			#如果執行失敗
17814
			if($getFileContent["status"]==="false"){
226 liveuser 17815
 
220 liveuser 17816
				#設置執行失敗
17817
				$result["status"]="false";
226 liveuser 17818
 
220 liveuser 17819
				#設置執行失敗訊息
17820
				$result["error"]=$getFileContent;
226 liveuser 17821
 
220 liveuser 17822
				#回傳結果
17823
				return $result;
226 liveuser 17824
 
220 liveuser 17825
				}#if end
226 liveuser 17826
 
220 liveuser 17827
			#針對每個要更新的行
17828
			foreach($conf["replaceSpecifyLine"] as $lineIndex => $newLineContent){
226 liveuser 17829
 
220 liveuser 17830
				#設置更新的資訊
17831
				$result["content"][$lineIndex]=array("ori"=>$getFileContent["fileContent"][$lineIndex],"new"=>$newLineContent);
226 liveuser 17832
 
220 liveuser 17833
				#更新行內容
17834
				$getFileContent["fileContent"][$lineIndex]=$newLineContent;
226 liveuser 17835
 
220 liveuser 17836
				}#foreach end
226 liveuser 17837
 
220 liveuser 17838
			#debug
17839
			#var_dump(__FILE__,__LINE__,count($getFileContent["fileContent"]));
226 liveuser 17840
 
220 liveuser 17841
			#將變更寫入到檔案裡面
17842
			#函式說明:
17843
			#將多行字串寫入到檔案
17844
			#回傳結果:
17845
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
17846
			#$result["error"],錯誤訊息陣列.
17847
			#$result["function"],當前執行函數的名稱.
17848
			#必填參數:
17849
			#$conf["fileName"],字串,爲要編輯的檔案名稱
17850
			$conf["fileAccess::writeMultiLine"]["fileName"]=$file2write;
17851
			#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
17852
			$conf["fileAccess::writeMultiLine"]["inputString"]=$getFileContent["fileContent"];
17853
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17854
			$conf["fileAccess::writeMultiLine"]["fileArgu"]=__FILE__;
17855
			#可省略參數:
17856
			$conf["fileAccess::writeMultiLine"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
17857
			#$conf["fastWrite"],字串,“true”代表要一次寫入多行內容;預設為"false"代表一次寫入一行,比較安全,但行數一多會需要等待多時.
17858
			$conf["fileAccess::writeMultiLine"]["fastWrite"]="true";
17859
			#參考資料:
17860
			#無.
17861
			#備註:
17862
			#無.
17863
			$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
17864
			unset($conf["fileAccess::writeMultiLine"]);
226 liveuser 17865
 
220 liveuser 17866
			#如果執行失敗
17867
			if($writeMultiLine["status"]==="false"){
226 liveuser 17868
 
220 liveuser 17869
				#設置執行失敗
17870
				$result["status"]="false";
226 liveuser 17871
 
220 liveuser 17872
				#設置執行失敗訊息
17873
				$result["error"]=$writeMultiLine;
226 liveuser 17874
 
220 liveuser 17875
				#回傳結果
17876
				return $result;
226 liveuser 17877
 
220 liveuser 17878
				}#if end
226 liveuser 17879
 
220 liveuser 17880
			#debug
17881
			#var_dump(__FILE__,__LINE__,$writeMultiLine);exit(1);
226 liveuser 17882
 
220 liveuser 17883
			}#if end
226 liveuser 17884
 
3 liveuser 17885
		#設置執行正常
17886
		$result["status"]="true";
226 liveuser 17887
 
3 liveuser 17888
		#回傳結果
17889
		return $result;
226 liveuser 17890
 
3 liveuser 17891
		}#function updateFile end
226 liveuser 17892
 
3 liveuser 17893
	/*
17894
	#函式說明:
17895
	#輔助使用PHP內建的chmod函式.
17896
	#回傳結果:
17897
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17898
	#$result["error"],錯誤訊息.
17899
	#$result["function"],當前執行的函式名稱.
17900
	#$result["argu"],使用的參數.
17901
	#$result["cmd"],執行的指令.
17902
	#$result["content"],執行的結果陣列,如果參數 "recursive" 跟 "excludeSelf" 都有設定的話,就會回傳該結果.
17903
	#必填參數:
17904
	#$conf["mode"],字串,要變成什麼權限.
17905
	$conf["mode"]="";
17906
	#$conf["target"],字串,需要變更權限的目標.
17907
	$conf["target"]="";
17908
	#可省略參數:
17909
	#無.
17910
	#參考資料:
17911
	#無.
17912
	#備註:
17913
	#無.
17914
	*/
17915
	public static function chmod(&$conf){
226 liveuser 17916
 
3 liveuser 17917
		#初始化要回傳的結果
17918
		$result=array();
17919
 
17920
		#取得當前執行的函數名稱
17921
		$result["function"]=__FUNCTION__;
17922
 
17923
		#如果沒有參數
17924
		if(func_num_args()==0){
17925
 
17926
			#設置執行失敗
17927
			$result["status"]="false";
17928
 
17929
			#設置執行錯誤訊息
17930
			$result["error"]="函數".$result["function"]."需要參數";
17931
 
17932
			#回傳結果
17933
			return $result;
17934
 
17935
			}#if end
17936
 
17937
		#取得參數
17938
		$result["argu"]=$conf;
17939
 
17940
		#如果 $conf 不為陣列
17941
		if(gettype($conf)!=="array"){
17942
 
17943
			#設置執行失敗
17944
			$result["status"]="false";
17945
 
17946
			#設置執行錯誤訊息
17947
			$result["error"][]="\$conf變數須為陣列形態";
17948
 
17949
			#如果傳入的參數為 null
17950
			if(is_null($conf)){
17951
 
17952
				#設置執行錯誤訊息
17953
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
17954
 
17955
				}#if end
17956
 
17957
			#回傳結果
17958
			return $result;
17959
 
17960
			}#if end
226 liveuser 17961
 
3 liveuser 17962
		#函式說明:
17963
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
17964
		#回傳結果:
17965
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17966
		#$result["error"],執行不正常結束的錯訊息陣列.
17967
		#$result["simpleError"],簡單表示的錯誤訊息.
17968
		#$result["function"],當前執行的函式名稱.
17969
		#$result["argu"],設置給予的參數.
17970
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
17971
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
17972
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
17973
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
17974
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
17975
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
17976
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
17977
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
17978
		#必填參數:
17979
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
17980
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
17981
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
17982
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
17983
		#可省略參數:
17984
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
17985
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("mode","target");
17986
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
17987
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
17988
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
17989
		#$conf["canBeEmptyString"]="false";
17990
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
17991
		#$conf["canNotBeEmpty"]=array();
17992
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
17993
		#$conf["canBeEmpty"]=array();
17994
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
17995
		#$conf["skipableVariableCanNotBeEmpty"]=array();
17996
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
17997
		#$conf["skipableVariableName"]=array();
17998
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
17999
		#$conf["skipableVariableType"]=array();
18000
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
18001
		#$conf["skipableVarDefaultValue"]=array("");
18002
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
18003
		#$conf["disallowAllSkipableVarIsEmpty"]="";
18004
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
18005
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
18006
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
18007
		#$conf["arrayCountEqualCheck"][]=array();
18008
		#參考資料:
18009
		#array_keys=>http://php.net/manual/en/function.array-keys.php
18010
		#備註:
18011
		#無.
18012
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
18013
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 18014
 
3 liveuser 18015
		#如果檢查參數失敗
18016
		if($checkArguments["status"]==="false"){
226 liveuser 18017
 
3 liveuser 18018
			#設置執行失敗
18019
			$result["status"]="false";
18020
 
18021
			#設置錯誤資訊
18022
			$result["error"]=$checkArguments;
226 liveuser 18023
 
3 liveuser 18024
			#回傳結果
18025
			return $result;
226 liveuser 18026
 
3 liveuser 18027
			}#if end
226 liveuser 18028
 
3 liveuser 18029
		#如果檢查參數不通過
18030
		if($checkArguments["passed"]==="false"){
226 liveuser 18031
 
3 liveuser 18032
			#設置執行失敗
18033
			$result["status"]="false";
18034
 
18035
			#設置錯誤資訊
18036
			$result["error"]=$checkArguments;
226 liveuser 18037
 
3 liveuser 18038
			#回傳結果
18039
			return $result;
226 liveuser 18040
 
3 liveuser 18041
			}#if end
226 liveuser 18042
 
3 liveuser 18043
		#將$conf["mode"]轉換為10進位的整數
18044
		$conf["mode"]=(int)base_convert($conf["mode"],8,10);
226 liveuser 18045
 
3 liveuser 18046
		#變更 target 的檔案權限為代碼
226 liveuser 18047
		$chmod=chmod($conf["target"],$conf["mode"]);
18048
 
3 liveuser 18049
		#如果改變檔案權限失敗
18050
		if($chmod===false){
226 liveuser 18051
 
3 liveuser 18052
			#設置執行失敗
18053
			$result["status"]="false";
226 liveuser 18054
 
3 liveuser 18055
			#設置錯誤訊息
18056
			$result["error"][]="改變 ".$conf["target"]." 檔案的權限資訊為 ".$conf["mode"]." 失敗,通常只有系統帳戶才能變更之.";
226 liveuser 18057
 
3 liveuser 18058
			#回傳結果
226 liveuser 18059
			return $result;
18060
 
3 liveuser 18061
			}#if end
226 liveuser 18062
 
3 liveuser 18063
		#設置執行正常
18064
		$result["status"]="true";
226 liveuser 18065
 
3 liveuser 18066
		#回傳結果
18067
		return $result;
226 liveuser 18068
 
3 liveuser 18069
		}#function chmod end
18070
 
18071
	}#class fileAccess end
18072
 
226 liveuser 18073
?>