| 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 |
*/
|
| 249 |
liveuser |
1191 |
public static function getFileContent(&$conf){
|
| 3 |
liveuser |
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 |
*/
|
| 249 |
liveuser |
1599 |
public static function getFileContentSpiltBySomething(&$conf){
|
| 3 |
liveuser |
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 |
#函式說明:
|
| 253 |
liveuser |
11168 |
#複製檔案、資料夾,只要符合權限就會執行並覆蓋既有內容.
|
|
|
11169 |
#回傳結果:
|
|
|
11170 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
11171 |
#$result["error"],錯誤訊息.
|
|
|
11172 |
#$result["function"],當前執行的函式名稱.
|
|
|
11173 |
#$result["content"],複製好的檔案路徑與名稱.
|
|
|
11174 |
#必填參數:
|
|
|
11175 |
#$conf["file"],字串,檔案的位置與名稱.
|
|
|
11176 |
$conf["file"]="";
|
|
|
11177 |
#$conf["to"],字串,檔案要複製到哪裡.
|
|
|
11178 |
$conf["to"]="";
|
|
|
11179 |
#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
|
|
|
11180 |
$conf["fileArgu"]=__FILE__;
|
|
|
11181 |
#可省略參數:
|
|
|
11182 |
#無.
|
|
|
11183 |
#參考資料:
|
|
|
11184 |
#無.
|
|
|
11185 |
#備註:
|
|
|
11186 |
#等同於cmd::cp的應用.
|
|
|
11187 |
*/
|
|
|
11188 |
public static function cp(&$conf){
|
|
|
11189 |
|
|
|
11190 |
#初始化要回傳的結果
|
|
|
11191 |
$result=array();
|
|
|
11192 |
|
|
|
11193 |
#取得當前執行的函式名稱
|
|
|
11194 |
$result["function"]=__FUNCTION__;
|
|
|
11195 |
|
|
|
11196 |
#如果沒有參數
|
|
|
11197 |
if(func_num_args()==0){
|
|
|
11198 |
|
|
|
11199 |
#設置執行失敗
|
|
|
11200 |
$result["status"]="false";
|
|
|
11201 |
|
|
|
11202 |
#設置執行錯誤訊息
|
|
|
11203 |
$result["error"]="函式".$result["function"]."需要參數";
|
|
|
11204 |
|
|
|
11205 |
#回傳結果
|
|
|
11206 |
return $result;
|
|
|
11207 |
|
|
|
11208 |
}#if end
|
|
|
11209 |
|
|
|
11210 |
#取得參數
|
|
|
11211 |
$result["argu"]=$conf;
|
|
|
11212 |
|
|
|
11213 |
#如果 $conf 不為陣列
|
|
|
11214 |
if(gettype($conf)!=="array"){
|
|
|
11215 |
|
|
|
11216 |
#設置執行失敗
|
|
|
11217 |
$result["status"]="false";
|
|
|
11218 |
|
|
|
11219 |
#設置執行錯誤訊息
|
|
|
11220 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
11221 |
|
|
|
11222 |
#如果傳入的參數為 null
|
|
|
11223 |
if($conf===null){
|
|
|
11224 |
|
|
|
11225 |
#設置執行錯誤訊息
|
|
|
11226 |
$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
|
|
|
11227 |
|
|
|
11228 |
}#if end
|
|
|
11229 |
|
|
|
11230 |
#回傳結果
|
|
|
11231 |
return $result;
|
|
|
11232 |
|
|
|
11233 |
}#if end
|
|
|
11234 |
|
|
|
11235 |
#檢查參數
|
|
|
11236 |
#函式說明:
|
|
|
11237 |
#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
11238 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
11239 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
11240 |
#$result["function"],當前執行的函式名稱.
|
|
|
11241 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
11242 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
11243 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
11244 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
11245 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
11246 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
11247 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
11248 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
11249 |
#必填寫的參數:
|
|
|
11250 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
11251 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
11252 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
11253 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","to","fileArgu");
|
|
|
11254 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
11255 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
11256 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
11257 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
11258 |
#可以省略的參數:
|
|
|
11259 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
11260 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
11261 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
11262 |
#$conf["canNotBeEmpty"]=array();
|
|
|
11263 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
11264 |
#$conf["canBeEmpty"]=array();
|
|
|
11265 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
11266 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
11267 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
11268 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","cmdOnly");
|
|
|
11269 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
11270 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
11271 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
11272 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["LOGNAME"],null,"true");
|
|
|
11273 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
11274 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
11275 |
#參考資料來源:
|
|
|
11276 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
11277 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
11278 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
11279 |
|
|
|
11280 |
#如果參數檢查失敗
|
|
|
11281 |
if($checkArguments["status"]==="false"){
|
|
|
11282 |
|
|
|
11283 |
#設置執行不正常
|
|
|
11284 |
$result["status"]="false";
|
|
|
11285 |
|
|
|
11286 |
#設置執行錯誤
|
|
|
11287 |
$result["error"]=$checkArguments;
|
|
|
11288 |
|
|
|
11289 |
#回傳結果
|
|
|
11290 |
return $result;
|
|
|
11291 |
|
|
|
11292 |
}#if end
|
|
|
11293 |
|
|
|
11294 |
#如果參數檢查不通過
|
|
|
11295 |
if($checkArguments["passed"]==="false"){
|
|
|
11296 |
|
|
|
11297 |
#設置執行不正常
|
|
|
11298 |
$result["status"]="false";
|
|
|
11299 |
|
|
|
11300 |
#設置執行錯誤
|
|
|
11301 |
$result["error"]=$checkArguments;
|
|
|
11302 |
|
|
|
11303 |
#回傳結果
|
|
|
11304 |
return $result;
|
|
|
11305 |
|
|
|
11306 |
}#if end
|
|
|
11307 |
|
|
|
11308 |
#函式說明:
|
|
|
11309 |
#複製檔案、資料夾,只要符合權限就會執行並覆蓋既有內容.
|
|
|
11310 |
#回傳結果:
|
|
|
11311 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
11312 |
#$result["error"],錯誤訊息.
|
|
|
11313 |
#$result["function"],當前執行的函式名稱.
|
|
|
11314 |
#$result["content"],複製好的檔案路徑與名稱.
|
|
|
11315 |
#必填參數:
|
|
|
11316 |
#$conf["file"],字串,檔案的位置與名稱.
|
|
|
11317 |
$conf["cmd::cp"]["file"]=$conf["file"];
|
|
|
11318 |
#$conf["to"],字串,檔案要複製到哪裡.
|
|
|
11319 |
$conf["cmd::cp"]["to"]=$conf["to"];
|
|
|
11320 |
#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
|
|
|
11321 |
$conf["cmd::cp"]["fileArgu"]=$conf["fileArgu"];
|
|
|
11322 |
#可省略參數:
|
|
|
11323 |
#$conf["cmdOnly"],字串,是否要只允許在cmd環境下運行,預設為"true",代表是;"false"代表沒有限制.
|
|
|
11324 |
$conf["cmd::cp"]["cmdOnly"]="false";
|
|
|
11325 |
#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
|
|
|
11326 |
#$conf["username"]="";
|
|
|
11327 |
#$conf["password"],字串,使用者對應的密碼,預設不使用.
|
|
|
11328 |
#$conf["password"]="";
|
|
|
11329 |
#參考資料:
|
|
|
11330 |
#無.
|
|
|
11331 |
#備註:
|
|
|
11332 |
#無.
|
|
|
11333 |
$cp=cmd::cp($conf["cmd::cp"]);
|
|
|
11334 |
unset($conf["cmd::cp"]);
|
|
|
11335 |
|
|
|
11336 |
#如果執行異常
|
|
|
11337 |
if($cp["status"]==="false"){
|
|
|
11338 |
|
|
|
11339 |
#設置執行不正常
|
|
|
11340 |
$result["status"]="false";
|
|
|
11341 |
|
|
|
11342 |
#設置執行錯誤
|
|
|
11343 |
$result["error"]=$cp;
|
|
|
11344 |
|
|
|
11345 |
#回傳結果
|
|
|
11346 |
return $result;
|
|
|
11347 |
|
|
|
11348 |
}#if end
|
|
|
11349 |
|
|
|
11350 |
#設置要回傳的 content
|
|
|
11351 |
$result["content"]=$cp["content"];
|
|
|
11352 |
|
|
|
11353 |
#設置執行正常
|
|
|
11354 |
$result["status"]="true";
|
|
|
11355 |
|
|
|
11356 |
#回傳結果
|
|
|
11357 |
return $result;
|
|
|
11358 |
|
|
|
11359 |
}#function cp end
|
|
|
11360 |
|
|
|
11361 |
/*
|
|
|
11362 |
#函式說明:
|
| 3 |
liveuser |
11363 |
#分割檔案,分割出來的檔案名稱編號為aa, ab ac...ba, bb, bc...,zx, zy, zz的順序.
|
|
|
11364 |
#回傳結果:
|
|
|
11365 |
#$result["status"],"true"代表移除成功,"false"代表移除失敗.
|
|
|
11366 |
#$result["error"],錯誤訊息陣列.
|
|
|
11367 |
#$result["function"],當前執行的函數名稱.
|
|
|
11368 |
#$result["cmd"],執行的指令.
|
|
|
11369 |
#$result["content"],執行指令回傳的結果.
|
|
|
11370 |
#必填參數:
|
|
|
11371 |
#$conf["file"],字串,要分割的檔案名稱.
|
| 226 |
liveuser |
11372 |
$conf["file"]="";
|
| 3 |
liveuser |
11373 |
#可省略參數:
|
|
|
11374 |
#$conf["splitNameHead"],字串,分割成檔案的名稱開頭,預設為 $conf["file"]."-" .
|
| 226 |
liveuser |
11375 |
#$conf["splitNameHead"]="";
|
| 3 |
liveuser |
11376 |
#$conf["partSize"],字串,分割檔的大小為多少?可以為XMB,XGB,XKB,可參見split指令的說明,預設為50MB.
|
|
|
11377 |
#$conf["partSize"]="";
|
|
|
11378 |
#參考資料:
|
|
|
11379 |
#無.
|
|
|
11380 |
#備註:
|
|
|
11381 |
#需要有split指令
|
|
|
11382 |
*/
|
|
|
11383 |
public static function split(&$conf=array()){
|
| 226 |
liveuser |
11384 |
|
| 3 |
liveuser |
11385 |
#初始化要回傳的結果
|
|
|
11386 |
$result=array();
|
|
|
11387 |
|
|
|
11388 |
#取得當前執行的函數名稱
|
|
|
11389 |
$result["function"]=__FUNCTION__;
|
|
|
11390 |
|
|
|
11391 |
#如果沒有參數
|
|
|
11392 |
if(func_num_args()==0){
|
| 226 |
liveuser |
11393 |
|
| 3 |
liveuser |
11394 |
#設置執行失敗
|
|
|
11395 |
$result["status"]="false";
|
| 226 |
liveuser |
11396 |
|
| 3 |
liveuser |
11397 |
#設置執行錯誤訊息
|
|
|
11398 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
11399 |
|
| 3 |
liveuser |
11400 |
#回傳結果
|
|
|
11401 |
return $result;
|
| 226 |
liveuser |
11402 |
|
| 3 |
liveuser |
11403 |
}#if end
|
|
|
11404 |
|
|
|
11405 |
#函式說明:
|
|
|
11406 |
#判斷當前環境為web還是cmd
|
|
|
11407 |
#回傳結果:
|
|
|
11408 |
#$result,"web"或"cmd"
|
|
|
11409 |
if(csInformation::getEnv()==="web"){
|
| 226 |
liveuser |
11410 |
|
| 3 |
liveuser |
11411 |
#設置執行失敗
|
|
|
11412 |
$result["status"]="false";
|
| 226 |
liveuser |
11413 |
|
| 3 |
liveuser |
11414 |
#設置執行錯誤訊息
|
|
|
11415 |
$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
|
| 226 |
liveuser |
11416 |
|
| 3 |
liveuser |
11417 |
#回傳結果
|
|
|
11418 |
return $result;
|
| 226 |
liveuser |
11419 |
|
| 3 |
liveuser |
11420 |
}#if end
|
| 226 |
liveuser |
11421 |
|
| 3 |
liveuser |
11422 |
#取得參數
|
|
|
11423 |
$result["argu"]=$conf;
|
|
|
11424 |
|
|
|
11425 |
#如果 $conf 不為陣列
|
|
|
11426 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
11427 |
|
| 3 |
liveuser |
11428 |
#設置執行失敗
|
|
|
11429 |
$result["status"]="false";
|
| 226 |
liveuser |
11430 |
|
| 3 |
liveuser |
11431 |
#設置執行錯誤訊息
|
|
|
11432 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
11433 |
|
| 3 |
liveuser |
11434 |
#如果傳入的參數為 null
|
|
|
11435 |
if($conf===null){
|
| 226 |
liveuser |
11436 |
|
| 3 |
liveuser |
11437 |
#設置執行錯誤訊息
|
|
|
11438 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
11439 |
|
| 3 |
liveuser |
11440 |
}#if end
|
|
|
11441 |
|
|
|
11442 |
#回傳結果
|
|
|
11443 |
return $result;
|
| 226 |
liveuser |
11444 |
|
| 3 |
liveuser |
11445 |
}#if end
|
| 226 |
liveuser |
11446 |
|
| 3 |
liveuser |
11447 |
#檢查參數
|
|
|
11448 |
#函式說明:
|
|
|
11449 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
11450 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
11451 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
11452 |
#$result["function"],當前執行的函式名稱.
|
|
|
11453 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
11454 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
11455 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
11456 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
11457 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
11458 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
11459 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
11460 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
11461 |
#必填寫的參數:
|
|
|
11462 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
11463 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
11464 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
11465 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file");
|
|
|
11466 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
11467 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
11468 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
11469 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
11470 |
#可以省略的參數:
|
|
|
11471 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
11472 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
11473 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
11474 |
#$conf["canNotBeEmpty"]=array();
|
|
|
11475 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
11476 |
#$conf["canBeEmpty"]=array();
|
|
|
11477 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
11478 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
11479 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
11480 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("splitNameHead","partSize");
|
| 226 |
liveuser |
11481 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
11482 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
11483 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]",若後面需要加上內容,則可以再補上\",後面再補上要串接的內容.
|
|
|
11484 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("\$conf[\"file\"]\"-","50MB");
|
|
|
11485 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
11486 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
11487 |
#參考資料來源:
|
|
|
11488 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
11489 |
#建議:
|
|
|
11490 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
11491 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
11492 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
11493 |
|
| 3 |
liveuser |
11494 |
#如果檢查參數失敗
|
|
|
11495 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
11496 |
|
| 3 |
liveuser |
11497 |
#設置執行失敗
|
|
|
11498 |
$result["status"]="false";
|
| 226 |
liveuser |
11499 |
|
| 3 |
liveuser |
11500 |
#設置錯誤訊息
|
|
|
11501 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
11502 |
|
| 3 |
liveuser |
11503 |
#回傳結果
|
|
|
11504 |
return $result;
|
| 226 |
liveuser |
11505 |
|
| 3 |
liveuser |
11506 |
}#if end
|
| 226 |
liveuser |
11507 |
|
| 3 |
liveuser |
11508 |
#如果要分割的檔案存在
|
|
|
11509 |
if(file_exists($conf["file"])){
|
| 226 |
liveuser |
11510 |
|
| 3 |
liveuser |
11511 |
#取得執行的指令
|
|
|
11512 |
$result["cmd"]="split -b ".$conf["partSize"]." '".$conf["file"]."' '".$conf["splitNameHead"]."'";
|
|
|
11513 |
|
|
|
11514 |
#執行還原的指令
|
|
|
11515 |
exec($result["cmd"],$output,$status);
|
|
|
11516 |
|
|
|
11517 |
#取得執行後的輸出
|
|
|
11518 |
$result["content"]=$output;
|
| 226 |
liveuser |
11519 |
|
| 3 |
liveuser |
11520 |
}#if end
|
| 226 |
liveuser |
11521 |
|
| 3 |
liveuser |
11522 |
#反之
|
|
|
11523 |
else{
|
| 226 |
liveuser |
11524 |
|
| 3 |
liveuser |
11525 |
#設置執行失敗
|
|
|
11526 |
$result["status"]="false";
|
| 226 |
liveuser |
11527 |
|
| 3 |
liveuser |
11528 |
#設置執行錯誤訊息
|
|
|
11529 |
$result["error"][]="要分割的檔案「".$conf["file"]."」不存在";
|
| 226 |
liveuser |
11530 |
|
| 3 |
liveuser |
11531 |
#回傳結果
|
|
|
11532 |
return $result;
|
| 226 |
liveuser |
11533 |
|
| 3 |
liveuser |
11534 |
}#else end
|
| 226 |
liveuser |
11535 |
|
| 3 |
liveuser |
11536 |
#設置執行正常
|
|
|
11537 |
$result["status"]="true";
|
| 226 |
liveuser |
11538 |
|
| 3 |
liveuser |
11539 |
#回傳結果
|
|
|
11540 |
return $result;
|
| 226 |
liveuser |
11541 |
|
| 3 |
liveuser |
11542 |
}#function split end
|
|
|
11543 |
|
|
|
11544 |
/*
|
|
|
11545 |
#函式說明:
|
|
|
11546 |
#合併檔案,檔案編號為aa, ab ac...ba, bb, bc...,zx, zy, zz的順序.
|
|
|
11547 |
#回傳結果:
|
|
|
11548 |
#$result["status"],"true"代表移除成功,"false"代表移除失敗.
|
|
|
11549 |
#$result["error"],錯誤訊息陣列.
|
|
|
11550 |
#$result["function"],當前執行的函數名稱.
|
|
|
11551 |
#$result["cmd"],執行的指令.
|
|
|
11552 |
#$result["content"],執行指令回傳的結果.
|
|
|
11553 |
#必填參數:
|
|
|
11554 |
#$conf["filePartHead"],字串,分割檔案的名稱開頭.
|
|
|
11555 |
$conf["filePartHead"]="";
|
|
|
11556 |
#$conf["oriFileName"],字串,合併後的檔案名稱.
|
|
|
11557 |
$conf["oriFileName"]="";
|
|
|
11558 |
#可省略參數:
|
|
|
11559 |
#無
|
|
|
11560 |
#參考資料:
|
|
|
11561 |
#無.
|
|
|
11562 |
#備註:
|
|
|
11563 |
#需要有cat指令.
|
|
|
11564 |
#僅能在命令列執行.
|
|
|
11565 |
*/
|
|
|
11566 |
public static function merge(&$conf=array()){
|
| 226 |
liveuser |
11567 |
|
| 3 |
liveuser |
11568 |
#初始化要回傳的結果
|
|
|
11569 |
$result=array();
|
|
|
11570 |
|
|
|
11571 |
#取得當前執行的函數名稱
|
|
|
11572 |
$result["function"]=__FUNCTION__;
|
|
|
11573 |
|
|
|
11574 |
#如果沒有參數
|
|
|
11575 |
if(func_num_args()==0){
|
| 226 |
liveuser |
11576 |
|
| 3 |
liveuser |
11577 |
#設置執行失敗
|
|
|
11578 |
$result["status"]="false";
|
| 226 |
liveuser |
11579 |
|
| 3 |
liveuser |
11580 |
#設置執行錯誤訊息
|
|
|
11581 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
11582 |
|
| 3 |
liveuser |
11583 |
#回傳結果
|
|
|
11584 |
return $result;
|
| 226 |
liveuser |
11585 |
|
| 3 |
liveuser |
11586 |
}#if end
|
|
|
11587 |
|
|
|
11588 |
#函式說明:
|
|
|
11589 |
#判斷當前環境為web還是cmd
|
|
|
11590 |
#回傳結果:
|
|
|
11591 |
#$result,"web"或"cmd"
|
|
|
11592 |
if(csInformation::getEnv()==="web"){
|
| 226 |
liveuser |
11593 |
|
| 3 |
liveuser |
11594 |
#設置執行失敗
|
|
|
11595 |
$result["status"]="false";
|
| 226 |
liveuser |
11596 |
|
| 3 |
liveuser |
11597 |
#設置執行錯誤訊息
|
|
|
11598 |
$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
|
| 226 |
liveuser |
11599 |
|
| 3 |
liveuser |
11600 |
#回傳結果
|
|
|
11601 |
return $result;
|
| 226 |
liveuser |
11602 |
|
| 3 |
liveuser |
11603 |
}#if end
|
| 226 |
liveuser |
11604 |
|
| 3 |
liveuser |
11605 |
#取得參數
|
|
|
11606 |
$result["argu"]=$conf;
|
|
|
11607 |
|
|
|
11608 |
#如果 $conf 不為陣列
|
|
|
11609 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
11610 |
|
| 3 |
liveuser |
11611 |
#設置執行失敗
|
|
|
11612 |
$result["status"]="false";
|
| 226 |
liveuser |
11613 |
|
| 3 |
liveuser |
11614 |
#設置執行錯誤訊息
|
|
|
11615 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
11616 |
|
| 3 |
liveuser |
11617 |
#如果傳入的參數為 null
|
|
|
11618 |
if($conf===null){
|
| 226 |
liveuser |
11619 |
|
| 3 |
liveuser |
11620 |
#設置執行錯誤訊息
|
|
|
11621 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
11622 |
|
| 3 |
liveuser |
11623 |
}#if end
|
|
|
11624 |
|
|
|
11625 |
#回傳結果
|
|
|
11626 |
return $result;
|
| 226 |
liveuser |
11627 |
|
| 3 |
liveuser |
11628 |
}#if end
|
| 226 |
liveuser |
11629 |
|
| 3 |
liveuser |
11630 |
#檢查參數
|
|
|
11631 |
#函式說明:
|
|
|
11632 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
11633 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
11634 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
11635 |
#$result["function"],當前執行的函式名稱.
|
|
|
11636 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
11637 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
11638 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
11639 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
11640 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
11641 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
11642 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
11643 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
11644 |
#必填寫的參數:
|
|
|
11645 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
11646 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
11647 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
11648 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePartHead","oriFileName");
|
|
|
11649 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
11650 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
11651 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
11652 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
11653 |
#可以省略的參數:
|
|
|
11654 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
11655 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
11656 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
11657 |
#$conf["canNotBeEmpty"]=array();
|
|
|
11658 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
11659 |
#$conf["canBeEmpty"]=array();
|
|
|
11660 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
11661 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
11662 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
11663 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
11664 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
11665 |
#$conf["skipableVariableType"]=array();
|
|
|
11666 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
11667 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
11668 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
11669 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
11670 |
#參考資料來源:
|
|
|
11671 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
11672 |
#建議:
|
|
|
11673 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
11674 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
11675 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
11676 |
|
| 3 |
liveuser |
11677 |
#如果檢查參數失敗
|
|
|
11678 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
11679 |
|
| 3 |
liveuser |
11680 |
#設置執行失敗
|
|
|
11681 |
$result["status"]="false";
|
| 226 |
liveuser |
11682 |
|
| 3 |
liveuser |
11683 |
#設置錯誤訊息
|
|
|
11684 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
11685 |
|
| 3 |
liveuser |
11686 |
#回傳結果
|
|
|
11687 |
return $result;
|
| 226 |
liveuser |
11688 |
|
| 3 |
liveuser |
11689 |
}#if end
|
| 226 |
liveuser |
11690 |
|
| 3 |
liveuser |
11691 |
#定義編號
|
|
|
11692 |
$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");
|
|
|
11693 |
|
|
|
11694 |
#定義分割檔案的前置字串
|
|
|
11695 |
$filePartHead=$conf["filePartHead"];
|
|
|
11696 |
|
|
|
11697 |
#要合併成的檔案名稱
|
|
|
11698 |
$oriFileName=$conf["oriFileName"];
|
|
|
11699 |
|
|
|
11700 |
#初始化要執行合併的語法
|
|
|
11701 |
$restoreCmd="cat ";
|
|
|
11702 |
|
|
|
11703 |
#有幾個編號就執行幾次
|
|
|
11704 |
for($i=0;$i<count($charArray);$i++){
|
|
|
11705 |
|
|
|
11706 |
#有幾個編號就執行幾次
|
|
|
11707 |
for($j=0;$j<count($charArray);$j++){
|
|
|
11708 |
|
|
|
11709 |
#如果該分割檔存在
|
|
|
11710 |
if(file_exists($filePartHead.$charArray[$i].$charArray[$j])){
|
|
|
11711 |
|
|
|
11712 |
#串接要還原的分割檔
|
|
|
11713 |
$restoreCmd=$restoreCmd." '".$filePartHead.$charArray[$i].$charArray[$j]."'";
|
|
|
11714 |
|
|
|
11715 |
}#if end
|
|
|
11716 |
|
|
|
11717 |
#反之
|
|
|
11718 |
else{
|
|
|
11719 |
|
|
|
11720 |
#如果是第一個分割檔就找不到
|
|
|
11721 |
if($i===0 && $j===0){
|
| 226 |
liveuser |
11722 |
|
| 3 |
liveuser |
11723 |
#設置執行失敗
|
|
|
11724 |
$result["status"]="false";
|
| 226 |
liveuser |
11725 |
|
| 3 |
liveuser |
11726 |
#設置錯誤訊息
|
|
|
11727 |
$result["error"][]="找不到第一個分割檔「".$filePartHead.$charArray[$i].$charArray[$j]."」";
|
| 226 |
liveuser |
11728 |
|
| 3 |
liveuser |
11729 |
#回傳結果
|
|
|
11730 |
return $result;
|
| 226 |
liveuser |
11731 |
|
| 3 |
liveuser |
11732 |
}#if end
|
|
|
11733 |
|
|
|
11734 |
#串接要還原成的檔案名稱
|
|
|
11735 |
$restoreCmd=$restoreCmd." > '".$oriFileName."'";
|
|
|
11736 |
|
|
|
11737 |
#取得執行的指令
|
|
|
11738 |
$result["cmd"]=$restoreCmd;
|
|
|
11739 |
|
|
|
11740 |
#執行還原的指令
|
|
|
11741 |
exec($restoreCmd,$output,$status);
|
|
|
11742 |
|
|
|
11743 |
#取得執行後的輸出
|
|
|
11744 |
$result["content"]=$output;
|
|
|
11745 |
|
|
|
11746 |
#結束回圈
|
|
|
11747 |
break 2;
|
| 226 |
liveuser |
11748 |
|
| 3 |
liveuser |
11749 |
}#else end
|
|
|
11750 |
|
|
|
11751 |
}#for end
|
|
|
11752 |
|
|
|
11753 |
}#for end
|
| 226 |
liveuser |
11754 |
|
| 3 |
liveuser |
11755 |
#設置執行正常
|
|
|
11756 |
$result["status"]="true";
|
| 226 |
liveuser |
11757 |
|
| 3 |
liveuser |
11758 |
#回傳結果
|
|
|
11759 |
return $result;
|
| 226 |
liveuser |
11760 |
|
| 3 |
liveuser |
11761 |
}#function merge end
|
|
|
11762 |
|
|
|
11763 |
/*
|
|
|
11764 |
#函式說明:
|
|
|
11765 |
#取得檔案的部分內容
|
|
|
11766 |
#回傳結果:
|
|
|
11767 |
#$result["status"],"true"代表移除成功,"false"代表移除失敗.
|
|
|
11768 |
#$result["error"],錯誤訊息陣列.
|
|
|
11769 |
#$result["function"],當前執行的函數名稱.
|
|
|
11770 |
#$result["cmd"],執行的指令.
|
|
|
11771 |
#$result["content"],取得的檔案內容.
|
|
|
11772 |
#$result["length"],取得的內容長度.
|
|
|
11773 |
#$result["EOF"],識別是否已經到檔案結尾,"true"代表是,"false"代表不是.
|
|
|
11774 |
#$result["mimeType"],檔案的 mime type.
|
|
|
11775 |
#必填參數:
|
|
|
11776 |
#$conf["file"],字串,檔案的路徑與名稱.
|
|
|
11777 |
$conf["file"]="";
|
|
|
11778 |
#$conf["fileArgu"],字串,__FILE__的內容.
|
|
|
11779 |
$conf["fileArgu"]=__FILE__;
|
|
|
11780 |
#$conf["bytes"],整數字串,要讀取多少bytes.
|
|
|
11781 |
$conf["bytes"]="";
|
|
|
11782 |
#$conf["startIndex"],要從哪個bytes位置開始,起始點為0.
|
|
|
11783 |
$conf["startIndex"]="";
|
|
|
11784 |
#可省略參數:
|
|
|
11785 |
#無
|
|
|
11786 |
#參考資料:
|
|
|
11787 |
#無.
|
|
|
11788 |
#備註:
|
|
|
11789 |
#無
|
|
|
11790 |
*/
|
|
|
11791 |
public static function getFilePart(&$conf){
|
| 226 |
liveuser |
11792 |
|
| 3 |
liveuser |
11793 |
#初始化要回傳的結果
|
|
|
11794 |
$result=array();
|
|
|
11795 |
|
|
|
11796 |
#取得當前執行的函數名稱
|
|
|
11797 |
$result["function"]=__FUNCTION__;
|
|
|
11798 |
|
|
|
11799 |
#如果沒有參數
|
|
|
11800 |
if(func_num_args()==0){
|
|
|
11801 |
|
|
|
11802 |
#設置執行失敗
|
|
|
11803 |
$result["status"]="false";
|
|
|
11804 |
|
|
|
11805 |
#設置執行錯誤訊息
|
|
|
11806 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
11807 |
|
|
|
11808 |
#回傳結果
|
|
|
11809 |
return $result;
|
|
|
11810 |
|
|
|
11811 |
}#if end
|
| 226 |
liveuser |
11812 |
|
| 3 |
liveuser |
11813 |
#取得參數
|
|
|
11814 |
$result["argu"]=$conf;
|
|
|
11815 |
|
|
|
11816 |
#如果 $conf 不為陣列
|
|
|
11817 |
if(gettype($conf)!=="array"){
|
|
|
11818 |
|
|
|
11819 |
#設置執行失敗
|
|
|
11820 |
$result["status"]="false";
|
|
|
11821 |
|
|
|
11822 |
#設置執行錯誤訊息
|
|
|
11823 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
11824 |
|
|
|
11825 |
#如果傳入的參數為 null
|
|
|
11826 |
if(is_null($conf)){
|
|
|
11827 |
|
|
|
11828 |
#設置執行錯誤訊息
|
|
|
11829 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
11830 |
|
|
|
11831 |
}#if end
|
|
|
11832 |
|
|
|
11833 |
#回傳結果
|
|
|
11834 |
return $result;
|
|
|
11835 |
|
|
|
11836 |
}#if end
|
| 226 |
liveuser |
11837 |
|
| 3 |
liveuser |
11838 |
#函式說明:
|
|
|
11839 |
#檢查多個檔案與資料夾是否存在.
|
|
|
11840 |
#回傳的結果:
|
|
|
11841 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
11842 |
#$result["error"],錯誤訊息陣列.
|
|
|
11843 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
11844 |
#$result["argu"],使用的參數.
|
|
|
11845 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
11846 |
#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
|
|
|
11847 |
#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
|
|
|
11848 |
#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
|
|
|
11849 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
11850 |
#必填參數:
|
|
|
11851 |
#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
11852 |
$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
|
|
|
11853 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
11854 |
$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
|
|
|
11855 |
#可省略參數:
|
|
|
11856 |
#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
|
|
|
11857 |
#$conf["disableWebSearch"]="false";
|
|
|
11858 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
11859 |
#$conf["userDir"]="true";
|
|
|
11860 |
#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
|
|
|
11861 |
#$conf["web"]="true";
|
|
|
11862 |
#參考資料:
|
|
|
11863 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
11864 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
11865 |
#備註:
|
|
|
11866 |
#函數file_exists檢查的路徑為檔案系統的路徑
|
|
|
11867 |
#$result["varName"][$i]結果未實作
|
|
|
11868 |
$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
|
|
|
11869 |
unset($conf["fileAccess::checkMultiFileExist"]);
|
| 226 |
liveuser |
11870 |
|
| 3 |
liveuser |
11871 |
#如果執行失敗
|
|
|
11872 |
if($checkMultiFileExist["status"]==="false"){
|
| 226 |
liveuser |
11873 |
|
| 3 |
liveuser |
11874 |
#設置執行失敗
|
|
|
11875 |
$result["status"]="false";
|
| 226 |
liveuser |
11876 |
|
| 3 |
liveuser |
11877 |
#設置執行錯誤訊息
|
|
|
11878 |
$result["error"]=$checkMultiFileExist;
|
| 226 |
liveuser |
11879 |
|
| 3 |
liveuser |
11880 |
#回傳結果
|
|
|
11881 |
return $result;
|
| 226 |
liveuser |
11882 |
|
| 3 |
liveuser |
11883 |
}#if end
|
| 226 |
liveuser |
11884 |
|
| 3 |
liveuser |
11885 |
#如果檔案不存在
|
|
|
11886 |
if($checkMultiFileExist["allExist"]==="false"){
|
| 226 |
liveuser |
11887 |
|
| 3 |
liveuser |
11888 |
#設置執行失敗
|
|
|
11889 |
$result["status"]="false";
|
| 226 |
liveuser |
11890 |
|
| 3 |
liveuser |
11891 |
#設置執行錯誤訊息
|
|
|
11892 |
$result["error"]=$checkMultiFileExist;
|
| 226 |
liveuser |
11893 |
|
| 3 |
liveuser |
11894 |
#回傳結果
|
|
|
11895 |
return $result;
|
| 226 |
liveuser |
11896 |
|
| 3 |
liveuser |
11897 |
}#if end
|
| 226 |
liveuser |
11898 |
|
| 3 |
liveuser |
11899 |
#取得mimetype
|
|
|
11900 |
$mimetype=mime_content_type($conf["file"]);
|
| 226 |
liveuser |
11901 |
|
| 3 |
liveuser |
11902 |
#取得檔案的 mime type
|
|
|
11903 |
$result["mimeType"]=$mimetype;
|
| 226 |
liveuser |
11904 |
|
| 3 |
liveuser |
11905 |
#透過 dd 指令,取得部分內容.
|
|
|
11906 |
#函式說明:
|
|
|
11907 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
11908 |
#回傳結果:
|
|
|
11909 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
11910 |
#$result["error"],錯誤訊息陣列.
|
|
|
11911 |
#$result["function"],當前執行的函數名稱.
|
|
|
11912 |
#$result["argu"],使用的參數.
|
|
|
11913 |
#$result["cmd"],執行的指令內容.
|
|
|
11914 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
11915 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
11916 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
11917 |
#$result["running"],是否還在執行.
|
|
|
11918 |
#$result["pid"],pid.
|
|
|
11919 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
11920 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
11921 |
#必填參數:
|
|
|
11922 |
#$conf["command"],字串,要執行的指令.
|
|
|
11923 |
$conf["external::callShell"]["command"]="dd";
|
|
|
11924 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
11925 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
|
|
11926 |
#可省略參數:
|
|
|
11927 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
11928 |
$conf["external::callShell"]["argu"]=array("if=".$conf["file"],"bs=".$conf["bytes"],"count=1","status=none");
|
|
|
11929 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
11930 |
#$conf["arguIsAddr"]=array();
|
|
|
11931 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
11932 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
11933 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
11934 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
11935 |
#$conf["enablePrintDescription"]="true";
|
|
|
11936 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
11937 |
#$conf["printDescription"]="";
|
|
|
11938 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
11939 |
#$conf["escapeshellarg"]="false";
|
|
|
11940 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
11941 |
#$conf["thereIsShellVar"]=array();
|
|
|
11942 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
11943 |
#$conf["username"]="";
|
|
|
11944 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
11945 |
#$conf["password"]="";
|
|
|
11946 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
11947 |
#$conf["useScript"]="";
|
|
|
11948 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
11949 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
11950 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
11951 |
#$conf["inBackGround"]="";
|
|
|
11952 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
11953 |
#$conf["getErr"]="false";
|
|
|
11954 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
11955 |
#$conf["doNotRun"]="false";
|
|
|
11956 |
#參考資料:
|
|
|
11957 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
11958 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
11959 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
11960 |
#備註:
|
|
|
11961 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
11962 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
11963 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
11964 |
unset($conf["external::callShell"]);
|
| 226 |
liveuser |
11965 |
|
| 3 |
liveuser |
11966 |
#如果執行失敗
|
|
|
11967 |
if($callShell["status"]==="false"){
|
| 226 |
liveuser |
11968 |
|
| 3 |
liveuser |
11969 |
#設置執行失敗
|
|
|
11970 |
$result["status"]="false";
|
| 226 |
liveuser |
11971 |
|
| 3 |
liveuser |
11972 |
#設置執行錯誤訊息
|
|
|
11973 |
$result["error"]=$callShell;
|
| 226 |
liveuser |
11974 |
|
| 3 |
liveuser |
11975 |
#回傳結果
|
|
|
11976 |
return $result;
|
| 226 |
liveuser |
11977 |
|
| 3 |
liveuser |
11978 |
}#if end
|
| 226 |
liveuser |
11979 |
|
| 3 |
liveuser |
11980 |
#取得結果
|
|
|
11981 |
$result["content"]=$callShell["output"][0];
|
| 226 |
liveuser |
11982 |
|
| 3 |
liveuser |
11983 |
#取得內容長度
|
|
|
11984 |
$result["length"]=strlen($result["content"]);
|
| 226 |
liveuser |
11985 |
|
|
|
11986 |
#預設尚未到檔案結尾
|
| 3 |
liveuser |
11987 |
$result["EOF"]="false";
|
| 226 |
liveuser |
11988 |
|
| 3 |
liveuser |
11989 |
#如果取得的內容長度小於預期
|
|
|
11990 |
if($result["length"]<$conf["bytes"]){
|
| 226 |
liveuser |
11991 |
|
| 3 |
liveuser |
11992 |
#設置已經到檔案結尾了
|
|
|
11993 |
$result["EOF"]="true";
|
| 226 |
liveuser |
11994 |
|
| 3 |
liveuser |
11995 |
}#if end
|
| 226 |
liveuser |
11996 |
|
| 3 |
liveuser |
11997 |
#設置執行正常
|
|
|
11998 |
$result["status"]="true";
|
| 226 |
liveuser |
11999 |
|
| 3 |
liveuser |
12000 |
#回傳結果
|
|
|
12001 |
return $result;
|
| 226 |
liveuser |
12002 |
|
| 3 |
liveuser |
12003 |
}#function getFilePart end
|
|
|
12004 |
|
|
|
12005 |
/*
|
|
|
12006 |
#函式說明:
|
|
|
12007 |
#取得節點的資訊.
|
|
|
12008 |
#回傳結果:
|
|
|
12009 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
12010 |
#$result["error"],錯誤訊息陣列.
|
| 226 |
liveuser |
12011 |
#$result["function"],函數名稱.
|
| 3 |
liveuser |
12012 |
#$result["content"],檔案資訊陣列.
|
| 226 |
liveuser |
12013 |
#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
|
| 3 |
liveuser |
12014 |
#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
|
|
|
12015 |
#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
|
|
|
12016 |
#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
|
|
|
12017 |
#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
|
|
|
12018 |
#$result["content"]["ownerName"],檔案擁有着資訊.
|
|
|
12019 |
#$result["content"]["groupName"],檔案所屬擁有着資訊.
|
|
|
12020 |
#$result["content"]["size"],檔案大小.
|
|
|
12021 |
#$result["content"]["modifyDate"],檔案變更年月日.
|
|
|
12022 |
#$result["content"]["modifyTime"],檔案變更時分秒.
|
|
|
12023 |
#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
|
|
|
12024 |
#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
|
|
|
12025 |
#必填參數:
|
|
|
12026 |
#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
|
|
|
12027 |
$conf["fileArgu"]=__FILE__;
|
|
|
12028 |
#$conf["file"],字串,要查看擁有者資訊的檔案.
|
|
|
12029 |
$conf["file"]="";
|
|
|
12030 |
#可省略參數:
|
|
|
12031 |
#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
|
|
|
12032 |
#$conf["web"]="true";
|
|
|
12033 |
#參考資料:
|
|
|
12034 |
#fileowner=>http://php.net/manual/en/function.fileowner.php
|
|
|
12035 |
#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
|
|
|
12036 |
#備註:
|
|
|
12037 |
#無.
|
|
|
12038 |
*/
|
|
|
12039 |
public static function fileInfo(&$conf=array()){
|
| 226 |
liveuser |
12040 |
|
| 3 |
liveuser |
12041 |
#初始化要回傳的結果
|
|
|
12042 |
$result=array();
|
|
|
12043 |
|
|
|
12044 |
#取得當前執行的函數名稱
|
|
|
12045 |
$result["function"]=__FUNCTION__;
|
|
|
12046 |
|
|
|
12047 |
#如果沒有參數
|
|
|
12048 |
if(func_num_args()==0){
|
| 226 |
liveuser |
12049 |
|
| 3 |
liveuser |
12050 |
#設置執行失敗
|
|
|
12051 |
$result["status"]="false";
|
| 226 |
liveuser |
12052 |
|
| 3 |
liveuser |
12053 |
#設置執行錯誤訊息
|
|
|
12054 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
12055 |
|
| 3 |
liveuser |
12056 |
#回傳結果
|
|
|
12057 |
return $result;
|
| 226 |
liveuser |
12058 |
|
| 3 |
liveuser |
12059 |
}#if end
|
|
|
12060 |
|
|
|
12061 |
#取得參數
|
|
|
12062 |
$result["argu"]=$conf;
|
|
|
12063 |
|
|
|
12064 |
#如果 $conf 不為陣列
|
|
|
12065 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
12066 |
|
| 3 |
liveuser |
12067 |
#設置執行失敗
|
|
|
12068 |
$result["status"]="false";
|
| 226 |
liveuser |
12069 |
|
| 3 |
liveuser |
12070 |
#設置執行錯誤訊息
|
|
|
12071 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
12072 |
|
| 3 |
liveuser |
12073 |
#如果傳入的參數為 null
|
|
|
12074 |
if($conf===null){
|
| 226 |
liveuser |
12075 |
|
| 3 |
liveuser |
12076 |
#設置執行錯誤訊息
|
|
|
12077 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
12078 |
|
| 3 |
liveuser |
12079 |
}#if end
|
|
|
12080 |
|
|
|
12081 |
#回傳結果
|
|
|
12082 |
return $result;
|
| 226 |
liveuser |
12083 |
|
| 3 |
liveuser |
12084 |
}#if end
|
| 226 |
liveuser |
12085 |
|
| 3 |
liveuser |
12086 |
#檢查參數
|
|
|
12087 |
#函式說明:
|
|
|
12088 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
12089 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
12090 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
12091 |
#$result["function"],當前執行的函式名稱.
|
|
|
12092 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
12093 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
12094 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
12095 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
12096 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
12097 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
12098 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
12099 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
12100 |
#必填寫的參數:
|
|
|
12101 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
| 226 |
liveuser |
12102 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
| 3 |
liveuser |
12103 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
12104 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
12105 |
#可以省略的參數:
|
|
|
12106 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
12107 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
|
|
|
12108 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
12109 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
12110 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
12111 |
#$conf["canBeEmptyString"]="false";
|
|
|
12112 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
12113 |
#$conf["ileAccess::checkArguments"]["canNotBeEmpty"]=array();
|
|
|
12114 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
12115 |
#$conf["canBeEmpty"]=array();
|
|
|
12116 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
12117 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
12118 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
12119 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
|
| 226 |
liveuser |
12120 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
12121 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
12122 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
12123 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
|
|
|
12124 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
12125 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
12126 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
12127 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
12128 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
12129 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
12130 |
#參考資料來源:
|
|
|
12131 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
12132 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
12133 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
12134 |
|
| 3 |
liveuser |
12135 |
#如果檢查參數失敗
|
|
|
12136 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
12137 |
|
| 3 |
liveuser |
12138 |
#設置執行失敗
|
|
|
12139 |
$result["status"]="false";
|
| 226 |
liveuser |
12140 |
|
| 3 |
liveuser |
12141 |
#設置執行錯誤訊息
|
|
|
12142 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
12143 |
|
| 3 |
liveuser |
12144 |
#回傳結果
|
|
|
12145 |
return $result;
|
| 226 |
liveuser |
12146 |
|
| 3 |
liveuser |
12147 |
}#if end
|
| 226 |
liveuser |
12148 |
|
| 3 |
liveuser |
12149 |
#如果檢查參數不通過
|
|
|
12150 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
12151 |
|
| 3 |
liveuser |
12152 |
#設置執行失敗
|
|
|
12153 |
$result["status"]="false";
|
| 226 |
liveuser |
12154 |
|
| 3 |
liveuser |
12155 |
#設置執行錯誤訊息
|
|
|
12156 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
12157 |
|
| 3 |
liveuser |
12158 |
#回傳結果
|
|
|
12159 |
return $result;
|
| 226 |
liveuser |
12160 |
|
| 3 |
liveuser |
12161 |
}#if end
|
| 226 |
liveuser |
12162 |
|
| 3 |
liveuser |
12163 |
#函式說明:
|
|
|
12164 |
#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
|
|
|
12165 |
#回傳結果:
|
|
|
12166 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
12167 |
#$result["error"],錯誤訊息陣列.
|
| 226 |
liveuser |
12168 |
#$result["function"],函數名稱.
|
| 3 |
liveuser |
12169 |
#$result["argu"],使用的參數.
|
|
|
12170 |
#$result["content"],網址,若是在命令列執行,則為"null".
|
|
|
12171 |
#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
|
|
|
12172 |
#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「document_root」目錄開始的路徑.
|
|
|
12173 |
#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
|
|
|
12174 |
#必填參數:
|
|
|
12175 |
#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
|
|
|
12176 |
$conf["fileAccess::getInternetAddressV2"]["address"]=$conf["file"];
|
|
|
12177 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
12178 |
$conf["fileAccess::getInternetAddressV2"]["fileArgu"]=$conf["fileArgu"];
|
|
|
12179 |
#可省略參數:
|
|
|
12180 |
#$conf["web"],字串,"true"代表檔案是放在web環境;"false"是代表在檔案系統環境,預設為"true".
|
|
|
12181 |
$conf["fileAccess::getInternetAddressV2"]["web"]=$conf["web"];
|
|
|
12182 |
#備註:
|
|
|
12183 |
#建構中,fileSystemRelativePosition尚未實作,檢查參數尚未實作.
|
|
|
12184 |
$getInternetAddressV2=fileAccess::getInternetAddressV2($conf["fileAccess::getInternetAddressV2"]);
|
|
|
12185 |
unset($conf["fileAccess::getInternetAddressV2"]);
|
| 226 |
liveuser |
12186 |
|
| 3 |
liveuser |
12187 |
#如果取得位置失敗
|
|
|
12188 |
if($getInternetAddressV2["status"]==="false"){
|
| 226 |
liveuser |
12189 |
|
| 3 |
liveuser |
12190 |
#設置執行失敗
|
|
|
12191 |
$result["status"]="false";
|
| 226 |
liveuser |
12192 |
|
| 3 |
liveuser |
12193 |
#設置執行錯誤訊息
|
|
|
12194 |
$result["error"]=$getInternetAddressV2;
|
| 226 |
liveuser |
12195 |
|
| 3 |
liveuser |
12196 |
#回傳結果
|
|
|
12197 |
return $result;
|
| 226 |
liveuser |
12198 |
|
| 3 |
liveuser |
12199 |
}#if end
|
|
|
12200 |
|
|
|
12201 |
#函式說明:
|
|
|
12202 |
#檢查多個檔案與資料夾是否存在.
|
|
|
12203 |
#回傳的結果:
|
|
|
12204 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
12205 |
#$result["error"],錯誤訊息陣列.
|
|
|
12206 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
12207 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
12208 |
#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
|
|
|
12209 |
#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
|
|
|
12210 |
#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
|
|
|
12211 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
12212 |
#必填參數:
|
|
|
12213 |
#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
12214 |
$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($getInternetAddressV2["fileSystemAbsoulutePosition"]);
|
|
|
12215 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
12216 |
$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
12217 |
#可省略參數
|
|
|
12218 |
#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
|
|
|
12219 |
#$conf["disableWebSearch"]="false";
|
|
|
12220 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
12221 |
#$conf["userDir"]="true";
|
|
|
12222 |
#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
|
|
|
12223 |
$conf["fileAccess::checkMultiFileExist"]["web"]="false";
|
|
|
12224 |
#參考資料來源:
|
|
|
12225 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
12226 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
12227 |
#備註:
|
|
|
12228 |
#函數file_exists檢查的路徑為檔案系統的路徑
|
|
|
12229 |
$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
|
|
|
12230 |
unset($conf["fileAccess::checkMultiFileExist"]);
|
| 226 |
liveuser |
12231 |
|
| 3 |
liveuser |
12232 |
#如果檢查檔案存在失敗
|
|
|
12233 |
if($checkMultiFileExist["status"]==="false"){
|
| 226 |
liveuser |
12234 |
|
| 3 |
liveuser |
12235 |
#設置執行失敗
|
|
|
12236 |
$result["status"]="false";
|
| 226 |
liveuser |
12237 |
|
| 3 |
liveuser |
12238 |
#設置執行錯誤訊息
|
|
|
12239 |
$result["error"]=$checkMultiFileExist;
|
| 226 |
liveuser |
12240 |
|
| 3 |
liveuser |
12241 |
#回傳結果
|
|
|
12242 |
return $result;
|
| 226 |
liveuser |
12243 |
|
| 3 |
liveuser |
12244 |
}#if end
|
| 226 |
liveuser |
12245 |
|
| 3 |
liveuser |
12246 |
#如果檔案不存在
|
|
|
12247 |
if($checkMultiFileExist["allExist"]==="false"){
|
| 226 |
liveuser |
12248 |
|
| 3 |
liveuser |
12249 |
#設置執行失敗
|
|
|
12250 |
$result["status"]="false";
|
| 226 |
liveuser |
12251 |
|
| 3 |
liveuser |
12252 |
#設置執行錯誤訊息
|
|
|
12253 |
$result["error"]=$checkMultiFileExist;
|
| 226 |
liveuser |
12254 |
|
| 3 |
liveuser |
12255 |
#回傳結果
|
|
|
12256 |
return $result;
|
| 226 |
liveuser |
12257 |
|
| 3 |
liveuser |
12258 |
}#if end
|
| 226 |
liveuser |
12259 |
|
| 3 |
liveuser |
12260 |
#透過ls指令取得檔案的資訊
|
|
|
12261 |
#函式說明:
|
|
|
12262 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
12263 |
#回傳的結果:
|
|
|
12264 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
12265 |
#$result["error"],錯誤訊息陣列.
|
|
|
12266 |
#$result["function"],當前執行的函數名稱.
|
|
|
12267 |
#$result["cmd"],執行的指令內容.
|
|
|
12268 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
12269 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
12270 |
#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
12271 |
#$result["running"],是否還在執行.
|
|
|
12272 |
#$result["pid"],pid
|
|
|
12273 |
#必填的參數
|
|
|
12274 |
#$conf["command"],字串,要執行的指令
|
|
|
12275 |
$conf["external::callShell"]["command"]="ls";
|
|
|
12276 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
12277 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
|
|
12278 |
#可省略參數:
|
|
|
12279 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
12280 |
$conf["external::callShell"]["argu"]=array("-l","--full-time","-d",$conf["file"]);
|
|
|
12281 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
12282 |
$conf["external::callShell"]["arguIsAddr"]=array("false","false","false","false");
|
|
|
12283 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
12284 |
#$conf["enablePrintDescription"]="true";
|
|
|
12285 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
|
|
|
12286 |
#$conf["printDescription"]="";
|
|
|
12287 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
|
|
|
12288 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
12289 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
12290 |
#$conf["username"]="";
|
|
|
12291 |
#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
12292 |
#$conf["password"]="";
|
|
|
12293 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
12294 |
#$conf["useScript"]="";
|
|
|
12295 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
12296 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
12297 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
12298 |
#$conf["inBackGround"]="";
|
|
|
12299 |
#備註:
|
|
|
12300 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
12301 |
#參考資料:
|
|
|
12302 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
12303 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
12304 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
12305 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
12306 |
unset($conf["external::callShell"]);
|
| 226 |
liveuser |
12307 |
|
| 3 |
liveuser |
12308 |
#如果執行失敗
|
|
|
12309 |
if($callShell["status"]==="false"){
|
| 226 |
liveuser |
12310 |
|
| 3 |
liveuser |
12311 |
#設置執行失敗
|
|
|
12312 |
$result["status"]="false";
|
| 226 |
liveuser |
12313 |
|
| 3 |
liveuser |
12314 |
#設置執行錯誤訊息
|
|
|
12315 |
$result["error"]=$callShell;
|
| 226 |
liveuser |
12316 |
|
| 3 |
liveuser |
12317 |
#回傳結果
|
|
|
12318 |
return $result;
|
| 226 |
liveuser |
12319 |
|
|
|
12320 |
}#if end
|
|
|
12321 |
|
| 3 |
liveuser |
12322 |
#解析檔案資訊
|
|
|
12323 |
#-rwxrwx--x. 1 apache apache 65K 2017-04-16 22:53:19.044545806 +0800 fileAccessT.php
|
| 226 |
liveuser |
12324 |
|
| 3 |
liveuser |
12325 |
#取得權限資訊 -rwxrwx--x
|
|
|
12326 |
$perm=substr($callShell["output"][0],0,strpos($callShell["output"][0],'.'));
|
| 226 |
liveuser |
12327 |
|
| 3 |
liveuser |
12328 |
#如果是目錄
|
|
|
12329 |
if(substr($perm,0,1)==="d"){
|
| 226 |
liveuser |
12330 |
|
| 3 |
liveuser |
12331 |
#設定為目錄
|
|
|
12332 |
$result["content"]["is_folder"]="true";
|
| 226 |
liveuser |
12333 |
|
| 3 |
liveuser |
12334 |
}#if end
|
| 226 |
liveuser |
12335 |
|
| 3 |
liveuser |
12336 |
#反之
|
|
|
12337 |
else{
|
| 226 |
liveuser |
12338 |
|
| 3 |
liveuser |
12339 |
#設定不為目錄
|
|
|
12340 |
$result["content"]["is_folder"]="false";
|
| 226 |
liveuser |
12341 |
|
| 3 |
liveuser |
12342 |
}#else end
|
| 226 |
liveuser |
12343 |
|
| 3 |
liveuser |
12344 |
#解析檔案擁有者權限資訊
|
|
|
12345 |
$result["content"]["ownerPerm"]=substr($perm,1,3);
|
| 226 |
liveuser |
12346 |
|
| 3 |
liveuser |
12347 |
#如果檔案擁有者名稱為空
|
|
|
12348 |
if(empty($result["content"]["ownerPerm"])){
|
| 226 |
liveuser |
12349 |
|
| 3 |
liveuser |
12350 |
#設置執行失敗
|
|
|
12351 |
$result["status"]="false";
|
| 226 |
liveuser |
12352 |
|
| 3 |
liveuser |
12353 |
#設置執行錯誤訊息
|
|
|
12354 |
$result["error"]=$callShell;
|
| 226 |
liveuser |
12355 |
|
| 3 |
liveuser |
12356 |
#回傳結果
|
|
|
12357 |
return $result;
|
| 226 |
liveuser |
12358 |
|
| 3 |
liveuser |
12359 |
}#if end
|
| 226 |
liveuser |
12360 |
|
| 3 |
liveuser |
12361 |
#解析檔案歸屬群組權限資訊
|
|
|
12362 |
$result["content"]["groupPerm"]=substr($perm,4,3);
|
| 226 |
liveuser |
12363 |
|
| 3 |
liveuser |
12364 |
#解析檔案對於其他身份使用者的權限資訊
|
|
|
12365 |
$result["content"]["otherPerm"]=substr($perm,7,3);
|
| 226 |
liveuser |
12366 |
|
| 3 |
liveuser |
12367 |
#取得目錄底下的檔案目錄數量起始點
|
|
|
12368 |
$subElementStartPos=strpos($callShell["output"][0],' ');
|
| 226 |
liveuser |
12369 |
|
| 3 |
liveuser |
12370 |
#取得目錄底下的檔案目錄數量結束點
|
|
|
12371 |
$subElementEndPos=strpos($callShell["output"][0],' ',$subElementStartPos+1);
|
| 226 |
liveuser |
12372 |
|
| 3 |
liveuser |
12373 |
#取得目錄底下的檔案目錄數量
|
|
|
12374 |
$result["content"]["subElementCount"]=substr($callShell["output"][0],$subElementStartPos,$subElementEndPos-$subElementStartPos);
|
| 226 |
liveuser |
12375 |
|
| 3 |
liveuser |
12376 |
#取得檔案擁有着資訊的起點
|
|
|
12377 |
$ownerNameStrPos=strpos($callShell["output"][0],' ',$subElementEndPos)+1;
|
| 226 |
liveuser |
12378 |
|
| 3 |
liveuser |
12379 |
#取得檔案擁有着資訊的結束點
|
|
|
12380 |
$ownerNameEndPos=strpos($callShell["output"][0],' ',$ownerNameStrPos+1);
|
| 226 |
liveuser |
12381 |
|
| 3 |
liveuser |
12382 |
#取得檔案擁有着資訊
|
|
|
12383 |
$result["content"]["ownerName"]=substr($callShell["output"][0],$ownerNameStrPos,$ownerNameEndPos-$ownerNameStrPos);
|
| 226 |
liveuser |
12384 |
|
| 3 |
liveuser |
12385 |
#取取得檔案群組擁有者資訊的起點
|
|
|
12386 |
$groupNameStrPos=strpos($callShell["output"][0],' ',$ownerNameEndPos)+1;
|
| 226 |
liveuser |
12387 |
|
| 3 |
liveuser |
12388 |
#取得檔案群組擁有者資訊的結束點
|
|
|
12389 |
$groupNameEndPos=strpos($callShell["output"][0],' ',$groupNameStrPos);
|
| 226 |
liveuser |
12390 |
|
| 3 |
liveuser |
12391 |
#取得檔案群組擁有者資訊
|
|
|
12392 |
$result["content"]["groupName"]=substr($callShell["output"][0],$groupNameStrPos,$groupNameEndPos-$groupNameStrPos);
|
| 226 |
liveuser |
12393 |
|
| 3 |
liveuser |
12394 |
#取得檔案大小的起點
|
|
|
12395 |
$sizeStrPos=strpos($callShell["output"][0],' ',$groupNameEndPos)+1;
|
| 226 |
liveuser |
12396 |
|
| 3 |
liveuser |
12397 |
#取得檔案大小的結束點
|
|
|
12398 |
$sizeEndPos=strpos($callShell["output"][0],' ',$sizeStrPos);
|
| 226 |
liveuser |
12399 |
|
| 3 |
liveuser |
12400 |
#取得檔案大小
|
|
|
12401 |
$result["content"]["size"]=substr($callShell["output"][0],$sizeStrPos,$sizeEndPos-$sizeStrPos);
|
| 226 |
liveuser |
12402 |
|
| 3 |
liveuser |
12403 |
#取得檔案變更年月日的起點
|
|
|
12404 |
$modifyDateStrPos=strpos($callShell["output"][0],' ',$sizeEndPos)+1;
|
| 226 |
liveuser |
12405 |
|
| 3 |
liveuser |
12406 |
#取得檔案變更年月日的結束點
|
|
|
12407 |
$modifyDateEndPos=strpos($callShell["output"][0],' ',$modifyDateStrPos);
|
| 226 |
liveuser |
12408 |
|
|
|
12409 |
#取得檔案變更年月日
|
| 3 |
liveuser |
12410 |
$result["content"]["modifyDate"]=substr($callShell["output"][0],$modifyDateStrPos,$modifyDateEndPos-$modifyDateStrPos);
|
| 226 |
liveuser |
12411 |
|
| 3 |
liveuser |
12412 |
#取得檔案變更時分秒的起點
|
|
|
12413 |
$modifyTimeStrPos=strpos($callShell["output"][0],' ',$modifyDateEndPos)+1;
|
| 226 |
liveuser |
12414 |
|
| 3 |
liveuser |
12415 |
#取得檔案變更時分秒的結束點
|
|
|
12416 |
$modifyTimeEndPos=strpos($callShell["output"][0],'.',$modifyTimeStrPos);
|
| 226 |
liveuser |
12417 |
|
| 3 |
liveuser |
12418 |
#取得檔案變更時分秒
|
|
|
12419 |
$result["content"]["modifyTime"]=substr($callShell["output"][0],$modifyTimeStrPos,$modifyTimeEndPos-$modifyTimeStrPos);
|
| 226 |
liveuser |
12420 |
|
| 3 |
liveuser |
12421 |
#取得檔版變更時間秒的float數值起點
|
|
|
12422 |
$modifyTimeFloatStrPos=strpos($callShell["output"][0],'.',$modifyTimeEndPos)+1;
|
| 226 |
liveuser |
12423 |
|
| 3 |
liveuser |
12424 |
#取得檔版變更時間秒的float數值結束點
|
|
|
12425 |
$modifyTimeFloatEndPos=strpos($callShell["output"][0],' ',$modifyTimeFloatStrPos);
|
| 226 |
liveuser |
12426 |
|
|
|
12427 |
#取得檔版變更時間秒的float數值
|
| 3 |
liveuser |
12428 |
$result["content"]["modifyTimeFloat"]=substr($callShell["output"][0],$modifyTimeFloatStrPos,$modifyTimeFloatEndPos-$modifyTimeFloatStrPos);
|
| 226 |
liveuser |
12429 |
|
| 3 |
liveuser |
12430 |
#取得時區起始點
|
|
|
12431 |
$timezoneStrPos=strpos($callShell["output"][0],' ',$modifyTimeFloatEndPos)+1;
|
| 226 |
liveuser |
12432 |
|
| 3 |
liveuser |
12433 |
#取得時區結束點
|
| 226 |
liveuser |
12434 |
$timezoneEndPos=strpos($callShell["output"][0],' ',$timezoneStrPos)+1;
|
|
|
12435 |
|
| 3 |
liveuser |
12436 |
#取得檔案變更時間的時區與UTC的差距.
|
| 226 |
liveuser |
12437 |
$result["content"]["timezone"]=substr($callShell["output"][0],$timezoneStrPos,$timezoneEndPos-$timezoneStrPos);
|
|
|
12438 |
|
| 3 |
liveuser |
12439 |
#設置執行正常
|
|
|
12440 |
$result["status"]="true";
|
| 226 |
liveuser |
12441 |
|
| 3 |
liveuser |
12442 |
#回傳結果
|
|
|
12443 |
return $result;
|
| 226 |
liveuser |
12444 |
|
| 3 |
liveuser |
12445 |
}#function fileInfo end
|
|
|
12446 |
|
|
|
12447 |
/*
|
|
|
12448 |
#函式說明:
|
| 226 |
liveuser |
12449 |
#依據函數getListTree執行的結果,將其底下與其子目錄底下的特定檔案內容依據目錄層級輸出成html檔案
|
| 3 |
liveuser |
12450 |
#回傳結果:
|
|
|
12451 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
12452 |
#$result["error"],錯誤訊息陣列.
|
| 226 |
liveuser |
12453 |
#$result["function"],函數名稱.
|
| 3 |
liveuser |
12454 |
#$result["content"],html檔案輸出的位置與名稱.
|
|
|
12455 |
#必填參數:
|
|
|
12456 |
#$conf["getListTree"],陣列變數,函數getListTree執行的結果.
|
|
|
12457 |
$conf["getListTree"]=$getListTree;
|
|
|
12458 |
#可省略參數:
|
|
|
12459 |
#$conf["fileToRead"],字串,要讀取的檔案名稱為何?預設為"help".
|
|
|
12460 |
#$conf["fileToRead"]="help";
|
|
|
12461 |
#$conf["output"],字串,輸出的網頁檔案位置與名稱,副檔名html會自動補上,預設為"help".
|
| 226 |
liveuser |
12462 |
#$conf["output"]="help.html";
|
| 3 |
liveuser |
12463 |
#參考資料:
|
|
|
12464 |
#無.
|
|
|
12465 |
#備註:
|
|
|
12466 |
#建構中...
|
|
|
12467 |
*/
|
|
|
12468 |
public static function createHelpFile($conf){
|
| 226 |
liveuser |
12469 |
|
| 3 |
liveuser |
12470 |
#初始化要回傳的結果
|
|
|
12471 |
$result=array();
|
| 226 |
liveuser |
12472 |
|
| 3 |
liveuser |
12473 |
#設置當其函數名稱
|
|
|
12474 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
12475 |
|
| 3 |
liveuser |
12476 |
#如果 $conf 不為陣列
|
|
|
12477 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
12478 |
|
| 3 |
liveuser |
12479 |
#設置執行失敗
|
|
|
12480 |
$result["status"]="false";
|
| 226 |
liveuser |
12481 |
|
| 3 |
liveuser |
12482 |
#設置執行錯誤訊息
|
|
|
12483 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
12484 |
|
|
|
12485 |
#如果傳入的參數為 null
|
|
|
12486 |
if($conf==null){
|
| 226 |
liveuser |
12487 |
|
| 3 |
liveuser |
12488 |
#設置執行錯誤訊息
|
|
|
12489 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
12490 |
|
| 3 |
liveuser |
12491 |
}#if end
|
|
|
12492 |
|
|
|
12493 |
#回傳結果
|
|
|
12494 |
return $result;
|
| 226 |
liveuser |
12495 |
|
| 3 |
liveuser |
12496 |
}#if end
|
| 226 |
liveuser |
12497 |
|
| 3 |
liveuser |
12498 |
#檢查參數
|
|
|
12499 |
#函式說明:
|
|
|
12500 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
12501 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
12502 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
12503 |
#$result["function"],當前執行的函式名稱.
|
|
|
12504 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
12505 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
12506 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
12507 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
12508 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
12509 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
12510 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
12511 |
#必填寫的參數:
|
|
|
12512 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
12513 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
12514 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
12515 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("getListTree");
|
| 226 |
liveuser |
12516 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
12517 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
|
|
|
12518 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
12519 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
12520 |
#可以省略的參數:
|
|
|
12521 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
12522 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
12523 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
12524 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileToRead","output");
|
| 226 |
liveuser |
12525 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
12526 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
12527 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
12528 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("help","help");
|
|
|
12529 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
12530 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("leaderWordArray","leaderWordOptionCountArray");
|
|
|
12531 |
#參考資料來源:
|
|
|
12532 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
12533 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
12534 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
12535 |
|
| 3 |
liveuser |
12536 |
#如果 $checkResult["status"] 等於 "fasle"
|
|
|
12537 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
12538 |
|
| 3 |
liveuser |
12539 |
#設置錯誤識別
|
|
|
12540 |
$result["status"]="false";
|
| 226 |
liveuser |
12541 |
|
| 3 |
liveuser |
12542 |
#設置錯誤訊息
|
|
|
12543 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
12544 |
|
| 3 |
liveuser |
12545 |
#回傳結果
|
|
|
12546 |
return $result;
|
| 226 |
liveuser |
12547 |
|
| 3 |
liveuser |
12548 |
}#if end
|
| 226 |
liveuser |
12549 |
|
| 3 |
liveuser |
12550 |
#如果 $checkResult["passed"] 等於 "fasle"
|
|
|
12551 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
12552 |
|
| 3 |
liveuser |
12553 |
#設置錯誤識別
|
|
|
12554 |
$result["status"]="false";
|
| 226 |
liveuser |
12555 |
|
| 3 |
liveuser |
12556 |
#設置錯誤訊息
|
|
|
12557 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
12558 |
|
| 3 |
liveuser |
12559 |
#回傳結果
|
|
|
12560 |
return $result;
|
| 226 |
liveuser |
12561 |
|
| 3 |
liveuser |
12562 |
}#if end
|
| 226 |
liveuser |
12563 |
|
| 3 |
liveuser |
12564 |
#如果 $conf["getListTree"]["status"] 不存在
|
|
|
12565 |
if(!isset($conf["getListTree"]["status"])){
|
| 226 |
liveuser |
12566 |
|
| 3 |
liveuser |
12567 |
#設置錯誤識別
|
|
|
12568 |
$result["status"]="false";
|
| 226 |
liveuser |
12569 |
|
| 3 |
liveuser |
12570 |
#設置錯誤訊息
|
|
|
12571 |
$result["error"][]="getListTree參數必須為getListTree函數執行後的結果";
|
| 226 |
liveuser |
12572 |
|
| 3 |
liveuser |
12573 |
#回傳結果
|
|
|
12574 |
return $result;
|
| 226 |
liveuser |
12575 |
|
| 3 |
liveuser |
12576 |
}#if end
|
| 226 |
liveuser |
12577 |
|
| 3 |
liveuser |
12578 |
#如果 $conf["getListTree"] 執行失敗
|
|
|
12579 |
if($conf["getListTree"]["status"]=="false"){
|
| 226 |
liveuser |
12580 |
|
| 3 |
liveuser |
12581 |
#設置錯誤識別
|
|
|
12582 |
$result["status"]="false";
|
| 226 |
liveuser |
12583 |
|
| 3 |
liveuser |
12584 |
#設置錯誤訊息
|
|
|
12585 |
$result["error"]=$conf["getListTree"];
|
| 226 |
liveuser |
12586 |
|
| 3 |
liveuser |
12587 |
#回傳結果
|
|
|
12588 |
return $result;
|
| 226 |
liveuser |
12589 |
|
| 3 |
liveuser |
12590 |
}#if end
|
| 226 |
liveuser |
12591 |
|
| 3 |
liveuser |
12592 |
#如果有目錄檔案
|
|
|
12593 |
if(isset($conf["getListTree"]["content"])){
|
| 226 |
liveuser |
12594 |
|
|
|
12595 |
|
|
|
12596 |
|
| 3 |
liveuser |
12597 |
}#if end
|
| 226 |
liveuser |
12598 |
|
| 3 |
liveuser |
12599 |
}#function createHelpFile end
|
| 226 |
liveuser |
12600 |
|
| 3 |
liveuser |
12601 |
/*
|
|
|
12602 |
#函式說明:
|
|
|
12603 |
#嵌入pdf檔案到網頁上面
|
|
|
12604 |
#回傳結果:
|
|
|
12605 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
12606 |
#$result["error"],錯誤訊息陣列.
|
| 226 |
liveuser |
12607 |
#$result["function"],函數名稱.
|
| 3 |
liveuser |
12608 |
#$result["content"],嵌入pdf檔案的語法
|
|
|
12609 |
#必填參數:
|
|
|
12610 |
#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
|
|
|
12611 |
$conf["fileArgu"]=__FILE__;
|
|
|
12612 |
#$conf["file"],字串,pdf檔案位置.
|
|
|
12613 |
$conf["file"]="";
|
|
|
12614 |
#可省略參數:
|
|
|
12615 |
#$conf["type"],字串,要用"iframe"還是"object"的方式嵌入pdf檔案,預設為"iframe".
|
|
|
12616 |
#$conf["type"]="iframe";
|
|
|
12617 |
#參考資料:
|
|
|
12618 |
#嵌入pdf到網頁=>https://stackoverflow.com/questions/14690000/embed-a-pdf-in-html5
|
|
|
12619 |
#備註:
|
|
|
12620 |
#如果是網址就會出錯.
|
|
|
12621 |
*/
|
|
|
12622 |
public static function embedPdf(&$conf=array()){
|
| 226 |
liveuser |
12623 |
|
| 3 |
liveuser |
12624 |
#初始化要回傳的結果
|
|
|
12625 |
$result=array();
|
|
|
12626 |
|
|
|
12627 |
#取得當前執行的函數名稱
|
|
|
12628 |
$result["function"]=__FUNCTION__;
|
|
|
12629 |
|
|
|
12630 |
#如果沒有參數
|
|
|
12631 |
if(func_num_args()==0){
|
| 226 |
liveuser |
12632 |
|
| 3 |
liveuser |
12633 |
#設置執行失敗
|
|
|
12634 |
$result["status"]="false";
|
| 226 |
liveuser |
12635 |
|
| 3 |
liveuser |
12636 |
#設置執行錯誤訊息
|
|
|
12637 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
12638 |
|
| 3 |
liveuser |
12639 |
#回傳結果
|
|
|
12640 |
return $result;
|
| 226 |
liveuser |
12641 |
|
| 3 |
liveuser |
12642 |
}#if end
|
|
|
12643 |
|
|
|
12644 |
#取得參數
|
|
|
12645 |
$result["argu"]=$conf;
|
|
|
12646 |
|
|
|
12647 |
#如果 $conf 不為陣列
|
|
|
12648 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
12649 |
|
| 3 |
liveuser |
12650 |
#設置執行失敗
|
|
|
12651 |
$result["status"]="false";
|
| 226 |
liveuser |
12652 |
|
| 3 |
liveuser |
12653 |
#設置執行錯誤訊息
|
|
|
12654 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
12655 |
|
| 3 |
liveuser |
12656 |
#如果傳入的參數為 null
|
|
|
12657 |
if($conf===null){
|
| 226 |
liveuser |
12658 |
|
| 3 |
liveuser |
12659 |
#設置執行錯誤訊息
|
|
|
12660 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
12661 |
|
| 3 |
liveuser |
12662 |
}#if end
|
|
|
12663 |
|
|
|
12664 |
#回傳結果
|
|
|
12665 |
return $result;
|
| 226 |
liveuser |
12666 |
|
| 3 |
liveuser |
12667 |
}#if end
|
| 226 |
liveuser |
12668 |
|
| 3 |
liveuser |
12669 |
#檢查參數
|
|
|
12670 |
#函式說明:
|
|
|
12671 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
12672 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
12673 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
12674 |
#$result["function"],當前執行的函式名稱.
|
|
|
12675 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
12676 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
12677 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
12678 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
12679 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
12680 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
12681 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
12682 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
12683 |
#必填寫的參數:
|
|
|
12684 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
12685 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
12686 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
12687 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
|
|
|
12688 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
12689 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
12690 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
12691 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
12692 |
#可以省略的參數:
|
|
|
12693 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
12694 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
12695 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
12696 |
#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("function");
|
|
|
12697 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
12698 |
#$conf["canBeEmpty"]=array();
|
|
|
12699 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
12700 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("width","height");
|
|
|
12701 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
12702 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("type");
|
| 226 |
liveuser |
12703 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
12704 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
12705 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
12706 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("iframe");
|
|
|
12707 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
12708 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
12709 |
#參考資料來源:
|
|
|
12710 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
12711 |
#建議:
|
|
|
12712 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
12713 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
12714 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
12715 |
|
| 3 |
liveuser |
12716 |
#如果檢查參數失敗
|
|
|
12717 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
12718 |
|
| 3 |
liveuser |
12719 |
#設置執行失敗
|
|
|
12720 |
$result["status"]="false";
|
| 226 |
liveuser |
12721 |
|
| 3 |
liveuser |
12722 |
#設置執行錯誤訊息
|
|
|
12723 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
12724 |
|
| 3 |
liveuser |
12725 |
#回傳結果
|
|
|
12726 |
return $result;
|
| 226 |
liveuser |
12727 |
|
| 3 |
liveuser |
12728 |
}#if end
|
| 226 |
liveuser |
12729 |
|
| 3 |
liveuser |
12730 |
#如果參數檢查不通過
|
|
|
12731 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
12732 |
|
| 3 |
liveuser |
12733 |
#設置執行失敗
|
|
|
12734 |
$result["status"]="false";
|
| 226 |
liveuser |
12735 |
|
| 3 |
liveuser |
12736 |
#設置執行錯誤訊息
|
|
|
12737 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
12738 |
|
| 3 |
liveuser |
12739 |
#回傳結果
|
|
|
12740 |
return $result;
|
| 226 |
liveuser |
12741 |
|
| 3 |
liveuser |
12742 |
}#if end
|
| 226 |
liveuser |
12743 |
|
| 3 |
liveuser |
12744 |
#檢查檔案是否存在
|
|
|
12745 |
#函式說明:
|
|
|
12746 |
#檢查多個檔案與資料夾是否存在.
|
|
|
12747 |
#回傳的結果:
|
|
|
12748 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
12749 |
#$result["error"],錯誤訊息陣列.
|
|
|
12750 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
12751 |
#$result["argu"],使用的參數.
|
|
|
12752 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
12753 |
#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
|
|
|
12754 |
#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
|
|
|
12755 |
#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
|
|
|
12756 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
12757 |
#必填參數:
|
|
|
12758 |
#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
12759 |
$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
|
|
|
12760 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
12761 |
$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
12762 |
#可省略參數
|
|
|
12763 |
#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
|
|
|
12764 |
$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="false";
|
|
|
12765 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
12766 |
#$conf["userDir"]="true";
|
|
|
12767 |
#參考資料來源:
|
|
|
12768 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
12769 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
12770 |
#備註:
|
|
|
12771 |
#函數file_exists檢查的路徑為檔案系統的路徑
|
|
|
12772 |
$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
|
|
|
12773 |
unset($conf["fileAccess::checkMultiFileExist"]);
|
| 226 |
liveuser |
12774 |
|
| 3 |
liveuser |
12775 |
#如果檢查檔案是否存在失敗
|
|
|
12776 |
if($checkMultiFileExist["status"]==="false"){
|
| 226 |
liveuser |
12777 |
|
| 3 |
liveuser |
12778 |
#設置執行失敗
|
|
|
12779 |
$result["status"]="false";
|
| 226 |
liveuser |
12780 |
|
| 3 |
liveuser |
12781 |
#設置執行錯誤訊息
|
|
|
12782 |
$result["error"]=$checkMultiFileExist;
|
| 226 |
liveuser |
12783 |
|
| 3 |
liveuser |
12784 |
#回傳結果
|
|
|
12785 |
return $result;
|
| 226 |
liveuser |
12786 |
|
| 3 |
liveuser |
12787 |
}#if end
|
| 226 |
liveuser |
12788 |
|
| 3 |
liveuser |
12789 |
#如果檔案不存在
|
|
|
12790 |
if($checkMultiFileExist["allExist"]==="false"){
|
| 226 |
liveuser |
12791 |
|
| 3 |
liveuser |
12792 |
#設置執行失敗
|
|
|
12793 |
$result["status"]="false";
|
| 226 |
liveuser |
12794 |
|
| 3 |
liveuser |
12795 |
#設置執行錯誤訊息
|
|
|
12796 |
$result["error"]=$checkMultiFileExist;
|
| 226 |
liveuser |
12797 |
|
| 3 |
liveuser |
12798 |
#回傳結果
|
|
|
12799 |
return $result;
|
| 226 |
liveuser |
12800 |
|
| 3 |
liveuser |
12801 |
}#if end
|
| 226 |
liveuser |
12802 |
|
| 3 |
liveuser |
12803 |
#產生 base64 的 pdf 編碼字串
|
|
|
12804 |
$base64pdf=base64_encode(file_get_contents($conf["file"]));
|
| 226 |
liveuser |
12805 |
|
| 3 |
liveuser |
12806 |
#產生 base64 的 pdf 編碼字串 data
|
|
|
12807 |
$base64pdfData="data:application/pdf;base64,".$base64pdf;
|
| 226 |
liveuser |
12808 |
|
| 3 |
liveuser |
12809 |
#判斷要用哪種方式嵌入pdf
|
|
|
12810 |
switch($conf["type"]){
|
| 226 |
liveuser |
12811 |
|
| 3 |
liveuser |
12812 |
#如果是用 object 方式
|
|
|
12813 |
case "object":
|
| 226 |
liveuser |
12814 |
|
| 3 |
liveuser |
12815 |
#產生嵌入的語法
|
|
|
12816 |
$embedSyntax="<object style=\"width:100%;height:100%;\" data=\"".$base64pdfData."\"></object>";
|
| 226 |
liveuser |
12817 |
|
| 3 |
liveuser |
12818 |
#取得語法
|
|
|
12819 |
$result["content"]=&$embedSyntax;
|
| 226 |
liveuser |
12820 |
|
| 3 |
liveuser |
12821 |
#跳出 switch
|
|
|
12822 |
break;
|
| 226 |
liveuser |
12823 |
|
| 3 |
liveuser |
12824 |
#預設
|
|
|
12825 |
default:
|
| 226 |
liveuser |
12826 |
|
| 3 |
liveuser |
12827 |
#產生嵌入的語法
|
|
|
12828 |
$embedSyntax="<iframe style=\"width:100%;height:100%;\" src=\"".$base64pdfData."\"></iframe>";
|
| 226 |
liveuser |
12829 |
|
| 3 |
liveuser |
12830 |
#取得語法
|
|
|
12831 |
$result["content"]=&$embedSyntax;
|
| 226 |
liveuser |
12832 |
|
| 3 |
liveuser |
12833 |
}#switch end
|
| 226 |
liveuser |
12834 |
|
| 3 |
liveuser |
12835 |
#設置執行正常
|
|
|
12836 |
$result["status"]="true";
|
| 226 |
liveuser |
12837 |
|
| 3 |
liveuser |
12838 |
#回傳結果
|
|
|
12839 |
return $result;
|
| 226 |
liveuser |
12840 |
|
| 3 |
liveuser |
12841 |
}#function embedPdf end
|
| 226 |
liveuser |
12842 |
|
| 3 |
liveuser |
12843 |
/*
|
|
|
12844 |
#函式說明:
|
| 226 |
liveuser |
12845 |
#用linux unzip去解壓縮zip檔案
|
| 3 |
liveuser |
12846 |
#回傳結果:
|
|
|
12847 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
12848 |
#$result["error"],錯誤訊息.
|
|
|
12849 |
#$result["function"],當前執行的函數名稱.
|
|
|
12850 |
#$result["content"]["each"],每個檔案的資訊.
|
|
|
12851 |
#$result["content"]["each"]["Length"][$i],各別檔案目錄的原始長度.
|
|
|
12852 |
#$result["content"]["each"]["Method"][$i],各別檔案目錄的壓縮方法.
|
|
|
12853 |
#$result["content"]["each"]["Size"][$i],各別檔案目錄的壓縮後長度.
|
|
|
12854 |
#$result["content"]["each"]["Cmpr"][$i],各別檔案目錄的壓縮率.
|
|
|
12855 |
#$result["content"]["each"]["Date"][$i],各別檔案目錄的最後修改日期.
|
|
|
12856 |
#$result["content"]["each"]["Time"][$i],各別檔案目錄的最後修改時間.
|
|
|
12857 |
#$result["content"]["each"]["CRC-32"][$i],各別檔案目錄的CRC-32檢查碼.
|
|
|
12858 |
#$result["content"]["each"]["Name"][$i],各別檔案目錄的路徑與名稱.
|
|
|
12859 |
#$result["content"]["total"],統整的資訊.
|
|
|
12860 |
#$result["content"]["Length"],總共的檔案長度.
|
|
|
12861 |
#$result["content"]["Size"],壓縮後的檔案長度.
|
|
|
12862 |
#$result["content"]["Cmpr"],平均壓縮率.
|
|
|
12863 |
#$result["content"]["count"],壓縮檔裡面總共的檔案跟目錄數目.
|
|
|
12864 |
#必填參數;
|
|
|
12865 |
#$conf["zip"],字串,要解壓縮的zip檔案.
|
|
|
12866 |
$conf["zip"]="";
|
|
|
12867 |
#$conf["fileArgu"],字串,__FILE__的內容.
|
|
|
12868 |
$conf["fileArgu"]=__FILE__;
|
|
|
12869 |
#可省略參數:
|
|
|
12870 |
#$conf["extract"],字串,要解壓縮到那個路徑,預設為當前位置"./".
|
|
|
12871 |
#$conf["extract"]="";
|
|
|
12872 |
#備註:
|
|
|
12873 |
#建議加上特定邊碼的支援例如、單
|
|
|
12874 |
*/
|
|
|
12875 |
public static function unzip(&$conf=array()){
|
| 226 |
liveuser |
12876 |
|
| 3 |
liveuser |
12877 |
#初始化要回傳的結果
|
|
|
12878 |
$result=array();
|
|
|
12879 |
|
|
|
12880 |
#取得當前執行的函數名稱
|
|
|
12881 |
$result["function"]=__FUNCTION__;
|
|
|
12882 |
|
|
|
12883 |
#如果沒有參數
|
|
|
12884 |
if(func_num_args()==0){
|
| 226 |
liveuser |
12885 |
|
| 3 |
liveuser |
12886 |
#設置執行失敗
|
|
|
12887 |
$result["status"]="false";
|
| 226 |
liveuser |
12888 |
|
| 3 |
liveuser |
12889 |
#設置執行錯誤訊息
|
|
|
12890 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
12891 |
|
| 3 |
liveuser |
12892 |
#回傳結果
|
|
|
12893 |
return $result;
|
| 226 |
liveuser |
12894 |
|
| 3 |
liveuser |
12895 |
}#if end
|
| 226 |
liveuser |
12896 |
|
| 3 |
liveuser |
12897 |
#取得參數
|
|
|
12898 |
$result["argu"]=$conf;
|
|
|
12899 |
|
|
|
12900 |
#如果 $conf 不為陣列
|
|
|
12901 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
12902 |
|
| 3 |
liveuser |
12903 |
#設置執行失敗
|
|
|
12904 |
$result["status"]="false";
|
| 226 |
liveuser |
12905 |
|
| 3 |
liveuser |
12906 |
#設置執行錯誤訊息
|
|
|
12907 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
12908 |
|
| 3 |
liveuser |
12909 |
#如果傳入的參數為 null
|
|
|
12910 |
if($conf===null){
|
| 226 |
liveuser |
12911 |
|
| 3 |
liveuser |
12912 |
#設置執行錯誤訊息
|
|
|
12913 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
12914 |
|
| 3 |
liveuser |
12915 |
}#if end
|
|
|
12916 |
|
|
|
12917 |
#回傳結果
|
|
|
12918 |
return $result;
|
| 226 |
liveuser |
12919 |
|
| 3 |
liveuser |
12920 |
}#if end
|
| 226 |
liveuser |
12921 |
|
| 3 |
liveuser |
12922 |
#檢查參數
|
|
|
12923 |
#函式說明:
|
|
|
12924 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
12925 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
12926 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
12927 |
#$result["function"],當前執行的函式名稱.
|
|
|
12928 |
#$result["argu"],設置給予的參數.
|
|
|
12929 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
12930 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
12931 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
12932 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
12933 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
12934 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
12935 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
12936 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
12937 |
#必填寫的參數:
|
|
|
12938 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
| 226 |
liveuser |
12939 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
| 3 |
liveuser |
12940 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
12941 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
12942 |
#可以省略的參數:
|
|
|
12943 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
12944 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("zip","fileArgu");
|
|
|
12945 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
12946 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
12947 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
12948 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
12949 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
12950 |
$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("zip","fileArgu");
|
|
|
12951 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
12952 |
#$conf["canBeEmpty"]=array();
|
|
|
12953 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
12954 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("extract");
|
|
|
12955 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
12956 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("extract");
|
| 226 |
liveuser |
12957 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
12958 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
12959 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
12960 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("./");
|
|
|
12961 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
12962 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
12963 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
12964 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
12965 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
12966 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
12967 |
#參考資料來源:
|
|
|
12968 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
12969 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
12970 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
12971 |
|
| 3 |
liveuser |
12972 |
#如果檢查參數失敗
|
|
|
12973 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
12974 |
|
| 3 |
liveuser |
12975 |
#設置執行不正常
|
|
|
12976 |
$result["status"]="false";
|
| 226 |
liveuser |
12977 |
|
| 3 |
liveuser |
12978 |
#設置錯誤訊息
|
|
|
12979 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
12980 |
|
| 3 |
liveuser |
12981 |
#回傳結果
|
|
|
12982 |
return $result;
|
| 226 |
liveuser |
12983 |
|
| 3 |
liveuser |
12984 |
}#if end
|
| 226 |
liveuser |
12985 |
|
| 3 |
liveuser |
12986 |
#如果檢查參數不通過
|
|
|
12987 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
12988 |
|
| 3 |
liveuser |
12989 |
#設置執行不正常
|
|
|
12990 |
$result["status"]="false";
|
| 226 |
liveuser |
12991 |
|
| 3 |
liveuser |
12992 |
#設置錯誤訊息
|
|
|
12993 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
12994 |
|
| 3 |
liveuser |
12995 |
#回傳結果
|
|
|
12996 |
return $result;
|
| 226 |
liveuser |
12997 |
|
| 3 |
liveuser |
12998 |
}#if end
|
| 226 |
liveuser |
12999 |
|
| 3 |
liveuser |
13000 |
#檢查要解壓縮的檔案是否存在
|
|
|
13001 |
#函式說明:
|
|
|
13002 |
#檢查多個檔案與資料夾是否存在.
|
|
|
13003 |
#回傳的結果:
|
|
|
13004 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
13005 |
#$result["error"],錯誤訊息陣列.
|
|
|
13006 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
13007 |
#$result["argu"],使用的參數.
|
|
|
13008 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
13009 |
#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
|
|
|
13010 |
#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
|
|
|
13011 |
#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
|
|
|
13012 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
13013 |
#必填參數:
|
|
|
13014 |
#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
13015 |
$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["zip"]);
|
|
|
13016 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
13017 |
$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
13018 |
#可省略參數
|
|
|
13019 |
#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
|
|
|
13020 |
#$conf["disableWebSearch"]="false";
|
|
|
13021 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
13022 |
#$conf["userDir"]="true";
|
|
|
13023 |
#參考資料來源:
|
|
|
13024 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
13025 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
13026 |
#備註:
|
|
|
13027 |
#函數file_exists檢查的路徑為檔案系統的路徑
|
|
|
13028 |
$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
|
|
|
13029 |
unset($conf["fileAccess::checkMultiFileExist"]);
|
| 226 |
liveuser |
13030 |
|
| 3 |
liveuser |
13031 |
#如果檢查檔案是否存在失敗
|
|
|
13032 |
if($checkMultiFileExist["status"]==="false"){
|
| 226 |
liveuser |
13033 |
|
| 3 |
liveuser |
13034 |
#設置執行不正常
|
|
|
13035 |
$result["status"]="false";
|
| 226 |
liveuser |
13036 |
|
| 3 |
liveuser |
13037 |
#設置錯誤訊息
|
|
|
13038 |
$result["error"]=$checkMultiFileExist;
|
| 226 |
liveuser |
13039 |
|
| 3 |
liveuser |
13040 |
#回傳結果
|
|
|
13041 |
return $result;
|
| 226 |
liveuser |
13042 |
|
| 3 |
liveuser |
13043 |
}#if end
|
| 226 |
liveuser |
13044 |
|
| 3 |
liveuser |
13045 |
#如果要解壓縮的檔案不存在
|
|
|
13046 |
if($checkMultiFileExist["allExist"]==="false"){
|
| 226 |
liveuser |
13047 |
|
| 3 |
liveuser |
13048 |
#設置執行不正常
|
|
|
13049 |
$result["status"]="false";
|
| 226 |
liveuser |
13050 |
|
| 3 |
liveuser |
13051 |
#設置錯誤訊息
|
|
|
13052 |
$result["error"]=$checkMultiFileExist;
|
| 226 |
liveuser |
13053 |
|
| 3 |
liveuser |
13054 |
#回傳結果
|
|
|
13055 |
return $result;
|
| 226 |
liveuser |
13056 |
|
| 3 |
liveuser |
13057 |
}#if end
|
| 226 |
liveuser |
13058 |
|
| 3 |
liveuser |
13059 |
#函式說明:
|
|
|
13060 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
13061 |
#回傳結果:
|
|
|
13062 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
13063 |
#$result["error"],錯誤訊息陣列.
|
|
|
13064 |
#$result["function"],當前執行的函數名稱.
|
|
|
13065 |
#$result["argu"],使用的參數.
|
|
|
13066 |
#$result["cmd"],執行的指令內容.
|
|
|
13067 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
13068 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
13069 |
#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
13070 |
#$result["running"],是否還在執行.
|
|
|
13071 |
#$result["pid"],pid
|
|
|
13072 |
#必填參數:
|
|
|
13073 |
#$conf["command"],字串,要執行的指令與.
|
|
|
13074 |
$conf["external::callShell"]["command"]="unzip";
|
|
|
13075 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
| 226 |
liveuser |
13076 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
| 3 |
liveuser |
13077 |
#可省略參數:
|
|
|
13078 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
13079 |
$conf["external::callShell"]["argu"]=array("-d",$conf["extract"],"-o","-q",$conf["zip"]);
|
|
|
13080 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
13081 |
#$conf["arguIsAddr"]=array();
|
|
|
13082 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
13083 |
#$conf["enablePrintDescription"]="true";
|
|
|
13084 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
|
|
|
13085 |
#$conf["printDescription"]="";
|
|
|
13086 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
|
|
|
13087 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
13088 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
13089 |
#$conf["username"]="";
|
|
|
13090 |
#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
13091 |
#$conf["password"]="";
|
|
|
13092 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
13093 |
#$conf["useScript"]="";
|
|
|
13094 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
13095 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
13096 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
13097 |
#$conf["inBackGround"]="";
|
|
|
13098 |
#備註:
|
|
|
13099 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
13100 |
#參考資料:
|
|
|
13101 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
13102 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
13103 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
13104 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
13105 |
unset($conf["external::callShell"]);
|
| 226 |
liveuser |
13106 |
|
| 3 |
liveuser |
13107 |
#如果執行cmd失敗
|
|
|
13108 |
if($callShell["status"]==="false"){
|
| 226 |
liveuser |
13109 |
|
| 3 |
liveuser |
13110 |
#設置執行不正常
|
|
|
13111 |
$result["status"]="false";
|
| 226 |
liveuser |
13112 |
|
| 3 |
liveuser |
13113 |
#設置錯誤訊息
|
|
|
13114 |
$result["error"]=$callShell;
|
| 226 |
liveuser |
13115 |
|
| 3 |
liveuser |
13116 |
#回傳結果
|
|
|
13117 |
return $result;
|
| 226 |
liveuser |
13118 |
|
| 3 |
liveuser |
13119 |
}#if end
|
| 226 |
liveuser |
13120 |
|
| 3 |
liveuser |
13121 |
#函式說明:
|
|
|
13122 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
13123 |
#回傳的結果:
|
|
|
13124 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
13125 |
#$result["error"],錯誤訊息陣列.
|
|
|
13126 |
#$result["function"],當前執行的函數名稱.
|
|
|
13127 |
#$result["argu"],使用的參數.
|
|
|
13128 |
#$result["cmd"],執行的指令內容.
|
|
|
13129 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
13130 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
13131 |
#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
13132 |
#$result["running"],是否還在執行.
|
|
|
13133 |
#$result["pid"],pid
|
|
|
13134 |
#必填的參數
|
|
|
13135 |
#$conf["command"],字串,要執行的指令與.
|
|
|
13136 |
$conf["external::callShell"]["command"]="unzip";
|
|
|
13137 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
| 226 |
liveuser |
13138 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
| 3 |
liveuser |
13139 |
#可省略參數:
|
|
|
13140 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
13141 |
$conf["external::callShell"]["argu"]=array("-v",$conf["zip"]);
|
|
|
13142 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
13143 |
#$conf["arguIsAddr"]=array();
|
|
|
13144 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
13145 |
#$conf["enablePrintDescription"]="true";
|
|
|
13146 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
|
|
|
13147 |
#$conf["printDescription"]="";
|
|
|
13148 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
|
|
|
13149 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
13150 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
13151 |
#$conf["username"]="";
|
|
|
13152 |
#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
13153 |
#$conf["password"]="";
|
|
|
13154 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
13155 |
#$conf["useScript"]="";
|
|
|
13156 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
13157 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
13158 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
13159 |
#$conf["inBackGround"]="";
|
|
|
13160 |
#備註:
|
|
|
13161 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
13162 |
#參考資料:
|
|
|
13163 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
13164 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
13165 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
13166 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
13167 |
unset($conf["external::callShell"]);
|
| 226 |
liveuser |
13168 |
|
| 3 |
liveuser |
13169 |
#如果執行cmd失敗
|
|
|
13170 |
if($callShell["status"]==="false"){
|
| 226 |
liveuser |
13171 |
|
| 3 |
liveuser |
13172 |
#設置執行不正常
|
|
|
13173 |
$result["status"]="false";
|
| 226 |
liveuser |
13174 |
|
| 3 |
liveuser |
13175 |
#設置錯誤訊息
|
|
|
13176 |
$result["error"]=$callShell;
|
| 226 |
liveuser |
13177 |
|
| 3 |
liveuser |
13178 |
#回傳結果
|
|
|
13179 |
return $result;
|
| 226 |
liveuser |
13180 |
|
|
|
13181 |
}#if end
|
|
|
13182 |
|
| 3 |
liveuser |
13183 |
#取得輸出的內容陣列
|
|
|
13184 |
$unzipInfo=$callShell["output"];
|
| 226 |
liveuser |
13185 |
|
| 3 |
liveuser |
13186 |
/*
|
| 226 |
liveuser |
13187 |
|
| 3 |
liveuser |
13188 |
Length Method Size Cmpr Date Time CRC-32 Name
|
|
|
13189 |
-------- ------ ------- ---- ---------- ----- -------- ----
|
|
|
13190 |
4194304 Defl:X 2507269 40% 05-04-2002 17:30 9386a740 PS2 Bios 30004R V6 Pal.bin
|
|
|
13191 |
4 Defl:X 6 -50% 05-15-2005 06:45 054a6ec2 PS2 Bios 30004R V6 Pal.MEC
|
|
|
13192 |
1024 Defl:X 22 98% 06-25-2005 14:55 3493bb06 PS2 Bios 30004R V6 Pal.NVM
|
|
|
13193 |
199680 Defl:X 70524 65% 06-02-2004 16:50 2c3bcd32 rom1.bin
|
|
|
13194 |
4194304 Defl:X 2637496 37% 02-20-2005 21:12 6f8e3c29 SCPH-70004_BIOS_V12_PAL_200.BIN
|
|
|
13195 |
3145728 Defl:X 3138427 0% 02-20-2005 21:12 bf3cbc65 SCPH-70004_BIOS_V12_PAL_200.EROM
|
|
|
13196 |
1024 Defl:X 706 31% 02-20-2005 21:12 a8d51ead SCPH-70004_BIOS_V12_PAL_200.NVM
|
|
|
13197 |
524288 Defl:X 149924 71% 02-20-2005 21:12 0e8797c0 SCPH-70004_BIOS_V12_PAL_200.ROM1
|
|
|
13198 |
524288 Defl:X 149924 71% 02-20-2005 21:12 0e8797c0 SCPH-70004_BIOS_V12_PAL_200.ROM2
|
|
|
13199 |
4194304 Defl:X 2213105 47% 10-18-2000 06:06 b7ef81a9 scph10000.bin
|
|
|
13200 |
1024 Defl:X 11 99% 01-01-2005 00:42 efb5af2e scph10000.NVM
|
|
|
13201 |
4194304 Defl:X 2511182 40% 06-27-2003 10:51 a19e0bf5 scph39001.bin
|
|
|
13202 |
4 Defl:X 6 -50% 05-14-2005 16:00 054a6ec2 scph39001.MEC
|
|
|
13203 |
1024 Defl:X 20 98% 05-31-2005 16:09 e14a6cd6 scph39001.NVM
|
|
|
13204 |
-------- ------- --- -------
|
|
|
13205 |
21175304 13378622 37% 14 files
|
| 226 |
liveuser |
13206 |
|
| 3 |
liveuser |
13207 |
*/
|
| 226 |
liveuser |
13208 |
|
| 3 |
liveuser |
13209 |
#取得行數
|
|
|
13210 |
$lineCount=count($unzipInfo);
|
| 226 |
liveuser |
13211 |
|
| 3 |
liveuser |
13212 |
#取得標題
|
|
|
13213 |
#函式說明:
|
|
|
13214 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
13215 |
#回傳結果:
|
|
|
13216 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
13217 |
#$result["error"],錯誤訊息陣列
|
|
|
13218 |
#$result["function"],當前執行的函數名稱.
|
|
|
13219 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
13220 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
13221 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
13222 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
13223 |
#必填參數:
|
|
|
13224 |
$conf["stringProcess::spiltString"]["stringIn"]=$unzipInfo[1];#要處理的字串。
|
|
|
13225 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
|
|
|
13226 |
#可省略參數:
|
|
|
13227 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
13228 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
13229 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
13230 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
13231 |
|
| 3 |
liveuser |
13232 |
#如果分割字串失敗
|
|
|
13233 |
if($spiltString["status"]==="false"){
|
| 226 |
liveuser |
13234 |
|
| 3 |
liveuser |
13235 |
#設置執行不正常
|
|
|
13236 |
$result["status"]="false";
|
| 226 |
liveuser |
13237 |
|
| 3 |
liveuser |
13238 |
#設置錯誤訊息
|
|
|
13239 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
13240 |
|
| 3 |
liveuser |
13241 |
#回傳結果
|
|
|
13242 |
return $result;
|
| 226 |
liveuser |
13243 |
|
| 3 |
liveuser |
13244 |
}#if end
|
| 226 |
liveuser |
13245 |
|
| 3 |
liveuser |
13246 |
#如果沒有分割用的關鍵字
|
|
|
13247 |
if($spiltString["found"]==="false"){
|
| 226 |
liveuser |
13248 |
|
| 3 |
liveuser |
13249 |
#設置執行不正常
|
|
|
13250 |
$result["status"]="false";
|
| 226 |
liveuser |
13251 |
|
| 3 |
liveuser |
13252 |
#設置錯誤訊息
|
|
|
13253 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
13254 |
|
| 3 |
liveuser |
13255 |
#回傳結果
|
|
|
13256 |
return $result;
|
| 226 |
liveuser |
13257 |
|
| 3 |
liveuser |
13258 |
}#if end
|
| 226 |
liveuser |
13259 |
|
| 3 |
liveuser |
13260 |
#取得標題欄位
|
| 226 |
liveuser |
13261 |
$titles=$spiltString["dataArray"];
|
|
|
13262 |
|
| 3 |
liveuser |
13263 |
#取得標題欄位數目
|
|
|
13264 |
$titleCount=$spiltString["dataCounts"];
|
| 226 |
liveuser |
13265 |
|
| 3 |
liveuser |
13266 |
#針對每列輸出
|
|
|
13267 |
for($i=3;$i<$lineCount-2;$i++){
|
| 226 |
liveuser |
13268 |
|
| 3 |
liveuser |
13269 |
#取得各欄位的內容
|
|
|
13270 |
#函式說明:
|
|
|
13271 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
13272 |
#回傳結果:
|
|
|
13273 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
13274 |
#$result["error"],錯誤訊息陣列
|
|
|
13275 |
#$result["function"],當前執行的函數名稱.
|
|
|
13276 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
13277 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
13278 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
13279 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
13280 |
#必填參數:
|
|
|
13281 |
$conf["stringProcess::spiltString"]["stringIn"]=$unzipInfo[$i];#要處理的字串。
|
|
|
13282 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
|
|
|
13283 |
#可省略參數:
|
|
|
13284 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
13285 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
13286 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
13287 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
13288 |
|
| 3 |
liveuser |
13289 |
#如果分割字串失敗
|
|
|
13290 |
if($spiltString["status"]==="false"){
|
| 226 |
liveuser |
13291 |
|
| 3 |
liveuser |
13292 |
#設置執行不正常
|
|
|
13293 |
$result["status"]="false";
|
| 226 |
liveuser |
13294 |
|
| 3 |
liveuser |
13295 |
#設置錯誤訊息
|
|
|
13296 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
13297 |
|
| 3 |
liveuser |
13298 |
#回傳結果
|
|
|
13299 |
return $result;
|
| 226 |
liveuser |
13300 |
|
| 3 |
liveuser |
13301 |
}#if end
|
| 226 |
liveuser |
13302 |
|
| 3 |
liveuser |
13303 |
#如果沒有分割用的關鍵字
|
|
|
13304 |
if($spiltString["found"]==="false"){
|
| 226 |
liveuser |
13305 |
|
| 3 |
liveuser |
13306 |
#設置執行不正常
|
|
|
13307 |
$result["status"]="false";
|
| 226 |
liveuser |
13308 |
|
| 3 |
liveuser |
13309 |
#設置錯誤訊息
|
|
|
13310 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
13311 |
|
| 3 |
liveuser |
13312 |
#回傳結果
|
|
|
13313 |
return $result;
|
| 226 |
liveuser |
13314 |
|
| 3 |
liveuser |
13315 |
}#if end
|
| 226 |
liveuser |
13316 |
|
| 3 |
liveuser |
13317 |
#取得各欄位的內容
|
|
|
13318 |
$cols=$spiltString["dataArray"];
|
| 226 |
liveuser |
13319 |
|
| 3 |
liveuser |
13320 |
#取得欄位的數目
|
|
|
13321 |
$colsCount=$spiltString["dataCounts"];
|
| 226 |
liveuser |
13322 |
|
| 3 |
liveuser |
13323 |
#如果實際抓出的內容欄位數量大於標題欄位數量,代表檔案/目錄名稱含有空格
|
|
|
13324 |
if($colsCount>$titleCount){
|
| 226 |
liveuser |
13325 |
|
| 3 |
liveuser |
13326 |
#新的檔案名稱
|
|
|
13327 |
$newFileName="";
|
| 226 |
liveuser |
13328 |
|
| 3 |
liveuser |
13329 |
#針對每個多出的欄位
|
|
|
13330 |
for($j=$titleCount;$j<$colsCount;$j++){
|
| 226 |
liveuser |
13331 |
|
| 3 |
liveuser |
13332 |
#串接屬於檔案名稱的部分
|
|
|
13333 |
$newFileName=$newFileName.$cols[$j];
|
| 226 |
liveuser |
13334 |
|
| 3 |
liveuser |
13335 |
#如果不是最後一個項目
|
|
|
13336 |
if($j!==$colsCount-1){
|
| 226 |
liveuser |
13337 |
|
| 3 |
liveuser |
13338 |
#增加空格
|
|
|
13339 |
$newFileName=$newFileName." ";
|
| 226 |
liveuser |
13340 |
|
| 3 |
liveuser |
13341 |
}#if end
|
| 226 |
liveuser |
13342 |
|
| 3 |
liveuser |
13343 |
}#for end
|
| 226 |
liveuser |
13344 |
|
| 3 |
liveuser |
13345 |
#取代成對的檔案名稱
|
|
|
13346 |
$cols[$titleCount-1]=$newFileName;
|
| 226 |
liveuser |
13347 |
|
| 3 |
liveuser |
13348 |
}#if end
|
| 226 |
liveuser |
13349 |
|
| 3 |
liveuser |
13350 |
#針對每個欄位
|
|
|
13351 |
for($j=0;$j<$titleCount;$j++){
|
| 226 |
liveuser |
13352 |
|
| 3 |
liveuser |
13353 |
#取得欄位內容
|
|
|
13354 |
$result["content"]["each"][$titles[$j]][]=$cols[$j];
|
| 226 |
liveuser |
13355 |
|
| 3 |
liveuser |
13356 |
}#for end
|
| 226 |
liveuser |
13357 |
|
| 3 |
liveuser |
13358 |
}#for end
|
| 226 |
liveuser |
13359 |
|
| 3 |
liveuser |
13360 |
#取得 total 的輸出內容
|
|
|
13361 |
#函式說明:
|
|
|
13362 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
13363 |
#回傳結果:
|
|
|
13364 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
13365 |
#$result["error"],錯誤訊息陣列
|
|
|
13366 |
#$result["function"],當前執行的函數名稱.
|
|
|
13367 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
13368 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
13369 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
13370 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
13371 |
#必填參數:
|
|
|
13372 |
$conf["stringProcess::spiltString"]["stringIn"]=$unzipInfo[$lineCount-1];#要處理的字串。
|
|
|
13373 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
|
|
|
13374 |
#可省略參數:
|
|
|
13375 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
13376 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
13377 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
13378 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
13379 |
|
| 3 |
liveuser |
13380 |
#如果分割字串失敗
|
|
|
13381 |
if($spiltString["status"]==="false"){
|
| 226 |
liveuser |
13382 |
|
| 3 |
liveuser |
13383 |
#設置執行不正常
|
|
|
13384 |
$result["status"]="false";
|
| 226 |
liveuser |
13385 |
|
| 3 |
liveuser |
13386 |
#設置錯誤訊息
|
|
|
13387 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
13388 |
|
| 3 |
liveuser |
13389 |
#回傳結果
|
|
|
13390 |
return $result;
|
| 226 |
liveuser |
13391 |
|
| 3 |
liveuser |
13392 |
}#if end
|
| 226 |
liveuser |
13393 |
|
| 3 |
liveuser |
13394 |
#如果沒有分割用的關鍵字
|
|
|
13395 |
if($spiltString["found"]==="false"){
|
| 226 |
liveuser |
13396 |
|
| 3 |
liveuser |
13397 |
#設置執行不正常
|
|
|
13398 |
$result["status"]="false";
|
| 226 |
liveuser |
13399 |
|
| 3 |
liveuser |
13400 |
#設置錯誤訊息
|
|
|
13401 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
13402 |
|
| 3 |
liveuser |
13403 |
#回傳結果
|
|
|
13404 |
return $result;
|
| 226 |
liveuser |
13405 |
|
| 3 |
liveuser |
13406 |
}#if end
|
| 226 |
liveuser |
13407 |
|
| 3 |
liveuser |
13408 |
#取得各欄位的內容
|
|
|
13409 |
$cols=$spiltString["dataArray"];
|
| 226 |
liveuser |
13410 |
|
| 3 |
liveuser |
13411 |
#取得總共的檔案長度
|
|
|
13412 |
$result["content"]["total"][$titles[0]]=$cols[0];
|
| 226 |
liveuser |
13413 |
|
| 3 |
liveuser |
13414 |
#取得壓縮時的總共檔案長度
|
|
|
13415 |
$result["content"]["total"][$titles[2]]=$cols[1];
|
| 226 |
liveuser |
13416 |
|
| 3 |
liveuser |
13417 |
#取得壓縮時的總共檔案長度
|
|
|
13418 |
$result["content"]["total"][$titles[3]]=$cols[2];
|
| 226 |
liveuser |
13419 |
|
| 3 |
liveuser |
13420 |
#取得解壓縮出了多少檔案跟目錄
|
|
|
13421 |
$result["content"]["total"]["count"]=explode(" ",$cols[3])[0];
|
| 226 |
liveuser |
13422 |
|
| 3 |
liveuser |
13423 |
#設置執行正常
|
|
|
13424 |
$result["status"]="true";
|
| 226 |
liveuser |
13425 |
|
| 3 |
liveuser |
13426 |
#回傳結果
|
|
|
13427 |
return $result;
|
| 226 |
liveuser |
13428 |
|
| 3 |
liveuser |
13429 |
}#function unzip end
|
| 226 |
liveuser |
13430 |
|
| 3 |
liveuser |
13431 |
/*
|
|
|
13432 |
#函式說明:
|
|
|
13433 |
#接收Range: bytes=0-499格式的header, 輸出檔案的片段或完整檔案.
|
|
|
13434 |
#回傳結果:
|
|
|
13435 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
13436 |
#$result["error"],錯誤訊息.
|
|
|
13437 |
#$result["function"],當前執行的函式名稱.
|
|
|
13438 |
#必填參數:
|
|
|
13439 |
#$conf["filePath"],字串,檔案的路徑.
|
|
|
13440 |
$conf["filePath"]="";
|
|
|
13441 |
#可省略參數:
|
|
|
13442 |
#$conf["fileName"],字串,顯示的檔案名稱,預設為basename($conf["filePath"]);
|
|
|
13443 |
#$conf["fileName"]="";
|
|
|
13444 |
#參考資料:
|
|
|
13445 |
#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/
|
|
|
13446 |
#http://php.net/manual/en/function.filemtime.php
|
|
|
13447 |
#http://php.net/manual/en/function.connection-status.php
|
|
|
13448 |
#http://php.net/manual/en/function.fread.php
|
|
|
13449 |
#備註:
|
|
|
13450 |
#請勿在運行該函式前印出任何內容,這是要給用戶端接收的內容.
|
|
|
13451 |
*/
|
|
|
13452 |
public static function partDownload(&$conf=array()){
|
| 226 |
liveuser |
13453 |
|
| 3 |
liveuser |
13454 |
#初始化要回傳的結果
|
|
|
13455 |
$result=array();
|
|
|
13456 |
|
|
|
13457 |
#取得當前執行的函數名稱
|
|
|
13458 |
$result["function"]=__FUNCTION__;
|
|
|
13459 |
|
|
|
13460 |
#如果沒有參數
|
|
|
13461 |
if(func_num_args()==0){
|
| 226 |
liveuser |
13462 |
|
| 3 |
liveuser |
13463 |
#設置執行失敗
|
|
|
13464 |
$result["status"]="false";
|
| 226 |
liveuser |
13465 |
|
| 3 |
liveuser |
13466 |
#設置執行錯誤訊息
|
|
|
13467 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
13468 |
|
| 3 |
liveuser |
13469 |
#回傳結果
|
|
|
13470 |
return $result;
|
| 226 |
liveuser |
13471 |
|
| 3 |
liveuser |
13472 |
}#if end
|
| 226 |
liveuser |
13473 |
|
| 3 |
liveuser |
13474 |
#取得參數
|
|
|
13475 |
$result["argu"]=$conf;
|
|
|
13476 |
|
|
|
13477 |
#如果 $conf 不為陣列
|
|
|
13478 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
13479 |
|
| 3 |
liveuser |
13480 |
#設置執行失敗
|
|
|
13481 |
$result["status"]="false";
|
| 226 |
liveuser |
13482 |
|
| 3 |
liveuser |
13483 |
#設置執行錯誤訊息
|
|
|
13484 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
13485 |
|
| 3 |
liveuser |
13486 |
#如果傳入的參數為 null
|
|
|
13487 |
if($conf===null){
|
| 226 |
liveuser |
13488 |
|
| 3 |
liveuser |
13489 |
#設置執行錯誤訊息
|
|
|
13490 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
13491 |
|
| 3 |
liveuser |
13492 |
}#if end
|
|
|
13493 |
|
|
|
13494 |
#回傳結果
|
|
|
13495 |
return $result;
|
| 226 |
liveuser |
13496 |
|
| 3 |
liveuser |
13497 |
}#if end
|
| 226 |
liveuser |
13498 |
|
| 3 |
liveuser |
13499 |
#檢查參數
|
|
|
13500 |
#函式說明:
|
|
|
13501 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
13502 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
13503 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
13504 |
#$result["function"],當前執行的函式名稱.
|
|
|
13505 |
#$result["argu"],設置給予的參數.
|
|
|
13506 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
13507 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
13508 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
13509 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
13510 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
13511 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
13512 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
13513 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
13514 |
#必填寫的參數:
|
|
|
13515 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
| 226 |
liveuser |
13516 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
| 3 |
liveuser |
13517 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
13518 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
13519 |
#可以省略的參數:
|
|
|
13520 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
13521 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("filePath");
|
|
|
13522 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
13523 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
13524 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
13525 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
13526 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
13527 |
#$conf["canNotBeEmpty"]=array();
|
|
|
13528 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
13529 |
#$conf["canBeEmpty"]=array();
|
|
|
13530 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
13531 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("fileName");
|
|
|
13532 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
13533 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileName");
|
| 226 |
liveuser |
13534 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
13535 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
13536 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
13537 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
|
|
|
13538 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
13539 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
13540 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
13541 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
13542 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
13543 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
13544 |
#參考資料來源:
|
|
|
13545 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
13546 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
13547 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
13548 |
|
| 3 |
liveuser |
13549 |
#如果檢查參數失敗
|
|
|
13550 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
13551 |
|
| 3 |
liveuser |
13552 |
#設置執行失敗
|
|
|
13553 |
$result["status"]="false";
|
| 226 |
liveuser |
13554 |
|
| 3 |
liveuser |
13555 |
#設置執行錯誤
|
|
|
13556 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
13557 |
|
| 3 |
liveuser |
13558 |
#回傳結果
|
|
|
13559 |
return $result;
|
| 226 |
liveuser |
13560 |
|
| 3 |
liveuser |
13561 |
}#if end
|
| 226 |
liveuser |
13562 |
|
| 3 |
liveuser |
13563 |
#如果檢查參數不通過
|
|
|
13564 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
13565 |
|
| 3 |
liveuser |
13566 |
#設置執行失敗
|
|
|
13567 |
$result["status"]="false";
|
| 226 |
liveuser |
13568 |
|
| 3 |
liveuser |
13569 |
#設置執行錯誤
|
|
|
13570 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
13571 |
|
| 3 |
liveuser |
13572 |
#回傳結果
|
|
|
13573 |
return $result;
|
| 226 |
liveuser |
13574 |
|
| 3 |
liveuser |
13575 |
}#if end
|
| 226 |
liveuser |
13576 |
|
| 3 |
liveuser |
13577 |
#如果沒有設置 $conf["fileName"]
|
|
|
13578 |
if(!isset($conf["fileName"])){
|
| 226 |
liveuser |
13579 |
|
| 3 |
liveuser |
13580 |
#取得檔案名稱
|
|
|
13581 |
$filename=basename($conf["filePath"]);
|
| 226 |
liveuser |
13582 |
|
| 3 |
liveuser |
13583 |
}#if end
|
| 226 |
liveuser |
13584 |
|
| 3 |
liveuser |
13585 |
#反之
|
|
|
13586 |
else{
|
| 226 |
liveuser |
13587 |
|
| 3 |
liveuser |
13588 |
#取得設定好的檔案名稱
|
|
|
13589 |
$filename=&$conf["fileName"];
|
| 226 |
liveuser |
13590 |
|
| 3 |
liveuser |
13591 |
}#else end
|
| 226 |
liveuser |
13592 |
|
| 3 |
liveuser |
13593 |
#取得檔案路徑
|
|
|
13594 |
$location=$conf["filePath"];
|
|
|
13595 |
|
|
|
13596 |
#取得mimetype
|
|
|
13597 |
$mimetype=mime_content_type($location);
|
| 226 |
liveuser |
13598 |
|
| 3 |
liveuser |
13599 |
#如果檔案不存在
|
|
|
13600 |
if(!file_exists($location)){
|
| 226 |
liveuser |
13601 |
|
| 3 |
liveuser |
13602 |
#提示找不到檔案
|
|
|
13603 |
header("HTTP/1.1 404 Not Found");
|
| 226 |
liveuser |
13604 |
|
| 3 |
liveuser |
13605 |
#設置執行失敗
|
|
|
13606 |
$result["status"]="false";
|
| 226 |
liveuser |
13607 |
|
| 3 |
liveuser |
13608 |
#設置錯誤訊息
|
|
|
13609 |
$result["error"][]="檔案 ".$location." 不存在.";
|
| 226 |
liveuser |
13610 |
|
| 3 |
liveuser |
13611 |
#回傳結果
|
|
|
13612 |
return $result;
|
| 226 |
liveuser |
13613 |
|
| 3 |
liveuser |
13614 |
}#if end
|
|
|
13615 |
|
|
|
13616 |
#取得檔案的bytes長度
|
|
|
13617 |
$size = filesize($location);
|
| 226 |
liveuser |
13618 |
|
| 3 |
liveuser |
13619 |
#取得檔案的最後變更日期
|
|
|
13620 |
$time = date('r', filemtime($location));
|
|
|
13621 |
|
|
|
13622 |
#讀取檔案的2元碼內容
|
|
|
13623 |
$fm = @fopen($location, 'rb');
|
| 226 |
liveuser |
13624 |
|
| 3 |
liveuser |
13625 |
#如果開啟檔案失敗
|
|
|
13626 |
if(!$fm){
|
| 226 |
liveuser |
13627 |
|
| 3 |
liveuser |
13628 |
#提示錯誤
|
|
|
13629 |
header("HTTP/1.1 505 Internal server error");
|
| 226 |
liveuser |
13630 |
|
| 3 |
liveuser |
13631 |
#設置執行失敗
|
|
|
13632 |
$result["status"]="false";
|
| 226 |
liveuser |
13633 |
|
| 3 |
liveuser |
13634 |
#設置錯誤訊息
|
|
|
13635 |
$result["error"][]="開啟檔案 ".$location." 失敗.";
|
| 226 |
liveuser |
13636 |
|
| 3 |
liveuser |
13637 |
#回傳結果
|
|
|
13638 |
return $result;
|
| 226 |
liveuser |
13639 |
|
| 3 |
liveuser |
13640 |
}#if end
|
|
|
13641 |
|
|
|
13642 |
#初始化要提供的bytes長度起始點
|
|
|
13643 |
$begin = 0;
|
| 226 |
liveuser |
13644 |
|
| 3 |
liveuser |
13645 |
#初始化要提供的bytes長度結束點
|
|
|
13646 |
$end = $size - 1;
|
|
|
13647 |
|
|
|
13648 |
#如果有接收到 'HTTP_RANGE' 的 header 訊息
|
|
|
13649 |
if(isset($_SERVER['HTTP_RANGE'])){
|
| 226 |
liveuser |
13650 |
|
| 3 |
liveuser |
13651 |
#接收到的範例
|
| 226 |
liveuser |
13652 |
#Range: bytes=0-499
|
|
|
13653 |
|
| 3 |
liveuser |
13654 |
#取得要求的bytes位置範圍
|
|
|
13655 |
sscanf($_SERVER['HTTP_RANGE'], "bytes=%d-%d",$begin,$end);
|
| 226 |
liveuser |
13656 |
|
| 3 |
liveuser |
13657 |
#如果 $begin 或 $end 有缺
|
|
|
13658 |
if(!isset($begin) || !isset($end)){
|
| 226 |
liveuser |
13659 |
|
| 3 |
liveuser |
13660 |
#設置執行失敗
|
|
|
13661 |
$result["status"]="false";
|
| 226 |
liveuser |
13662 |
|
| 3 |
liveuser |
13663 |
#設置錯誤訊息
|
|
|
13664 |
$result["error"][]="header \"Range\" 的數值格式為 \"bytes=0-499\"";
|
| 226 |
liveuser |
13665 |
|
| 3 |
liveuser |
13666 |
#回傳結果
|
|
|
13667 |
return $result;
|
| 226 |
liveuser |
13668 |
|
| 3 |
liveuser |
13669 |
}#if end
|
| 226 |
liveuser |
13670 |
|
| 3 |
liveuser |
13671 |
#如果 $begin 沒有小於等於 $end
|
|
|
13672 |
if(!($begin<=$end)){
|
| 226 |
liveuser |
13673 |
|
| 3 |
liveuser |
13674 |
#設置執行失敗
|
|
|
13675 |
$result["status"]="false";
|
| 226 |
liveuser |
13676 |
|
| 3 |
liveuser |
13677 |
#設置錯誤訊息
|
|
|
13678 |
$result["error"][]="header \"Range\" 的數值格式為 \"bytes=0-499\"";
|
| 226 |
liveuser |
13679 |
|
| 3 |
liveuser |
13680 |
#回傳結果
|
|
|
13681 |
return $result;
|
| 226 |
liveuser |
13682 |
|
| 3 |
liveuser |
13683 |
}#if end
|
| 226 |
liveuser |
13684 |
|
| 3 |
liveuser |
13685 |
}#if end
|
| 226 |
liveuser |
13686 |
|
| 3 |
liveuser |
13687 |
#提示 200 ok
|
|
|
13688 |
header('HTTP/1.1 200 OK');
|
| 226 |
liveuser |
13689 |
|
| 3 |
liveuser |
13690 |
#提示 mimetype
|
|
|
13691 |
header("Content-Type: $mimetype");
|
| 226 |
liveuser |
13692 |
|
| 3 |
liveuser |
13693 |
#要先驗證cache中的資料,取得的內容放在快取的時間為0
|
|
|
13694 |
header('Cache-Control: public, must-revalidate, max-age=0');
|
| 226 |
liveuser |
13695 |
|
| 3 |
liveuser |
13696 |
#提示不要cache
|
| 226 |
liveuser |
13697 |
header('Pragma: no-cache');
|
|
|
13698 |
|
| 3 |
liveuser |
13699 |
#提示接收的 Ranges 單位為 bytes
|
|
|
13700 |
header('Accept-Ranges: bytes');
|
| 226 |
liveuser |
13701 |
|
| 3 |
liveuser |
13702 |
#數值傳輸的內容長度為多少
|
|
|
13703 |
header('Content-Length:' . (($end - $begin) + 1));
|
| 226 |
liveuser |
13704 |
|
| 3 |
liveuser |
13705 |
#提示內容為檔案的哪邊到哪邊與總共的長度
|
|
|
13706 |
header("Content-Range: bytes $begin-$end/$size");
|
| 226 |
liveuser |
13707 |
|
| 3 |
liveuser |
13708 |
#提示檔案的名稱
|
|
|
13709 |
header("Content-Disposition: inline; filename=$filename");
|
| 226 |
liveuser |
13710 |
|
| 3 |
liveuser |
13711 |
#提示用2元碼傳輸
|
|
|
13712 |
header("Content-Transfer-Encoding: binary");
|
| 226 |
liveuser |
13713 |
|
| 3 |
liveuser |
13714 |
#提示檔案最後變更日期
|
|
|
13715 |
header("Last-Modified: $time");
|
|
|
13716 |
|
|
|
13717 |
#初始化當前位置
|
|
|
13718 |
$cur = $begin;
|
| 226 |
liveuser |
13719 |
|
|
|
13720 |
#指定讀取的起始點為 $begin
|
| 3 |
liveuser |
13721 |
fseek($fm, $begin, 0);
|
|
|
13722 |
|
|
|
13723 |
#讀取內容, 若不是檔案結尾, 且當前位置($cur)小於等於 本次要提供的長度結尾($end), 且connection_status為0
|
|
|
13724 |
while(!feof($fm) && $cur<=$end && (connection_status()===0)){
|
| 226 |
liveuser |
13725 |
|
| 3 |
liveuser |
13726 |
#一次最多印出 1024*16bytes 的長度,若剩下長度不足則只印出剩下的長度.
|
|
|
13727 |
echo fread($fm, min(1024 * 16, ($end - $cur) + 1));
|
| 226 |
liveuser |
13728 |
|
| 3 |
liveuser |
13729 |
#更改位置
|
|
|
13730 |
$cur += 1024 * 16;
|
| 226 |
liveuser |
13731 |
|
| 3 |
liveuser |
13732 |
}#while end
|
| 226 |
liveuser |
13733 |
|
| 3 |
liveuser |
13734 |
}#function partDownload end
|
| 226 |
liveuser |
13735 |
|
| 3 |
liveuser |
13736 |
/*
|
|
|
13737 |
#函式說明:
|
| 226 |
liveuser |
13738 |
#尋找檔案.
|
| 3 |
liveuser |
13739 |
#回傳結果:
|
|
|
13740 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
13741 |
#$result["error"],錯誤訊息.
|
|
|
13742 |
#$result["warning"],警告訊息陣列.
|
|
|
13743 |
#$result["function"],當前執行的函數名稱.
|
|
|
13744 |
#$result["argu"],所使用的參數.
|
|
|
13745 |
#$result["found"],是否有找到可以轉換的檔案,"true"代表有;"false"代表沒有.
|
|
|
13746 |
#$result["content"],找到的檔案陣列.
|
|
|
13747 |
#必填參數:
|
|
|
13748 |
#$conf["keyWord"],字串,要搜尋的檔案關鍵字,可用"*"符號,例如"*.qcow2",就代表檔案名成為"qcow2"結尾的檔案.
|
|
|
13749 |
$conf["keyWord"]="";
|
|
|
13750 |
#$conf["path"],字串陣列,虛擬硬碟檔案的搜尋路徑,預設為當前路徑.
|
|
|
13751 |
$conf["path"]=array();
|
|
|
13752 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
13753 |
$conf["fileArgu"]=__FILE__;
|
|
|
13754 |
#參考資料:
|
|
|
13755 |
#http://php.net/manual/en/function.glob.php
|
|
|
13756 |
#備註:
|
|
|
13757 |
#無.
|
|
|
13758 |
*/
|
|
|
13759 |
public static function findFile(&$conf=array()){
|
| 226 |
liveuser |
13760 |
|
| 3 |
liveuser |
13761 |
#初始化要回傳的結果
|
|
|
13762 |
$result=array();
|
|
|
13763 |
|
|
|
13764 |
#取得當前執行的函數名稱
|
|
|
13765 |
$result["function"]=__FUNCTION__;
|
|
|
13766 |
|
|
|
13767 |
#如果沒有參數
|
|
|
13768 |
if(func_num_args()==0){
|
| 226 |
liveuser |
13769 |
|
| 3 |
liveuser |
13770 |
#設置執行失敗
|
|
|
13771 |
$result["status"]="false";
|
| 226 |
liveuser |
13772 |
|
| 3 |
liveuser |
13773 |
#設置執行錯誤訊息
|
|
|
13774 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
13775 |
|
| 3 |
liveuser |
13776 |
#回傳結果
|
|
|
13777 |
return $result;
|
|
|
13778 |
|
| 226 |
liveuser |
13779 |
}#if end
|
|
|
13780 |
|
| 3 |
liveuser |
13781 |
#取得參數
|
|
|
13782 |
$result["argu"]=$conf;
|
|
|
13783 |
|
|
|
13784 |
#如果 $conf 不為陣列
|
|
|
13785 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
13786 |
|
| 3 |
liveuser |
13787 |
#設置執行失敗
|
|
|
13788 |
$result["status"]="false";
|
| 226 |
liveuser |
13789 |
|
| 3 |
liveuser |
13790 |
#設置執行錯誤訊息
|
|
|
13791 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
13792 |
|
| 3 |
liveuser |
13793 |
#如果傳入的參數為 null
|
|
|
13794 |
if($conf===null){
|
| 226 |
liveuser |
13795 |
|
| 3 |
liveuser |
13796 |
#設置執行錯誤訊息
|
|
|
13797 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
13798 |
|
| 3 |
liveuser |
13799 |
}#if end
|
|
|
13800 |
|
|
|
13801 |
#回傳結果
|
|
|
13802 |
return $result;
|
| 226 |
liveuser |
13803 |
|
| 3 |
liveuser |
13804 |
}#if end
|
| 226 |
liveuser |
13805 |
|
| 3 |
liveuser |
13806 |
#函式說明:
|
|
|
13807 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
13808 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
13809 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
13810 |
#$result["function"],當前執行的函式名稱.
|
|
|
13811 |
#$result["argu"],設置給予的參數.
|
|
|
13812 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
13813 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
13814 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
13815 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
13816 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
13817 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
13818 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
13819 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
13820 |
#必填寫的參數:
|
|
|
13821 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
| 226 |
liveuser |
13822 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
| 3 |
liveuser |
13823 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
13824 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
13825 |
#可以省略的參數:
|
|
|
13826 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
13827 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path","keyWord","fileArgu");
|
|
|
13828 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
13829 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string","string");
|
|
|
13830 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
13831 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
13832 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
13833 |
#$conf["canNotBeEmpty"]=array();
|
|
|
13834 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
13835 |
#$conf["canBeEmpty"]=array();
|
|
|
13836 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
13837 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
13838 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
13839 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
13840 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
13841 |
#$conf["skipableVariableType"]=array();
|
|
|
13842 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
13843 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
13844 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
13845 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
13846 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
13847 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
13848 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
13849 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
13850 |
#參考資料來源:
|
|
|
13851 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
13852 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
13853 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
13854 |
|
| 3 |
liveuser |
13855 |
#如果檢查參數失敗
|
|
|
13856 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
13857 |
|
| 3 |
liveuser |
13858 |
#設置執行失敗
|
|
|
13859 |
$result["status"]="false";
|
| 226 |
liveuser |
13860 |
|
| 3 |
liveuser |
13861 |
#設置執行失敗訊息
|
|
|
13862 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
13863 |
|
| 3 |
liveuser |
13864 |
#回傳結果
|
|
|
13865 |
return $result;
|
| 226 |
liveuser |
13866 |
|
| 3 |
liveuser |
13867 |
}#if end
|
| 226 |
liveuser |
13868 |
|
| 3 |
liveuser |
13869 |
#如果檢查參數不通過
|
|
|
13870 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
13871 |
|
| 3 |
liveuser |
13872 |
#設置執行失敗
|
|
|
13873 |
$result["status"]="false";
|
| 226 |
liveuser |
13874 |
|
| 3 |
liveuser |
13875 |
#設置執行失敗訊息
|
|
|
13876 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
13877 |
|
| 3 |
liveuser |
13878 |
#回傳結果
|
|
|
13879 |
return $result;
|
| 226 |
liveuser |
13880 |
|
| 3 |
liveuser |
13881 |
}#if end
|
| 226 |
liveuser |
13882 |
|
| 3 |
liveuser |
13883 |
#檢查要搜尋的路徑是否都存在
|
|
|
13884 |
#函式說明:
|
|
|
13885 |
#s檢查多個檔案與資料夾是否存在.
|
|
|
13886 |
#回傳的結果:
|
|
|
13887 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
13888 |
#$result["error"],錯誤訊息陣列.
|
|
|
13889 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
13890 |
#$result["argu"],使用的參數.
|
|
|
13891 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
13892 |
#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
|
|
|
13893 |
#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
|
|
|
13894 |
#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
|
|
|
13895 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
13896 |
#必填參數:
|
|
|
13897 |
#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
13898 |
$conf["self::checkMultiFileExist"]["fileArray"]=$conf["path"];
|
|
|
13899 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
13900 |
$conf["self::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
13901 |
#可省略參數
|
|
|
13902 |
#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
|
|
|
13903 |
#$conf["disableWebSearch"]="false";
|
|
|
13904 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
13905 |
#$conf["userDir"]="true";
|
|
|
13906 |
#參考資料來源:
|
|
|
13907 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
13908 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
13909 |
#備註:
|
|
|
13910 |
#函數file_exists檢查的路徑為檔案系統的路徑
|
|
|
13911 |
$checkMultiFileExist=self::checkMultiFileExist($conf["self::checkMultiFileExist"]);
|
|
|
13912 |
unset($conf["self::checkMultiFileExist"]);
|
| 226 |
liveuser |
13913 |
|
| 3 |
liveuser |
13914 |
#如果檢查目錄存在失敗
|
|
|
13915 |
if($checkMultiFileExist["status"]==="false"){
|
| 226 |
liveuser |
13916 |
|
| 3 |
liveuser |
13917 |
#設置執行失敗
|
|
|
13918 |
$result["status"]="false";
|
| 226 |
liveuser |
13919 |
|
| 3 |
liveuser |
13920 |
#設置執行失敗訊息
|
|
|
13921 |
$result["error"]=$checkMultiFileExist;
|
| 226 |
liveuser |
13922 |
|
| 3 |
liveuser |
13923 |
#回傳結果
|
|
|
13924 |
return $result;
|
| 226 |
liveuser |
13925 |
|
|
|
13926 |
}#if end
|
|
|
13927 |
|
| 3 |
liveuser |
13928 |
#如果目錄不存在
|
|
|
13929 |
if($checkMultiFileExist["status"]==="false"){
|
| 226 |
liveuser |
13930 |
|
| 3 |
liveuser |
13931 |
#設置執行失敗
|
|
|
13932 |
$result["status"]="false";
|
| 226 |
liveuser |
13933 |
|
| 3 |
liveuser |
13934 |
#設置執行失敗訊息
|
|
|
13935 |
$result["error"]=$checkMultiFileExist;
|
| 226 |
liveuser |
13936 |
|
| 3 |
liveuser |
13937 |
#回傳結果
|
|
|
13938 |
return $result;
|
| 226 |
liveuser |
13939 |
|
| 3 |
liveuser |
13940 |
}#if end
|
| 226 |
liveuser |
13941 |
|
| 3 |
liveuser |
13942 |
#如果有路徑不存在
|
|
|
13943 |
if($checkMultiFileExist["allExist"]==="false"){
|
| 226 |
liveuser |
13944 |
|
| 3 |
liveuser |
13945 |
#設置執行失敗
|
|
|
13946 |
$result["status"]="false";
|
| 226 |
liveuser |
13947 |
|
| 3 |
liveuser |
13948 |
#設置執行失敗訊息
|
|
|
13949 |
$result["error"]=$checkMultiFileExist;
|
| 226 |
liveuser |
13950 |
|
| 3 |
liveuser |
13951 |
#設置提示有路徑不存在的訊息
|
|
|
13952 |
$result["warning"][]="參數path的路徑沒有每個都存在";
|
| 226 |
liveuser |
13953 |
|
| 3 |
liveuser |
13954 |
#回傳結果
|
|
|
13955 |
return $result;
|
| 226 |
liveuser |
13956 |
|
| 3 |
liveuser |
13957 |
}#if end
|
| 226 |
liveuser |
13958 |
|
| 3 |
liveuser |
13959 |
#預設沒有找到檔案
|
| 226 |
liveuser |
13960 |
$result["found"]="false";
|
|
|
13961 |
|
| 3 |
liveuser |
13962 |
#針對每個要搜尋的路徑
|
|
|
13963 |
foreach($conf["path"] as $path){
|
| 226 |
liveuser |
13964 |
|
| 3 |
liveuser |
13965 |
#函式說明:
|
|
|
13966 |
#用find指令尋找檔案
|
|
|
13967 |
#回傳結果:
|
|
|
13968 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
13969 |
#$result["error"],錯誤訊息.
|
|
|
13970 |
#$result["function"],當前執行的函數名稱.
|
|
|
13971 |
#$result["argu"],所使用的參數.
|
|
|
13972 |
#$result["found"],是否有找到符合的檔案,"true"代表有;"false"代表沒有.
|
|
|
13973 |
#$result["content"],找到的檔案陣列.
|
|
|
13974 |
#必填參數:
|
|
|
13975 |
#$conf["keyWord"],字串,要搜尋的檔案關鍵字,可用"*"符號,例如"*.qcow2",就代表檔案名成為"qcow2"結尾的檔案.
|
| 226 |
liveuser |
13976 |
$conf["cmd::find"]["keyWord"]=$conf["keyWord"];
|
| 3 |
liveuser |
13977 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
13978 |
$conf["cmd::find"]["fileArgu"]=$conf["fileArgu"];
|
|
|
13979 |
#可省略參數:
|
|
|
13980 |
#$conf["path"],字串,搜尋的路徑,預設為"/".
|
|
|
13981 |
$conf["cmd::find"]["path"]=$path;
|
|
|
13982 |
#$conf["fileOnly"],字串,"true"代表只要找檔案,"false"代表.
|
|
|
13983 |
$conf["cmd::find"]["fileOnly"]="true";
|
|
|
13984 |
#參考資料:
|
|
|
13985 |
#http://php.net/manual/en/function.glob.php
|
|
|
13986 |
$find=cmd::find($conf["cmd::find"]);
|
|
|
13987 |
unset($conf["cmd::find"]);
|
| 226 |
liveuser |
13988 |
|
| 3 |
liveuser |
13989 |
#如果尋找檔案失敗
|
|
|
13990 |
if($find["status"]==="false"){
|
| 226 |
liveuser |
13991 |
|
| 3 |
liveuser |
13992 |
#設置執行失敗
|
|
|
13993 |
$result["status"]="false";
|
| 226 |
liveuser |
13994 |
|
| 3 |
liveuser |
13995 |
#設置執行失敗訊息
|
|
|
13996 |
$result["error"]=$find;
|
| 226 |
liveuser |
13997 |
|
| 3 |
liveuser |
13998 |
#回傳結果
|
|
|
13999 |
return $result;
|
| 226 |
liveuser |
14000 |
|
| 3 |
liveuser |
14001 |
}#if end
|
| 226 |
liveuser |
14002 |
|
| 3 |
liveuser |
14003 |
#如果有找到符合的檔案
|
|
|
14004 |
if($find["found"]==="true"){
|
| 226 |
liveuser |
14005 |
|
| 3 |
liveuser |
14006 |
#設置有找到檔案
|
|
|
14007 |
$result["found"]="true";
|
| 226 |
liveuser |
14008 |
|
| 3 |
liveuser |
14009 |
#針對每個找到的檔案
|
|
|
14010 |
foreach($find["content"] as $filtedFile){
|
| 226 |
liveuser |
14011 |
|
| 3 |
liveuser |
14012 |
#設置有找到的檔案
|
|
|
14013 |
$result["content"][]=$filtedFile;
|
| 226 |
liveuser |
14014 |
|
| 3 |
liveuser |
14015 |
}#foreach end
|
| 226 |
liveuser |
14016 |
|
| 3 |
liveuser |
14017 |
}#if end
|
| 226 |
liveuser |
14018 |
|
|
|
14019 |
}#foreach end
|
|
|
14020 |
|
| 3 |
liveuser |
14021 |
#設置執行正常
|
|
|
14022 |
$result["status"]="true";
|
| 226 |
liveuser |
14023 |
|
| 3 |
liveuser |
14024 |
#回傳結果
|
|
|
14025 |
return $result;
|
| 226 |
liveuser |
14026 |
|
| 3 |
liveuser |
14027 |
}#function findFile end
|
|
|
14028 |
|
|
|
14029 |
/*
|
|
|
14030 |
#函式說明:
|
|
|
14031 |
#判斷檔案位於哪個分割區
|
|
|
14032 |
#回傳結果:
|
|
|
14033 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
14034 |
#$result["error"],錯誤訊息.
|
|
|
14035 |
#$result["function"],當前執行的函數名稱.
|
|
|
14036 |
#$result["argu"],所使用的參數.
|
|
|
14037 |
#$result["content"],找到的檔案所屬分割區資訊.
|
|
|
14038 |
#必填參數:
|
|
|
14039 |
#$conf["file"],字串,檔案的路徑與名稱.
|
|
|
14040 |
$conf["file"]="";
|
|
|
14041 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
14042 |
$conf["fileArgu"]=__FILE__;
|
|
|
14043 |
#可省略參數:
|
|
|
14044 |
#無.
|
|
|
14045 |
#參考資料:
|
|
|
14046 |
#無.
|
|
|
14047 |
#備註:
|
|
|
14048 |
#無.
|
|
|
14049 |
*/
|
|
|
14050 |
public static function addrInMountPoint(&$conf=array()){
|
| 226 |
liveuser |
14051 |
|
| 3 |
liveuser |
14052 |
#初始化要回傳的結果
|
|
|
14053 |
$result=array();
|
|
|
14054 |
|
|
|
14055 |
#取得當前執行的函數名稱
|
|
|
14056 |
$result["function"]=__FUNCTION__;
|
|
|
14057 |
|
|
|
14058 |
#如果沒有參數
|
|
|
14059 |
if(func_num_args()==0){
|
| 226 |
liveuser |
14060 |
|
| 3 |
liveuser |
14061 |
#設置執行失敗
|
|
|
14062 |
$result["status"]="false";
|
| 226 |
liveuser |
14063 |
|
| 3 |
liveuser |
14064 |
#設置執行錯誤訊息
|
|
|
14065 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
14066 |
|
| 3 |
liveuser |
14067 |
#回傳結果
|
|
|
14068 |
return $result;
|
|
|
14069 |
|
| 226 |
liveuser |
14070 |
}#if end
|
|
|
14071 |
|
| 3 |
liveuser |
14072 |
#取得參數
|
|
|
14073 |
$result["argu"]=$conf;
|
|
|
14074 |
|
|
|
14075 |
#如果 $conf 不為陣列
|
|
|
14076 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
14077 |
|
| 3 |
liveuser |
14078 |
#設置執行失敗
|
|
|
14079 |
$result["status"]="false";
|
| 226 |
liveuser |
14080 |
|
| 3 |
liveuser |
14081 |
#設置執行錯誤訊息
|
|
|
14082 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
14083 |
|
| 3 |
liveuser |
14084 |
#如果傳入的參數為 null
|
|
|
14085 |
if($conf===null){
|
| 226 |
liveuser |
14086 |
|
| 3 |
liveuser |
14087 |
#設置執行錯誤訊息
|
|
|
14088 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
14089 |
|
| 3 |
liveuser |
14090 |
}#if end
|
|
|
14091 |
|
|
|
14092 |
#回傳結果
|
|
|
14093 |
return $result;
|
| 226 |
liveuser |
14094 |
|
| 3 |
liveuser |
14095 |
}#if end
|
| 226 |
liveuser |
14096 |
|
| 3 |
liveuser |
14097 |
#函式說明:
|
|
|
14098 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
14099 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
14100 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
14101 |
#$result["function"],當前執行的函式名稱.
|
|
|
14102 |
#$result["argu"],設置給予的參數.
|
|
|
14103 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
14104 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
14105 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
14106 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
14107 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
14108 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
14109 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
14110 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
14111 |
#必填寫的參數:
|
|
|
14112 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
| 226 |
liveuser |
14113 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
| 3 |
liveuser |
14114 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
14115 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
14116 |
#可以省略的參數:
|
|
|
14117 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
14118 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
|
|
|
14119 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
14120 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
14121 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
14122 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
14123 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
14124 |
#$conf["canNotBeEmpty"]=array();
|
|
|
14125 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
14126 |
#$conf["canBeEmpty"]=array();
|
|
|
14127 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
14128 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
14129 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
14130 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
14131 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
14132 |
#$conf["skipableVariableType"]=array();
|
|
|
14133 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
14134 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
14135 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
14136 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
14137 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
14138 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
14139 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
14140 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
14141 |
#參考資料來源:
|
|
|
14142 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
14143 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
14144 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
14145 |
|
| 3 |
liveuser |
14146 |
#如果檢查參數失敗
|
|
|
14147 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
14148 |
|
| 3 |
liveuser |
14149 |
#設置執行失敗
|
|
|
14150 |
$result["status"]="false";
|
| 226 |
liveuser |
14151 |
|
| 3 |
liveuser |
14152 |
#設置執行失敗訊息
|
|
|
14153 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
14154 |
|
| 3 |
liveuser |
14155 |
#回傳結果
|
|
|
14156 |
return $result;
|
| 226 |
liveuser |
14157 |
|
| 3 |
liveuser |
14158 |
}#if end
|
| 226 |
liveuser |
14159 |
|
| 3 |
liveuser |
14160 |
#如果檢查參數不通過
|
|
|
14161 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
14162 |
|
| 3 |
liveuser |
14163 |
#設置執行失敗
|
|
|
14164 |
$result["status"]="false";
|
| 226 |
liveuser |
14165 |
|
| 3 |
liveuser |
14166 |
#設置執行失敗訊息
|
|
|
14167 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
14168 |
|
| 3 |
liveuser |
14169 |
#回傳結果
|
|
|
14170 |
return $result;
|
| 226 |
liveuser |
14171 |
|
| 3 |
liveuser |
14172 |
}#if end
|
| 226 |
liveuser |
14173 |
|
| 3 |
liveuser |
14174 |
#函式說明:
|
|
|
14175 |
#透過lsblk指令的輸出取得已經掛載的blk.
|
|
|
14176 |
#回傳結果:
|
|
|
14177 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
14178 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
14179 |
#$result["function"],當前執行的函式名稱.
|
|
|
14180 |
#$result["content"],lsblk的輸出內容.
|
|
|
14181 |
#必填參數:
|
|
|
14182 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
14183 |
$conf["cmd::lsblk"]["fileArgu"]=$conf["fileArgu"];
|
|
|
14184 |
#可省略參數:
|
| 226 |
liveuser |
14185 |
#無.
|
| 3 |
liveuser |
14186 |
$lsblk=cmd::lsblk($conf["cmd::lsblk"]);
|
|
|
14187 |
unset($conf["cmd::lsblk"]);
|
| 226 |
liveuser |
14188 |
|
| 3 |
liveuser |
14189 |
#如果執行失敗
|
|
|
14190 |
if($lsblk["status"]==="false"){
|
| 226 |
liveuser |
14191 |
|
| 3 |
liveuser |
14192 |
#設置執行失敗
|
|
|
14193 |
$result["status"]="false";
|
| 226 |
liveuser |
14194 |
|
| 3 |
liveuser |
14195 |
#設置執行失敗訊息
|
|
|
14196 |
$result["error"]=$lsblk;
|
| 226 |
liveuser |
14197 |
|
| 3 |
liveuser |
14198 |
#回傳結果
|
|
|
14199 |
return $result;
|
| 226 |
liveuser |
14200 |
|
| 3 |
liveuser |
14201 |
}#if end
|
| 226 |
liveuser |
14202 |
|
| 3 |
liveuser |
14203 |
#將 $conf["file"] 轉換成絕對路徑
|
|
|
14204 |
#函式說明:
|
|
|
14205 |
#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
|
|
|
14206 |
#回傳結果:
|
|
|
14207 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
14208 |
#$result["error"],錯誤訊息陣列.
|
| 226 |
liveuser |
14209 |
#$result["function"],函數名稱.
|
| 3 |
liveuser |
14210 |
#$result["argu"],使用的參數.
|
|
|
14211 |
#$result["content"],網址,若是在命令列執行,則為"null".
|
|
|
14212 |
#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
|
|
|
14213 |
#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
|
|
|
14214 |
#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
|
|
|
14215 |
#必填參數:
|
|
|
14216 |
#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
|
|
|
14217 |
$conf["fileAccess::getInternetAddress"]["address"]=$conf["file"];
|
|
|
14218 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
14219 |
$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
|
|
|
14220 |
#可省略參數:
|
|
|
14221 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
14222 |
#$conf["userDir"]="true";
|
|
|
14223 |
$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
|
|
|
14224 |
unset($conf["fileAccess::getInternetAddress"]);
|
| 226 |
liveuser |
14225 |
|
| 3 |
liveuser |
14226 |
#如果執行失敗
|
|
|
14227 |
if($getInternetAddress["status"]==="false"){
|
| 226 |
liveuser |
14228 |
|
| 3 |
liveuser |
14229 |
#設置執行失敗
|
|
|
14230 |
$result["status"]="false";
|
| 226 |
liveuser |
14231 |
|
| 3 |
liveuser |
14232 |
#設置執行失敗訊息
|
|
|
14233 |
$result["error"]=$getInternetAddress;
|
| 226 |
liveuser |
14234 |
|
| 3 |
liveuser |
14235 |
#回傳結果
|
|
|
14236 |
return $result;
|
| 226 |
liveuser |
14237 |
|
|
|
14238 |
}#if end
|
|
|
14239 |
|
| 3 |
liveuser |
14240 |
#使用絕對位置作為輸入字串
|
|
|
14241 |
#函式說明:
|
|
|
14242 |
#尋找字串是否存在對應的關鍵字,且符合的最常關鍵字為何?
|
|
|
14243 |
#回傳結果:
|
|
|
14244 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
14245 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
14246 |
#$result["function"],當前執行的函式名稱.
|
|
|
14247 |
#$result["argu"],所使用的參數.
|
|
|
14248 |
#$result["founded"],是否有找到關鍵字,"true"代表有找到,"false"代表沒有找到.
|
|
|
14249 |
#$result["content"],最符合的字串完整內容.
|
|
|
14250 |
#必填參數:
|
|
|
14251 |
#$conf["input"],字串,要比對的字串陣列.
|
|
|
14252 |
$conf["search::findLikelyStr"]["input"]=$getInternetAddress["fileSystemAbsoulutePosition"];
|
|
|
14253 |
#$conf["keyWord"],字串陣列,要搜尋的關鍵字.
|
|
|
14254 |
$conf["search::findLikelyStr"]["keyWord"]=$lsblk["content"]["MOUNTPOINT"];
|
|
|
14255 |
$findLikelyStr=search::findLikelyStr($conf["search::findLikelyStr"]);
|
|
|
14256 |
unset($conf["search::findLikelyStr"]);
|
| 226 |
liveuser |
14257 |
|
| 3 |
liveuser |
14258 |
#如果執行失敗
|
|
|
14259 |
if($findLikelyStr["status"]==="false"){
|
| 226 |
liveuser |
14260 |
|
| 3 |
liveuser |
14261 |
#設置執行失敗
|
|
|
14262 |
$result["status"]="false";
|
| 226 |
liveuser |
14263 |
|
| 3 |
liveuser |
14264 |
#設置執行失敗訊息
|
|
|
14265 |
$result["error"]=$findLikelyStr;
|
| 226 |
liveuser |
14266 |
|
| 3 |
liveuser |
14267 |
#回傳結果
|
|
|
14268 |
return $result;
|
| 226 |
liveuser |
14269 |
|
| 3 |
liveuser |
14270 |
}#if end
|
| 226 |
liveuser |
14271 |
|
| 3 |
liveuser |
14272 |
#如果找不到歸屬的分割區
|
|
|
14273 |
if($findLikelyStr["found"]==="false"){
|
| 226 |
liveuser |
14274 |
|
| 3 |
liveuser |
14275 |
#設置執行失敗
|
|
|
14276 |
$result["status"]="false";
|
| 226 |
liveuser |
14277 |
|
| 3 |
liveuser |
14278 |
#設置執行失敗訊息
|
|
|
14279 |
$result["error"]=$findLikelyStr;
|
| 226 |
liveuser |
14280 |
|
| 3 |
liveuser |
14281 |
#回傳結果
|
|
|
14282 |
return $result;
|
| 226 |
liveuser |
14283 |
|
| 3 |
liveuser |
14284 |
}#if end
|
| 226 |
liveuser |
14285 |
|
| 3 |
liveuser |
14286 |
#設置歸屬的分割區資訊
|
|
|
14287 |
$result["content"]=$findLikelyStr["content"];
|
| 226 |
liveuser |
14288 |
|
| 3 |
liveuser |
14289 |
#設置執行正常
|
|
|
14290 |
$result["status"]="true";
|
| 226 |
liveuser |
14291 |
|
| 3 |
liveuser |
14292 |
#回傳結果
|
|
|
14293 |
return $result;
|
| 226 |
liveuser |
14294 |
|
| 3 |
liveuser |
14295 |
}#function addrInMountPoint end
|
|
|
14296 |
|
|
|
14297 |
/*
|
|
|
14298 |
#函式說明:
|
|
|
14299 |
#取得檔案的副檔名
|
|
|
14300 |
#回傳結果:
|
|
|
14301 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
14302 |
#$result["error"],錯誤訊息.
|
|
|
14303 |
#$result["function"],當前執行的函數名稱.
|
| 226 |
liveuser |
14304 |
#$result["argu"],所使用的參數.
|
| 3 |
liveuser |
14305 |
#$result["content"],副檔名.
|
|
|
14306 |
#$result["name"],不含副檔的名稱.
|
|
|
14307 |
#$result["fullName"],含副檔的名稱.
|
|
|
14308 |
#$result["path"],檔案所處的路徑.
|
|
|
14309 |
#必填參數:
|
|
|
14310 |
#$conf["file"],字串,檔案的路徑與名稱.
|
|
|
14311 |
$conf["file"]="";
|
|
|
14312 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
14313 |
$conf["fileArgu"]=__FILE__;
|
|
|
14314 |
#可省略參數:
|
|
|
14315 |
#無.
|
|
|
14316 |
#參考資料:
|
|
|
14317 |
#無.
|
|
|
14318 |
#備註:
|
|
|
14319 |
#無.
|
|
|
14320 |
*/
|
|
|
14321 |
public static function getExtension(&$conf=array()){
|
| 226 |
liveuser |
14322 |
|
| 3 |
liveuser |
14323 |
#初始化要回傳的結果
|
|
|
14324 |
$result=array();
|
|
|
14325 |
|
|
|
14326 |
#取得當前執行的函數名稱
|
|
|
14327 |
$result["function"]=__FUNCTION__;
|
|
|
14328 |
|
|
|
14329 |
#如果沒有參數
|
|
|
14330 |
if(func_num_args()==0){
|
| 226 |
liveuser |
14331 |
|
| 3 |
liveuser |
14332 |
#設置執行失敗
|
|
|
14333 |
$result["status"]="false";
|
| 226 |
liveuser |
14334 |
|
| 3 |
liveuser |
14335 |
#設置執行錯誤訊息
|
|
|
14336 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
14337 |
|
| 3 |
liveuser |
14338 |
#回傳結果
|
|
|
14339 |
return $result;
|
|
|
14340 |
|
| 226 |
liveuser |
14341 |
}#if end
|
|
|
14342 |
|
| 3 |
liveuser |
14343 |
#取得參數
|
|
|
14344 |
$result["argu"]=$conf;
|
|
|
14345 |
|
|
|
14346 |
#如果 $conf 不為陣列
|
|
|
14347 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
14348 |
|
| 3 |
liveuser |
14349 |
#設置執行失敗
|
|
|
14350 |
$result["status"]="false";
|
| 226 |
liveuser |
14351 |
|
| 3 |
liveuser |
14352 |
#設置執行錯誤訊息
|
|
|
14353 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
14354 |
|
| 3 |
liveuser |
14355 |
#如果傳入的參數為 null
|
|
|
14356 |
if($conf===null){
|
| 226 |
liveuser |
14357 |
|
| 3 |
liveuser |
14358 |
#設置執行錯誤訊息
|
|
|
14359 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
14360 |
|
| 3 |
liveuser |
14361 |
}#if end
|
|
|
14362 |
|
|
|
14363 |
#回傳結果
|
|
|
14364 |
return $result;
|
| 226 |
liveuser |
14365 |
|
| 3 |
liveuser |
14366 |
}#if end
|
| 226 |
liveuser |
14367 |
|
| 3 |
liveuser |
14368 |
#函式說明:
|
|
|
14369 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
14370 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
14371 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
14372 |
#$result["function"],當前執行的函式名稱.
|
|
|
14373 |
#$result["argu"],設置給予的參數.
|
|
|
14374 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
14375 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
14376 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
14377 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
14378 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
14379 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
14380 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
14381 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
14382 |
#必填寫的參數:
|
|
|
14383 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
| 226 |
liveuser |
14384 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
| 3 |
liveuser |
14385 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
14386 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
14387 |
#可以省略的參數:
|
|
|
14388 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
14389 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
|
|
|
14390 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
14391 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
14392 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
14393 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
14394 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
14395 |
#$conf["canNotBeEmpty"]=array();
|
|
|
14396 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
14397 |
#$conf["canBeEmpty"]=array();
|
|
|
14398 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
14399 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
14400 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
14401 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
14402 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
14403 |
#$conf["skipableVariableType"]=array();
|
|
|
14404 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
14405 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
14406 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
14407 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
14408 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
14409 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
14410 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
14411 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
14412 |
#參考資料來源:
|
|
|
14413 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
14414 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
14415 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
14416 |
|
| 3 |
liveuser |
14417 |
#如果檢查參數失敗
|
|
|
14418 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
14419 |
|
| 3 |
liveuser |
14420 |
#設置執行失敗
|
|
|
14421 |
$result["status"]="false";
|
| 226 |
liveuser |
14422 |
|
| 3 |
liveuser |
14423 |
#設置執行失敗訊息
|
|
|
14424 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
14425 |
|
| 3 |
liveuser |
14426 |
#回傳結果
|
|
|
14427 |
return $result;
|
| 226 |
liveuser |
14428 |
|
| 3 |
liveuser |
14429 |
}#if end
|
| 226 |
liveuser |
14430 |
|
| 3 |
liveuser |
14431 |
#如果檢查參數不通過
|
|
|
14432 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
14433 |
|
| 3 |
liveuser |
14434 |
#設置執行失敗
|
|
|
14435 |
$result["status"]="false";
|
| 226 |
liveuser |
14436 |
|
| 3 |
liveuser |
14437 |
#設置執行失敗訊息
|
|
|
14438 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
14439 |
|
| 3 |
liveuser |
14440 |
#回傳結果
|
|
|
14441 |
return $result;
|
| 226 |
liveuser |
14442 |
|
| 3 |
liveuser |
14443 |
}#if end
|
| 226 |
liveuser |
14444 |
|
| 3 |
liveuser |
14445 |
#初始化檔案的路徑
|
|
|
14446 |
$result["path"]="./";
|
| 226 |
liveuser |
14447 |
|
| 3 |
liveuser |
14448 |
#用 "/" 來分割字串
|
|
|
14449 |
#函式說明:
|
|
|
14450 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
14451 |
#回傳結果:
|
|
|
14452 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
14453 |
#$result["error"],錯誤訊息陣列
|
|
|
14454 |
#$result["function"],當前執行的函數名稱.
|
|
|
14455 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
14456 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
14457 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
14458 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
14459 |
#必填參數:
|
|
|
14460 |
$conf["stringProcess::spiltString"]["stringIn"]=$conf["file"];#要處理的字串。
|
|
|
14461 |
$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
|
|
|
14462 |
#可省略參數:
|
|
|
14463 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
14464 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
14465 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
14466 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
14467 |
|
| 3 |
liveuser |
14468 |
#如果檢查參數失敗
|
|
|
14469 |
if($spiltString["status"]==="false"){
|
| 226 |
liveuser |
14470 |
|
| 3 |
liveuser |
14471 |
#設置執行失敗
|
|
|
14472 |
$result["status"]="false";
|
| 226 |
liveuser |
14473 |
|
| 3 |
liveuser |
14474 |
#設置執行失敗訊息
|
|
|
14475 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
14476 |
|
| 3 |
liveuser |
14477 |
#回傳結果
|
|
|
14478 |
return $result;
|
| 226 |
liveuser |
14479 |
|
| 3 |
liveuser |
14480 |
}#if end
|
| 226 |
liveuser |
14481 |
|
| 3 |
liveuser |
14482 |
#初始化含副檔名的檔案名稱
|
|
|
14483 |
$result["fullName"]=$conf["file"];
|
| 226 |
liveuser |
14484 |
|
| 3 |
liveuser |
14485 |
#如果有"/"存在
|
|
|
14486 |
if($spiltString["found"]==="true"){
|
| 226 |
liveuser |
14487 |
|
| 3 |
liveuser |
14488 |
#取得含副檔名的檔案名稱
|
|
|
14489 |
$result["fullName"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
|
| 226 |
liveuser |
14490 |
|
| 3 |
liveuser |
14491 |
#取得檔案的路徑
|
|
|
14492 |
$result["path"]=substr($conf["file"],0,strlen($conf["file"])-strlen($result["fullName"]));
|
| 226 |
liveuser |
14493 |
|
| 3 |
liveuser |
14494 |
}#if end
|
| 226 |
liveuser |
14495 |
|
| 3 |
liveuser |
14496 |
#用 "." 來分割字串
|
|
|
14497 |
#函式說明:
|
|
|
14498 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
14499 |
#回傳結果:
|
|
|
14500 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
14501 |
#$result["error"],錯誤訊息陣列
|
|
|
14502 |
#$result["function"],當前執行的函數名稱.
|
|
|
14503 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
14504 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
14505 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
14506 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
14507 |
#必填參數:
|
|
|
14508 |
$conf["stringProcess::spiltString"]["stringIn"]=$result["fullName"];#要處理的字串。
|
|
|
14509 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
|
|
|
14510 |
#可省略參數:
|
|
|
14511 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
14512 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
14513 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
14514 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
14515 |
|
| 3 |
liveuser |
14516 |
#如果檢查參數失敗
|
|
|
14517 |
if($spiltString["status"]==="false"){
|
| 226 |
liveuser |
14518 |
|
| 3 |
liveuser |
14519 |
#設置執行失敗
|
|
|
14520 |
$result["status"]="false";
|
| 226 |
liveuser |
14521 |
|
| 3 |
liveuser |
14522 |
#設置執行失敗訊息
|
|
|
14523 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
14524 |
|
| 3 |
liveuser |
14525 |
#回傳結果
|
|
|
14526 |
return $result;
|
| 226 |
liveuser |
14527 |
|
| 3 |
liveuser |
14528 |
}#if end
|
| 226 |
liveuser |
14529 |
|
| 3 |
liveuser |
14530 |
#預設副檔名為 ""
|
|
|
14531 |
$result["content"]="";
|
| 226 |
liveuser |
14532 |
|
| 3 |
liveuser |
14533 |
#預設不含副檔名的檔案名稱
|
|
|
14534 |
$result["name"]=$result["fullName"];
|
| 226 |
liveuser |
14535 |
|
| 3 |
liveuser |
14536 |
#如果有"."存在
|
|
|
14537 |
if($spiltString["found"]==="true"){
|
| 226 |
liveuser |
14538 |
|
| 3 |
liveuser |
14539 |
#取得含副檔名
|
|
|
14540 |
$result["content"]=$spiltString["dataArray"][$spiltString["dataCounts"]-1];
|
| 226 |
liveuser |
14541 |
|
| 3 |
liveuser |
14542 |
#取得不含副檔名的檔案名稱
|
| 226 |
liveuser |
14543 |
$result["name"]=substr($result["fullName"],0,strlen($result["fullName"])-strlen($result["content"])-1);
|
|
|
14544 |
|
| 3 |
liveuser |
14545 |
}#if end
|
| 226 |
liveuser |
14546 |
|
| 3 |
liveuser |
14547 |
#設置執行正常
|
|
|
14548 |
$result["status"]="true";
|
| 226 |
liveuser |
14549 |
|
| 3 |
liveuser |
14550 |
#回傳結果
|
|
|
14551 |
return $result;
|
| 226 |
liveuser |
14552 |
|
| 3 |
liveuser |
14553 |
}#function getExtension end
|
|
|
14554 |
|
|
|
14555 |
/*
|
|
|
14556 |
#函式說明:
|
|
|
14557 |
#從檔案尾部開始讀取
|
|
|
14558 |
#回傳結果:
|
|
|
14559 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
14560 |
#$result["error"],錯誤訊息.
|
|
|
14561 |
#$result["function"],當前執行的函數名稱.
|
| 226 |
liveuser |
14562 |
#$result["argu"],所使用的參數.
|
| 3 |
liveuser |
14563 |
#$result["content"],讀取到的內容陣列.
|
|
|
14564 |
#$result["totalLineCount"],檔案的總共行數.
|
|
|
14565 |
#$result["lines"],取得輸出的行數.
|
|
|
14566 |
#$result["lineNum"],取得當前行數.
|
|
|
14567 |
#必填參數:
|
|
|
14568 |
#$conf["file"],字串,檔案的路徑與名稱.
|
|
|
14569 |
$conf["file"]="";
|
|
|
14570 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
14571 |
$conf["fileArgu"]=__FILE__;
|
|
|
14572 |
#可省略參數:
|
|
|
14573 |
#$conf["web"],字串,"true"代表位網頁系統,"false"為檔案系統,預設為"false".
|
|
|
14574 |
#$conf["web"]="false";
|
|
|
14575 |
#$conf["line2start"],字串,從第幾列開始,預設為總行書減去linesPerTime+1.
|
|
|
14576 |
#$conf["line2start"]="";
|
|
|
14577 |
#$conf["linesPerTime"],字串,一次最多讀取幾列,預設爲10列.
|
| 226 |
liveuser |
14578 |
#$conf["linesPerTime"]="10";
|
| 3 |
liveuser |
14579 |
#參考資料:
|
|
|
14580 |
#無.
|
|
|
14581 |
#備註:
|
|
|
14582 |
#無.
|
|
|
14583 |
*/
|
|
|
14584 |
public static function tail(&$conf){
|
|
|
14585 |
|
|
|
14586 |
#初始化要回傳的結果
|
|
|
14587 |
$result=array();
|
|
|
14588 |
|
|
|
14589 |
#取得當前執行的函數名稱
|
|
|
14590 |
$result["function"]=__FUNCTION__;
|
|
|
14591 |
|
|
|
14592 |
#如果沒有參數
|
|
|
14593 |
if(func_num_args()==0){
|
| 226 |
liveuser |
14594 |
|
| 3 |
liveuser |
14595 |
#設置執行失敗
|
|
|
14596 |
$result["status"]="false";
|
| 226 |
liveuser |
14597 |
|
| 3 |
liveuser |
14598 |
#設置執行錯誤訊息
|
|
|
14599 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
14600 |
|
| 3 |
liveuser |
14601 |
#回傳結果
|
|
|
14602 |
return $result;
|
|
|
14603 |
|
| 226 |
liveuser |
14604 |
}#if end
|
|
|
14605 |
|
| 3 |
liveuser |
14606 |
#取得參數
|
|
|
14607 |
$result["argu"]=$conf;
|
|
|
14608 |
|
|
|
14609 |
#如果 $conf 不為陣列
|
|
|
14610 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
14611 |
|
| 3 |
liveuser |
14612 |
#設置執行失敗
|
|
|
14613 |
$result["status"]="false";
|
| 226 |
liveuser |
14614 |
|
| 3 |
liveuser |
14615 |
#設置執行錯誤訊息
|
|
|
14616 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
14617 |
|
| 3 |
liveuser |
14618 |
#如果傳入的參數為 null
|
|
|
14619 |
if($conf===null){
|
| 226 |
liveuser |
14620 |
|
| 3 |
liveuser |
14621 |
#設置執行錯誤訊息
|
|
|
14622 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
14623 |
|
| 3 |
liveuser |
14624 |
}#if end
|
|
|
14625 |
|
|
|
14626 |
#回傳結果
|
|
|
14627 |
return $result;
|
| 226 |
liveuser |
14628 |
|
| 3 |
liveuser |
14629 |
}#if end
|
| 226 |
liveuser |
14630 |
|
| 3 |
liveuser |
14631 |
#函式說明:
|
|
|
14632 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
14633 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
14634 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
14635 |
#$result["function"],當前執行的函式名稱.
|
|
|
14636 |
#$result["argu"],設置給予的參數.
|
|
|
14637 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
14638 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
14639 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
14640 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
14641 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
14642 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
14643 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
14644 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
14645 |
#必填寫的參數:
|
|
|
14646 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
| 226 |
liveuser |
14647 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
| 3 |
liveuser |
14648 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
14649 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
14650 |
#可以省略的參數:
|
|
|
14651 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
14652 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
|
|
|
14653 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
14654 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
14655 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
14656 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
14657 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
14658 |
$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file","fileArgu");
|
|
|
14659 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
14660 |
#$conf["canBeEmpty"]=array();
|
|
|
14661 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
14662 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web","line2start","linesPerTime");
|
|
|
14663 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
14664 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web","line2start","linesPerTime");
|
| 226 |
liveuser |
14665 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
14666 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
14667 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
14668 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",null,"10");
|
|
|
14669 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
14670 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
14671 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
14672 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
14673 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
14674 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
14675 |
#參考資料來源:
|
|
|
14676 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
14677 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
14678 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
14679 |
|
| 3 |
liveuser |
14680 |
#如果檢查參數失敗
|
|
|
14681 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
14682 |
|
| 3 |
liveuser |
14683 |
#設置執行失敗
|
|
|
14684 |
$result["status"]="false";
|
| 226 |
liveuser |
14685 |
|
| 3 |
liveuser |
14686 |
#設置執行失敗訊息
|
|
|
14687 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
14688 |
|
| 3 |
liveuser |
14689 |
#回傳結果
|
|
|
14690 |
return $result;
|
| 226 |
liveuser |
14691 |
|
| 3 |
liveuser |
14692 |
}#if end
|
| 226 |
liveuser |
14693 |
|
| 3 |
liveuser |
14694 |
#如果檢查參數不通過
|
|
|
14695 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
14696 |
|
| 3 |
liveuser |
14697 |
#設置執行失敗
|
|
|
14698 |
$result["status"]="false";
|
| 226 |
liveuser |
14699 |
|
| 3 |
liveuser |
14700 |
#設置執行失敗訊息
|
|
|
14701 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
14702 |
|
| 3 |
liveuser |
14703 |
#回傳結果
|
|
|
14704 |
return $result;
|
| 226 |
liveuser |
14705 |
|
| 3 |
liveuser |
14706 |
}#if end
|
|
|
14707 |
|
|
|
14708 |
#檢查檔案是否存在
|
|
|
14709 |
#函式說明:
|
|
|
14710 |
#檢查多個檔案與資料夾是否存在.
|
|
|
14711 |
#回傳的結果:
|
|
|
14712 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
14713 |
#$result["error"],錯誤訊息陣列.
|
|
|
14714 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
14715 |
#$result["argu"],使用的參數.
|
|
|
14716 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
14717 |
#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
|
|
|
14718 |
#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
|
|
|
14719 |
#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
|
|
|
14720 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
14721 |
#必填參數:
|
|
|
14722 |
#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
14723 |
$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
|
|
|
14724 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
14725 |
$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
14726 |
#可省略參數
|
|
|
14727 |
#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
|
|
|
14728 |
#$conf["disableWebSearch"]="false";
|
|
|
14729 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
14730 |
#$conf["userDir"]="true";
|
|
|
14731 |
#$conf["web"],字串,"true"代表位網頁系統,"false"為檔案系統,預設為"false".
|
|
|
14732 |
$conf["fileAccess::checkMultiFileExist"]["web"]=$conf["web"];
|
|
|
14733 |
#參考資料來源:
|
|
|
14734 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
14735 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
14736 |
#備註:
|
|
|
14737 |
#函數file_exists檢查的路徑為檔案系統的路徑
|
|
|
14738 |
$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
|
|
|
14739 |
unset($conf["fileAccess::checkMultiFileExist"]);
|
|
|
14740 |
|
|
|
14741 |
#如果執行失敗
|
|
|
14742 |
if($checkMultiFileExist["status"]==="false"){
|
| 226 |
liveuser |
14743 |
|
| 3 |
liveuser |
14744 |
#設置執行失敗
|
|
|
14745 |
$result["status"]="false";
|
| 226 |
liveuser |
14746 |
|
| 3 |
liveuser |
14747 |
#設置執行失敗訊息
|
|
|
14748 |
$result["error"]=$checkMultiFileExist;
|
| 226 |
liveuser |
14749 |
|
| 3 |
liveuser |
14750 |
#回傳結果
|
|
|
14751 |
return $result;
|
| 226 |
liveuser |
14752 |
|
| 3 |
liveuser |
14753 |
}#if end
|
| 226 |
liveuser |
14754 |
|
| 3 |
liveuser |
14755 |
#如果檔案無法存取
|
|
|
14756 |
if($checkMultiFileExist["allExist"]==="false"){
|
| 226 |
liveuser |
14757 |
|
| 3 |
liveuser |
14758 |
#設置執行失敗
|
|
|
14759 |
$result["status"]="false";
|
| 226 |
liveuser |
14760 |
|
| 3 |
liveuser |
14761 |
#設置執行失敗訊息
|
|
|
14762 |
$result["error"]=$checkMultiFileExist;
|
| 226 |
liveuser |
14763 |
|
| 3 |
liveuser |
14764 |
#回傳結果
|
|
|
14765 |
return $result;
|
| 226 |
liveuser |
14766 |
|
| 3 |
liveuser |
14767 |
}#if end
|
|
|
14768 |
|
|
|
14769 |
#取得檔案的行數
|
|
|
14770 |
#函式說明:
|
|
|
14771 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
14772 |
#回傳的結果:
|
|
|
14773 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
14774 |
#$result["error"],錯誤訊息陣列.
|
|
|
14775 |
#$result["function"],當前執行的函數名稱.
|
|
|
14776 |
#$result["argu"],使用的參數.
|
|
|
14777 |
#$result["cmd"],執行的指令內容.
|
|
|
14778 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
14779 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
14780 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
14781 |
#$result["running"],是否還在執行.
|
|
|
14782 |
#$result["pid"],pid.
|
|
|
14783 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
14784 |
#必填的參數
|
|
|
14785 |
#$conf["command"],字串,要執行的指令與.
|
|
|
14786 |
$conf["external::callShell"]["command"]="cat";
|
|
|
14787 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
| 226 |
liveuser |
14788 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
| 3 |
liveuser |
14789 |
#可省略參數:
|
|
|
14790 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
14791 |
$conf["external::callShell"]["argu"]=array($conf["file"],"|","wc","-l");
|
|
|
14792 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
| 226 |
liveuser |
14793 |
#$conf["arguIsAddr"]=array();
|
| 3 |
liveuser |
14794 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
14795 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
14796 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
14797 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
14798 |
#$conf["enablePrintDescription"]="true";
|
|
|
14799 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
14800 |
#$conf["printDescription"]="";
|
|
|
14801 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
|
|
|
14802 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
14803 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
14804 |
#$conf["username"]="";
|
|
|
14805 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
14806 |
#$conf["password"]="";
|
|
|
14807 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
14808 |
#$conf["useScript"]="";
|
|
|
14809 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
14810 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
14811 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
14812 |
#$conf["inBackGround"]="";
|
|
|
14813 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
14814 |
#$conf["getErr"]="false";
|
|
|
14815 |
#備註:
|
|
|
14816 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
14817 |
#參考資料:
|
|
|
14818 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
14819 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
14820 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
14821 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
14822 |
unset($conf["external::callShell"]);
|
|
|
14823 |
|
|
|
14824 |
#如果檢查參數失敗
|
|
|
14825 |
if($callShell["status"]==="false"){
|
| 226 |
liveuser |
14826 |
|
| 3 |
liveuser |
14827 |
#設置執行失敗
|
|
|
14828 |
$result["status"]="false";
|
| 226 |
liveuser |
14829 |
|
| 3 |
liveuser |
14830 |
#設置執行失敗訊息
|
|
|
14831 |
$result["error"]=$callShell;
|
| 226 |
liveuser |
14832 |
|
| 3 |
liveuser |
14833 |
#回傳結果
|
|
|
14834 |
return $result;
|
| 226 |
liveuser |
14835 |
|
| 3 |
liveuser |
14836 |
}#if end
|
| 226 |
liveuser |
14837 |
|
| 3 |
liveuser |
14838 |
#取得檔案總行數
|
|
|
14839 |
$result["totalLineCount"]=$callShell["output"][0];
|
| 226 |
liveuser |
14840 |
|
| 3 |
liveuser |
14841 |
#如果未設置 $conf["line2start"]
|
|
|
14842 |
if(!isset($conf["line2start"])){
|
| 226 |
liveuser |
14843 |
|
| 3 |
liveuser |
14844 |
#$conf["line2start"]為總行數減去一次要看的行數減1
|
|
|
14845 |
$conf["line2start"]=$result["totalLineCount"]-$conf["linesPerTime"]+1;
|
| 226 |
liveuser |
14846 |
|
|
|
14847 |
}#if end
|
|
|
14848 |
|
|
|
14849 |
#如果開始行數小於1
|
| 3 |
liveuser |
14850 |
if($conf["line2start"]<1){
|
| 226 |
liveuser |
14851 |
|
| 3 |
liveuser |
14852 |
#$conf["line2start"]為總行數減去一次要看的行數減1
|
|
|
14853 |
$conf["line2start"]=$result["totalLineCount"]-$conf["linesPerTime"]+1;
|
| 226 |
liveuser |
14854 |
|
| 3 |
liveuser |
14855 |
}#if end
|
| 226 |
liveuser |
14856 |
|
|
|
14857 |
#如果開始行數小於1
|
| 3 |
liveuser |
14858 |
if($conf["line2start"]<1){
|
| 226 |
liveuser |
14859 |
|
| 3 |
liveuser |
14860 |
#$conf["line2start"]為1
|
|
|
14861 |
$conf["line2start"]=1;
|
| 226 |
liveuser |
14862 |
|
| 3 |
liveuser |
14863 |
}#if end
|
| 226 |
liveuser |
14864 |
|
| 3 |
liveuser |
14865 |
#取得指定範圍的行數
|
|
|
14866 |
#取得檔案的行數
|
|
|
14867 |
#函式說明:
|
|
|
14868 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
14869 |
#回傳的結果:
|
|
|
14870 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
14871 |
#$result["error"],錯誤訊息陣列.
|
|
|
14872 |
#$result["function"],當前執行的函數名稱.
|
|
|
14873 |
#$result["argu"],使用的參數.
|
|
|
14874 |
#$result["cmd"],執行的指令內容.
|
|
|
14875 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
14876 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
14877 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
14878 |
#$result["running"],是否還在執行.
|
|
|
14879 |
#$result["pid"],pid.
|
|
|
14880 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
14881 |
#必填的參數
|
|
|
14882 |
#$conf["command"],字串,要執行的指令與.
|
|
|
14883 |
$conf["external::callShell"]["command"]="sed";
|
|
|
14884 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
| 226 |
liveuser |
14885 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
| 3 |
liveuser |
14886 |
#可省略參數:
|
|
|
14887 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
14888 |
$conf["external::callShell"]["argu"]=array("-n",$conf["line2start"].",".($conf["line2start"]+$conf["linesPerTime"]-1)."p",$conf["file"]);
|
|
|
14889 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
| 226 |
liveuser |
14890 |
#$conf["arguIsAddr"]=array();
|
| 3 |
liveuser |
14891 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
14892 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
14893 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
14894 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
14895 |
#$conf["enablePrintDescription"]="true";
|
|
|
14896 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
14897 |
#$conf["printDescription"]="";
|
|
|
14898 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
|
|
|
14899 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
14900 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
14901 |
#$conf["username"]="";
|
|
|
14902 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
14903 |
#$conf["password"]="";
|
|
|
14904 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
14905 |
#$conf["useScript"]="";
|
|
|
14906 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
14907 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
14908 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
14909 |
#$conf["inBackGround"]="";
|
|
|
14910 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
14911 |
#$conf["getErr"]="false";
|
|
|
14912 |
#備註:
|
|
|
14913 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
14914 |
#參考資料:
|
|
|
14915 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
14916 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
14917 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
14918 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
14919 |
unset($conf["external::callShell"]);
|
|
|
14920 |
|
|
|
14921 |
#如果檢查參數失敗
|
|
|
14922 |
if($callShell["status"]==="false"){
|
| 226 |
liveuser |
14923 |
|
| 3 |
liveuser |
14924 |
#設置執行失敗
|
|
|
14925 |
$result["status"]="false";
|
| 226 |
liveuser |
14926 |
|
| 3 |
liveuser |
14927 |
#設置執行失敗訊息
|
|
|
14928 |
$result["error"]=$callShell;
|
| 226 |
liveuser |
14929 |
|
| 3 |
liveuser |
14930 |
#回傳結果
|
|
|
14931 |
return $result;
|
| 226 |
liveuser |
14932 |
|
| 3 |
liveuser |
14933 |
}#if end
|
|
|
14934 |
|
|
|
14935 |
#取得輸出的行數
|
|
|
14936 |
$result["lines"]=count($callShell["output"]);
|
|
|
14937 |
|
|
|
14938 |
#取得目前的輸出內容
|
|
|
14939 |
$result["content"]=$callShell["output"];
|
|
|
14940 |
|
|
|
14941 |
#取得當前行數
|
|
|
14942 |
$result["lineNum"]=$conf["line2start"]+$result["lines"]-1;
|
|
|
14943 |
|
| 226 |
liveuser |
14944 |
#如果當前行號小於總行數
|
| 3 |
liveuser |
14945 |
if($result["lineNum"]<$result["totalLineCount"]){
|
|
|
14946 |
|
|
|
14947 |
#設置還有剩餘的內容
|
|
|
14948 |
$result["left"]="true";
|
| 226 |
liveuser |
14949 |
|
| 3 |
liveuser |
14950 |
}#if end
|
|
|
14951 |
|
| 226 |
liveuser |
14952 |
#反之
|
| 3 |
liveuser |
14953 |
else{
|
|
|
14954 |
|
|
|
14955 |
#設置無剩餘的內容
|
|
|
14956 |
$result["left"]="false";
|
|
|
14957 |
|
|
|
14958 |
}#else end
|
|
|
14959 |
|
|
|
14960 |
#設置執行正常
|
|
|
14961 |
$result["status"]="true";
|
|
|
14962 |
|
|
|
14963 |
#回傳結果
|
|
|
14964 |
return $result;
|
|
|
14965 |
|
|
|
14966 |
}#function tail end
|
| 226 |
liveuser |
14967 |
|
| 3 |
liveuser |
14968 |
/*
|
|
|
14969 |
#函式說明:
|
|
|
14970 |
#解析PHP檔案裡面的變數.
|
|
|
14971 |
#回傳結果:
|
|
|
14972 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
14973 |
#$result["error"],錯誤訊息.
|
|
|
14974 |
#$result["function"],當前執行的函數名稱.
|
| 226 |
liveuser |
14975 |
#$result["argu"],所使用的參數.
|
| 3 |
liveuser |
14976 |
#$result["content"],找到的變數內容陣列,若有多個變數則會用array來表示.
|
|
|
14977 |
#必填參數:
|
|
|
14978 |
#$conf["file"],字串,檔案的路徑與名稱.
|
|
|
14979 |
$conf["file"]="";
|
|
|
14980 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
14981 |
$conf["fileArgu"]=__FILE__;
|
|
|
14982 |
#$conf["varName"],字串陣列,要搜尋的變數名稱,例如要搜尋變數$email則輸入"email".
|
|
|
14983 |
$conf["varName"]=array();
|
|
|
14984 |
#可省略參數:
|
|
|
14985 |
#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false",預設為"false".
|
|
|
14986 |
#$conf["web"]="true";
|
| 255 |
liveuser |
14987 |
#$conf["allVarCountSame"],字串,是否每個參數的數量要一致,預設為"false"不要;反之為"true"代表要.
|
|
|
14988 |
#$conf["allVarCountSame"]="false";
|
| 3 |
liveuser |
14989 |
#參考資料:
|
|
|
14990 |
#https://www.php.net/manual/en/function.parse-str.php
|
|
|
14991 |
#備註:
|
|
|
14992 |
#無.
|
|
|
14993 |
*/
|
|
|
14994 |
public static function parseVaraiableInPHPfile(&$conf){
|
| 226 |
liveuser |
14995 |
|
| 3 |
liveuser |
14996 |
#初始化要回傳的結果
|
|
|
14997 |
$result=array();
|
|
|
14998 |
|
|
|
14999 |
#取得當前執行的函數名稱
|
|
|
15000 |
$result["function"]=__FUNCTION__;
|
|
|
15001 |
|
|
|
15002 |
#如果沒有參數
|
|
|
15003 |
if(func_num_args()==0){
|
| 226 |
liveuser |
15004 |
|
| 3 |
liveuser |
15005 |
#設置執行失敗
|
|
|
15006 |
$result["status"]="false";
|
| 226 |
liveuser |
15007 |
|
| 3 |
liveuser |
15008 |
#設置執行錯誤訊息
|
|
|
15009 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
15010 |
|
| 3 |
liveuser |
15011 |
#回傳結果
|
|
|
15012 |
return $result;
|
|
|
15013 |
|
| 226 |
liveuser |
15014 |
}#if end
|
|
|
15015 |
|
| 3 |
liveuser |
15016 |
#取得參數
|
|
|
15017 |
$result["argu"]=$conf;
|
|
|
15018 |
|
|
|
15019 |
#如果 $conf 不為陣列
|
|
|
15020 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
15021 |
|
| 3 |
liveuser |
15022 |
#設置執行失敗
|
|
|
15023 |
$result["status"]="false";
|
| 226 |
liveuser |
15024 |
|
| 3 |
liveuser |
15025 |
#設置執行錯誤訊息
|
|
|
15026 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
15027 |
|
| 3 |
liveuser |
15028 |
#如果傳入的參數為 null
|
|
|
15029 |
if($conf===null){
|
| 226 |
liveuser |
15030 |
|
| 3 |
liveuser |
15031 |
#設置執行錯誤訊息
|
|
|
15032 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
15033 |
|
| 3 |
liveuser |
15034 |
}#if end
|
|
|
15035 |
|
|
|
15036 |
#回傳結果
|
|
|
15037 |
return $result;
|
| 226 |
liveuser |
15038 |
|
| 3 |
liveuser |
15039 |
}#if end
|
| 226 |
liveuser |
15040 |
|
| 3 |
liveuser |
15041 |
#函式說明:
|
|
|
15042 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
15043 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
15044 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
15045 |
#$result["function"],當前執行的函式名稱.
|
|
|
15046 |
#$result["argu"],設置給予的參數.
|
|
|
15047 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
15048 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
15049 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
15050 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
15051 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
15052 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
15053 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
15054 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
15055 |
#必填寫的參數:
|
|
|
15056 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
| 226 |
liveuser |
15057 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
| 3 |
liveuser |
15058 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
15059 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
15060 |
#可以省略的參數:
|
|
|
15061 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
15062 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu","varName");
|
|
|
15063 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
15064 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array");
|
|
|
15065 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
15066 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
15067 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
15068 |
$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file","fileArgu","varName");
|
|
|
15069 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
15070 |
#$conf["canBeEmpty"]=array();
|
|
|
15071 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
| 255 |
liveuser |
15072 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web","allVarCountSame");
|
| 3 |
liveuser |
15073 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
| 255 |
liveuser |
15074 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web","allVarCountSame");
|
| 226 |
liveuser |
15075 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 255 |
liveuser |
15076 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
| 3 |
liveuser |
15077 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
| 255 |
liveuser |
15078 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false");
|
| 3 |
liveuser |
15079 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
15080 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
15081 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
15082 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
15083 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
15084 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
15085 |
#參考資料來源:
|
|
|
15086 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
15087 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
15088 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
15089 |
|
| 3 |
liveuser |
15090 |
#如果檢查參數失敗
|
|
|
15091 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
15092 |
|
| 3 |
liveuser |
15093 |
#設置執行失敗
|
|
|
15094 |
$result["status"]="false";
|
| 226 |
liveuser |
15095 |
|
| 3 |
liveuser |
15096 |
#設置執行失敗訊息
|
|
|
15097 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
15098 |
|
| 3 |
liveuser |
15099 |
#回傳結果
|
|
|
15100 |
return $result;
|
| 226 |
liveuser |
15101 |
|
| 3 |
liveuser |
15102 |
}#if end
|
| 226 |
liveuser |
15103 |
|
| 3 |
liveuser |
15104 |
#如果檢查參數不通過
|
|
|
15105 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
15106 |
|
| 3 |
liveuser |
15107 |
#設置執行失敗
|
|
|
15108 |
$result["status"]="false";
|
| 226 |
liveuser |
15109 |
|
| 3 |
liveuser |
15110 |
#設置執行失敗訊息
|
|
|
15111 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
15112 |
|
| 3 |
liveuser |
15113 |
#回傳結果
|
|
|
15114 |
return $result;
|
| 226 |
liveuser |
15115 |
|
| 3 |
liveuser |
15116 |
}#if end
|
| 226 |
liveuser |
15117 |
|
| 3 |
liveuser |
15118 |
#初始化儲存解析出來的變數內容
|
|
|
15119 |
$result["content"]=array();
|
| 226 |
liveuser |
15120 |
|
| 3 |
liveuser |
15121 |
#讀取檔案
|
|
|
15122 |
#函式說明:
|
|
|
15123 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
15124 |
#回傳的變數說明:
|
|
|
15125 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
|
|
|
15126 |
#$result["error"],錯誤訊息提示.
|
|
|
15127 |
#$result["warning"],警告訊息.
|
|
|
15128 |
#$result["function"],當前執行的函數名稱.
|
|
|
15129 |
#$result["fileContent"],爲檔案的內容陣列.
|
|
|
15130 |
#$result["lineCount"],爲檔案內容總共的行數.
|
|
|
15131 |
#$result["fullContent"],為檔案的完整內容.
|
|
|
15132 |
#$result["base64data"],為檔案的base64內容.
|
|
|
15133 |
#$result["mimeType"],為檔案的mime type.
|
|
|
15134 |
#必填參數:
|
|
|
15135 |
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
|
|
|
15136 |
$conf["ileAccess::getFileContent"]["filePositionAndName"]=$conf["file"];
|
|
|
15137 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
15138 |
$conf["ileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
|
|
|
15139 |
#可省略參數:
|
|
|
15140 |
#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
|
|
|
15141 |
$conf["ileAccess::getFileContent"]["web"]=$conf["web"];
|
|
|
15142 |
#參考資料:
|
|
|
15143 |
#file(),取得檔案內容的行數.
|
|
|
15144 |
#file=>http:#php.net/manual/en/function.file.php
|
|
|
15145 |
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
|
|
|
15146 |
#filesize=>http://php.net/manual/en/function.filesize.php
|
|
|
15147 |
$getFileContent=fileAccess::getFileContent($conf["ileAccess::getFileContent"]);
|
|
|
15148 |
unset($conf["ileAccess::getFileContent"]);
|
|
|
15149 |
|
|
|
15150 |
#如果讀取檔案失敗
|
|
|
15151 |
if($getFileContent["status"]==="false"){
|
| 226 |
liveuser |
15152 |
|
| 3 |
liveuser |
15153 |
#設置執行失敗
|
|
|
15154 |
$result["status"]="false";
|
| 226 |
liveuser |
15155 |
|
| 3 |
liveuser |
15156 |
#設置執行失敗訊息
|
|
|
15157 |
$result["error"]=$getFileContent;
|
| 226 |
liveuser |
15158 |
|
| 3 |
liveuser |
15159 |
#回傳結果
|
|
|
15160 |
return $result;
|
| 226 |
liveuser |
15161 |
|
| 3 |
liveuser |
15162 |
}#if end
|
| 226 |
liveuser |
15163 |
|
| 3 |
liveuser |
15164 |
#針對每列檔案內容
|
|
|
15165 |
foreach($getFileContent["fileContent"] as $line){
|
| 226 |
liveuser |
15166 |
|
| 3 |
liveuser |
15167 |
#針對每個要搜尋的變數
|
|
|
15168 |
foreach($conf["varName"] as $keyWord){
|
| 226 |
liveuser |
15169 |
|
| 3 |
liveuser |
15170 |
#如果關鍵字小於被搜尋的字串長度
|
|
|
15171 |
if( strlen($line) < strlen($keyWord)+1 ){
|
| 226 |
liveuser |
15172 |
|
| 3 |
liveuser |
15173 |
#跳過
|
|
|
15174 |
continue;
|
| 226 |
liveuser |
15175 |
|
| 3 |
liveuser |
15176 |
}#if end
|
| 226 |
liveuser |
15177 |
|
| 3 |
liveuser |
15178 |
#函式說明:
|
|
|
15179 |
#取得符合特定字首與字尾的字串
|
|
|
15180 |
#回傳結果:
|
|
|
15181 |
#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
|
|
|
15182 |
#$result["function"],當前執行的函數名稱.
|
|
|
15183 |
#$result["error"],錯誤訊息陣列.
|
|
|
15184 |
#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
|
|
|
15185 |
#$result["returnString"],爲符合字首條件的字串內容。
|
|
|
15186 |
#$result["argu"],使用的參數.
|
|
|
15187 |
#必填參數:
|
|
|
15188 |
#$conf["checkString"],字串,要檢查的字串.
|
|
|
15189 |
$conf["search::getMeetConditionsString"]["checkString"]=$line;
|
|
|
15190 |
#可省略參數:
|
|
|
15191 |
#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
15192 |
$conf["search::getMeetConditionsString"]["frontWord"]="$".$keyWord;
|
|
|
15193 |
#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
15194 |
$conf["search::getMeetConditionsString"]["tailWord"]=";";
|
|
|
15195 |
#參考資料:
|
|
|
15196 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
15197 |
$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
|
|
|
15198 |
unset($conf["search::getMeetConditionsString"]);
|
| 226 |
liveuser |
15199 |
|
| 3 |
liveuser |
15200 |
#如果失敗
|
|
|
15201 |
if($getMeetConditionsString["status"]==="false"){
|
|
|
15202 |
|
|
|
15203 |
#設置執行失敗
|
|
|
15204 |
$result["status"]="false";
|
| 226 |
liveuser |
15205 |
|
| 3 |
liveuser |
15206 |
#設置執行失敗訊息
|
|
|
15207 |
$result["error"]=$getMeetConditionsString;
|
| 226 |
liveuser |
15208 |
|
| 3 |
liveuser |
15209 |
#回傳結果
|
|
|
15210 |
return $result;
|
| 226 |
liveuser |
15211 |
|
|
|
15212 |
}#if end
|
|
|
15213 |
|
| 3 |
liveuser |
15214 |
#如果有找到關鍵字
|
|
|
15215 |
if($getMeetConditionsString["founded"]==="true"){
|
| 226 |
liveuser |
15216 |
|
| 3 |
liveuser |
15217 |
#剔除變數名稱
|
|
|
15218 |
#函式說明:
|
|
|
15219 |
#將字串特定關鍵字與其前面的內容剔除
|
|
|
15220 |
#回傳結果:
|
|
|
15221 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
15222 |
#$result["error"],錯誤訊息陣列.
|
|
|
15223 |
#$result["warning"],警告訊息鎮列.
|
|
|
15224 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
15225 |
#$result["function"],當前執行的函數名稱.
|
|
|
15226 |
#$result["oriStr"],要處理的原始字串內容.
|
| 226 |
liveuser |
15227 |
#$result["content"],處理好的的字串內容.
|
| 3 |
liveuser |
15228 |
#必填參數:
|
|
|
15229 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
15230 |
$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$line;
|
|
|
15231 |
#$conf["keyWord"],字串,特定字串.
|
|
|
15232 |
$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="$".$keyWord;
|
|
|
15233 |
#可省略參數:
|
|
|
15234 |
#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,直到沒有關鍵字為止.
|
|
|
15235 |
#$conf["recursive"]="true";
|
|
|
15236 |
#參考資料:
|
|
|
15237 |
#無.
|
|
|
15238 |
#備註:
|
|
|
15239 |
#無.
|
|
|
15240 |
$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
15241 |
unset($conf["stringProcess::delStrBeforeKeyWord"]);
|
| 226 |
liveuser |
15242 |
|
| 3 |
liveuser |
15243 |
#如果執行失敗
|
|
|
15244 |
if($delStrBeforeKeyWord["status"]==="false"){
|
| 226 |
liveuser |
15245 |
|
| 3 |
liveuser |
15246 |
#設置執行失敗
|
|
|
15247 |
$result["status"]="false";
|
| 226 |
liveuser |
15248 |
|
| 3 |
liveuser |
15249 |
#設置執行失敗訊息
|
|
|
15250 |
$result["error"]=$delStrBeforeKeyWord;
|
| 226 |
liveuser |
15251 |
|
| 3 |
liveuser |
15252 |
#回傳結果
|
|
|
15253 |
return $result;
|
| 226 |
liveuser |
15254 |
|
| 3 |
liveuser |
15255 |
}#if end
|
| 226 |
liveuser |
15256 |
|
| 3 |
liveuser |
15257 |
#如果沒有找到應該存在的php變數
|
|
|
15258 |
if($delStrBeforeKeyWord["founded"]==="false"){
|
| 226 |
liveuser |
15259 |
|
| 3 |
liveuser |
15260 |
#設置執行失敗
|
|
|
15261 |
$result["status"]="false";
|
| 226 |
liveuser |
15262 |
|
| 3 |
liveuser |
15263 |
#設置執行失敗訊息
|
|
|
15264 |
$result["error"]=$delStrBeforeKeyWord;
|
| 226 |
liveuser |
15265 |
|
| 3 |
liveuser |
15266 |
#回傳結果
|
|
|
15267 |
return $result;
|
| 226 |
liveuser |
15268 |
|
| 3 |
liveuser |
15269 |
}#if end
|
| 226 |
liveuser |
15270 |
|
| 3 |
liveuser |
15271 |
#剔除 "=" 前面的內容
|
|
|
15272 |
#函式說明:
|
|
|
15273 |
#將字串特定關鍵字與其前面的內容剔除
|
|
|
15274 |
#回傳結果:
|
|
|
15275 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
15276 |
#$result["error"],錯誤訊息陣列.
|
|
|
15277 |
#$result["warning"],警告訊息鎮列.
|
|
|
15278 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
15279 |
#$result["function"],當前執行的函數名稱.
|
|
|
15280 |
#$result["oriStr"],要處理的原始字串內容.
|
| 226 |
liveuser |
15281 |
#$result["content"],處理好的的字串內容.
|
| 3 |
liveuser |
15282 |
#必填參數:
|
|
|
15283 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
15284 |
$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$delStrBeforeKeyWord["content"];
|
|
|
15285 |
#$conf["keyWord"],字串,特定字串.
|
|
|
15286 |
$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="=";
|
|
|
15287 |
#可省略參數:
|
|
|
15288 |
#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,直到沒有關鍵字為止.
|
|
|
15289 |
#$conf["recursive"]="true";
|
|
|
15290 |
#參考資料:
|
|
|
15291 |
#無.
|
|
|
15292 |
#備註:
|
|
|
15293 |
#無.
|
|
|
15294 |
$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
15295 |
unset($conf["stringProcess::delStrBeforeKeyWord"]);
|
| 226 |
liveuser |
15296 |
|
| 3 |
liveuser |
15297 |
#如果執行失敗
|
|
|
15298 |
if($delStrBeforeKeyWord["status"]==="false"){
|
| 226 |
liveuser |
15299 |
|
| 3 |
liveuser |
15300 |
#設置執行失敗
|
|
|
15301 |
$result["status"]="false";
|
| 226 |
liveuser |
15302 |
|
| 3 |
liveuser |
15303 |
#設置執行失敗訊息
|
|
|
15304 |
$result["error"]=$delStrBeforeKeyWord;
|
| 226 |
liveuser |
15305 |
|
| 3 |
liveuser |
15306 |
#回傳結果
|
|
|
15307 |
return $result;
|
| 226 |
liveuser |
15308 |
|
| 3 |
liveuser |
15309 |
}#if end
|
| 226 |
liveuser |
15310 |
|
| 3 |
liveuser |
15311 |
#如果沒有找“=”關鍵字
|
|
|
15312 |
if($delStrBeforeKeyWord["founded"]==="false"){
|
| 226 |
liveuser |
15313 |
|
| 3 |
liveuser |
15314 |
#跳過
|
|
|
15315 |
continue;
|
| 226 |
liveuser |
15316 |
|
| 3 |
liveuser |
15317 |
}#if end
|
| 226 |
liveuser |
15318 |
|
| 3 |
liveuser |
15319 |
#剔除 value 前面的空白
|
|
|
15320 |
#函式說明:
|
| 288 |
liveuser |
15321 |
#移除字串開頭的特定內容
|
| 3 |
liveuser |
15322 |
#回傳結果:
|
| 288 |
liveuser |
15323 |
#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
|
| 3 |
liveuser |
15324 |
#$result["error"],錯誤訊息陣列.
|
| 288 |
liveuser |
15325 |
#$result["function"],當前執行的函數.
|
|
|
15326 |
#$result["content"],處理好的字串.
|
|
|
15327 |
#$result["argu"],使用的參數.
|
| 3 |
liveuser |
15328 |
#必填參數:
|
| 288 |
liveuser |
15329 |
#$conf["inputStr"],字串,要檢查並移除開頭有 $conf["keyWords"] 的字串.
|
|
|
15330 |
$conf["stringProcess::delKeyWordsInStrHead"]["inputStr"]=$delStrBeforeKeyWord["content"];
|
|
|
15331 |
#$conf["keyWord"],字串,要移除的字串開頭關鍵字.
|
|
|
15332 |
$conf["stringProcess::delKeyWordsInStrHead"]["keyWord"]=" ";
|
| 3 |
liveuser |
15333 |
#可省略參數:
|
| 288 |
liveuser |
15334 |
#$conf["recursive"],字串,"true"代表要遞迴移除開頭的關鍵字,預設為"false",只移除開頭關鍵字1次.
|
|
|
15335 |
$conf["stringProcess::delKeyWordsInStrHead"]["recursive"]="true";
|
| 3 |
liveuser |
15336 |
#參考資料:
|
|
|
15337 |
#無.
|
|
|
15338 |
#備註:
|
|
|
15339 |
#無.
|
| 288 |
liveuser |
15340 |
$delKeyWordsInStrHead=stringProcess::delKeyWordsInStrHead($conf["stringProcess::delKeyWordsInStrHead"]);
|
|
|
15341 |
unset($conf["stringProcess::delKeyWordsInStrHead"]);
|
| 226 |
liveuser |
15342 |
|
| 3 |
liveuser |
15343 |
#如果執行失敗
|
| 288 |
liveuser |
15344 |
if($delKeyWordsInStrHead["status"]==="false"){
|
| 226 |
liveuser |
15345 |
|
| 3 |
liveuser |
15346 |
#設置執行失敗
|
|
|
15347 |
$result["status"]="false";
|
| 226 |
liveuser |
15348 |
|
| 3 |
liveuser |
15349 |
#設置執行失敗訊息
|
| 288 |
liveuser |
15350 |
$result["error"]=$delKeyWordsInStrHead;
|
| 226 |
liveuser |
15351 |
|
| 3 |
liveuser |
15352 |
#回傳結果
|
|
|
15353 |
return $result;
|
| 226 |
liveuser |
15354 |
|
| 3 |
liveuser |
15355 |
}#if end
|
| 226 |
liveuser |
15356 |
|
| 3 |
liveuser |
15357 |
#取得找到的變數
|
| 288 |
liveuser |
15358 |
eval("\$result[\"content\"][\"".$keyWord."\"][]=".$delKeyWordsInStrHead["content"]);
|
| 226 |
liveuser |
15359 |
|
| 3 |
liveuser |
15360 |
}#if end
|
| 226 |
liveuser |
15361 |
|
| 3 |
liveuser |
15362 |
}#foreach end
|
| 226 |
liveuser |
15363 |
|
| 3 |
liveuser |
15364 |
}#foreach end
|
| 226 |
liveuser |
15365 |
|
| 255 |
liveuser |
15366 |
#如果 allVarCountSame 設置為 "true"
|
|
|
15367 |
if($conf["allVarCountSame"]==="true"){
|
|
|
15368 |
|
|
|
15369 |
#每個變數的數量初始為0
|
|
|
15370 |
$count=0;
|
|
|
15371 |
|
|
|
15372 |
#針對每個解析出來的變數
|
|
|
15373 |
foreach($conf["varName"] as $varName){
|
|
|
15374 |
|
|
|
15375 |
#取得該變數數量
|
|
|
15376 |
$varCount=count($result["content"][$varName]);
|
|
|
15377 |
|
|
|
15378 |
#如果尚無變數數量資料
|
|
|
15379 |
if($count===0){
|
|
|
15380 |
|
|
|
15381 |
#直接儲存之
|
|
|
15382 |
$count=$varCount;
|
|
|
15383 |
|
|
|
15384 |
#看下一個變數
|
|
|
15385 |
continue;
|
|
|
15386 |
|
|
|
15387 |
}#if end
|
|
|
15388 |
|
|
|
15389 |
#如果變數數量不一樣
|
|
|
15390 |
if($count!==$varCount){
|
|
|
15391 |
|
|
|
15392 |
#設置執行失敗
|
|
|
15393 |
$result["status"]="false";
|
|
|
15394 |
|
|
|
15395 |
#設置執行失敗訊息
|
|
|
15396 |
$result["error"]="config file error";
|
|
|
15397 |
|
|
|
15398 |
#回傳結果
|
|
|
15399 |
return $result;
|
|
|
15400 |
|
|
|
15401 |
}#if end
|
|
|
15402 |
|
|
|
15403 |
|
|
|
15404 |
|
|
|
15405 |
}#foreach end
|
|
|
15406 |
|
|
|
15407 |
}#if end
|
|
|
15408 |
|
| 3 |
liveuser |
15409 |
#設置執行正常
|
|
|
15410 |
$result["status"]="true";
|
| 226 |
liveuser |
15411 |
|
| 3 |
liveuser |
15412 |
#回傳結果
|
|
|
15413 |
return $result;
|
| 226 |
liveuser |
15414 |
|
| 3 |
liveuser |
15415 |
}#function parseVaraiableInPHPfile end
|
|
|
15416 |
|
|
|
15417 |
/*
|
|
|
15418 |
#函式說明:
|
|
|
15419 |
#開啟特定目錄,取得底下的檔案路徑清單.
|
|
|
15420 |
#回傳結果:
|
|
|
15421 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
15422 |
#$result["error"],錯誤訊息.
|
|
|
15423 |
#$result["function"],當前執行的函數名稱.
|
|
|
15424 |
#$result["argu"],所使用的參數.
|
|
|
15425 |
#$result["content"],讀取到的內容陣列.
|
|
|
15426 |
#$result["content"][$i],第$i+1個結果.
|
|
|
15427 |
#$result["content"][$i]["name"],第$i+1個名稱.
|
|
|
15428 |
#$result["content"][$i]["dir"],第$i+1個檔案是否為資料夾.
|
|
|
15429 |
#$result["content"][$i]["info"],第$i+1個檔案的額外資訊.
|
|
|
15430 |
#$result["content"][$i]["size"],第$i+1個檔案的大小(bytes).
|
|
|
15431 |
#必填參數:
|
|
|
15432 |
#$conf["path"],字串,要取得檔案資訊的所屬路徑.
|
|
|
15433 |
$conf["path"]="";
|
|
|
15434 |
#可省略參數:
|
|
|
15435 |
#無.
|
|
|
15436 |
#參考資料
|
|
|
15437 |
#無.
|
|
|
15438 |
#備註:
|
|
|
15439 |
#無.
|
|
|
15440 |
*/
|
|
|
15441 |
public static function listInfo(&$conf){
|
| 226 |
liveuser |
15442 |
|
| 3 |
liveuser |
15443 |
#初始化要回傳的結果
|
|
|
15444 |
$result=array();
|
|
|
15445 |
|
|
|
15446 |
#取得當前執行的函數名稱
|
|
|
15447 |
$result["function"]=__FUNCTION__;
|
|
|
15448 |
|
|
|
15449 |
#如果沒有參數
|
|
|
15450 |
if(func_num_args()==0){
|
| 226 |
liveuser |
15451 |
|
| 3 |
liveuser |
15452 |
#設置執行失敗
|
|
|
15453 |
$result["status"]="false";
|
| 226 |
liveuser |
15454 |
|
| 3 |
liveuser |
15455 |
#設置執行錯誤訊息
|
|
|
15456 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
15457 |
|
| 3 |
liveuser |
15458 |
#回傳結果
|
|
|
15459 |
return $result;
|
|
|
15460 |
|
| 226 |
liveuser |
15461 |
}#if end
|
|
|
15462 |
|
| 3 |
liveuser |
15463 |
#取得參數
|
|
|
15464 |
$result["argu"]=$conf;
|
|
|
15465 |
|
|
|
15466 |
#如果 $conf 不為陣列
|
|
|
15467 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
15468 |
|
| 3 |
liveuser |
15469 |
#設置執行失敗
|
|
|
15470 |
$result["status"]="false";
|
| 226 |
liveuser |
15471 |
|
| 3 |
liveuser |
15472 |
#設置執行錯誤訊息
|
|
|
15473 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
15474 |
|
| 3 |
liveuser |
15475 |
#如果傳入的參數為 null
|
|
|
15476 |
if($conf===null){
|
| 226 |
liveuser |
15477 |
|
| 3 |
liveuser |
15478 |
#設置執行錯誤訊息
|
|
|
15479 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
15480 |
|
| 3 |
liveuser |
15481 |
}#if end
|
|
|
15482 |
|
|
|
15483 |
#回傳結果
|
|
|
15484 |
return $result;
|
| 226 |
liveuser |
15485 |
|
| 3 |
liveuser |
15486 |
}#if end
|
| 226 |
liveuser |
15487 |
|
| 3 |
liveuser |
15488 |
#函式說明:
|
|
|
15489 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
15490 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
15491 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
15492 |
#$result["function"],當前執行的函式名稱.
|
|
|
15493 |
#$result["argu"],設置給予的參數.
|
|
|
15494 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
15495 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
15496 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
15497 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
15498 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
15499 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
15500 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
15501 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
15502 |
#必填寫的參數:
|
|
|
15503 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
| 226 |
liveuser |
15504 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
| 3 |
liveuser |
15505 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
15506 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
15507 |
#可以省略的參數:
|
|
|
15508 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
15509 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path");
|
|
|
15510 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
15511 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
15512 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
15513 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
15514 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
15515 |
$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
|
|
|
15516 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
15517 |
#$conf["canBeEmpty"]=array();
|
|
|
15518 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
15519 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web");
|
|
|
15520 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
15521 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
|
| 226 |
liveuser |
15522 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
15523 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
15524 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
15525 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
|
|
15526 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
15527 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
15528 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
15529 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
15530 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
15531 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
15532 |
#參考資料來源:
|
|
|
15533 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
15534 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
15535 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
15536 |
|
| 3 |
liveuser |
15537 |
#如果檢查參數失敗
|
|
|
15538 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
15539 |
|
| 3 |
liveuser |
15540 |
#設置執行失敗
|
|
|
15541 |
$result["status"]="false";
|
| 226 |
liveuser |
15542 |
|
| 3 |
liveuser |
15543 |
#設置執行失敗訊息
|
|
|
15544 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
15545 |
|
| 3 |
liveuser |
15546 |
#回傳結果
|
|
|
15547 |
return $result;
|
| 226 |
liveuser |
15548 |
|
| 3 |
liveuser |
15549 |
}#if end
|
| 226 |
liveuser |
15550 |
|
| 3 |
liveuser |
15551 |
#如果檢查參數不通過
|
|
|
15552 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
15553 |
|
| 3 |
liveuser |
15554 |
#設置執行失敗
|
|
|
15555 |
$result["status"]="false";
|
| 226 |
liveuser |
15556 |
|
| 3 |
liveuser |
15557 |
#設置執行失敗訊息
|
|
|
15558 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
15559 |
|
| 3 |
liveuser |
15560 |
#回傳結果
|
|
|
15561 |
return $result;
|
| 226 |
liveuser |
15562 |
|
| 3 |
liveuser |
15563 |
}#if end
|
| 226 |
liveuser |
15564 |
|
| 3 |
liveuser |
15565 |
#初始化儲存解析出來的變數內容
|
|
|
15566 |
$result["content"]=array();
|
| 226 |
liveuser |
15567 |
|
| 3 |
liveuser |
15568 |
#取得特定位置的資訊
|
|
|
15569 |
$pathInfo=@dir($conf["path"]);
|
| 226 |
liveuser |
15570 |
|
| 3 |
liveuser |
15571 |
#如果取得路徑資訊失敗
|
|
|
15572 |
if($pathInfo===false){
|
| 226 |
liveuser |
15573 |
|
| 3 |
liveuser |
15574 |
#設置執行失敗
|
|
|
15575 |
$result["status"]="false";
|
| 226 |
liveuser |
15576 |
|
| 3 |
liveuser |
15577 |
#設置執行失敗訊息
|
|
|
15578 |
$result["error"][]="無法存取路徑(".$conf["path"].")";
|
| 226 |
liveuser |
15579 |
|
| 3 |
liveuser |
15580 |
#回傳結果
|
|
|
15581 |
return $result;
|
| 226 |
liveuser |
15582 |
|
| 3 |
liveuser |
15583 |
}#if end
|
| 226 |
liveuser |
15584 |
|
| 3 |
liveuser |
15585 |
#讀取底下一個檔案,暫存到 $tmpItem 裡面,且當結果不為 false 時進入迴圈.
|
|
|
15586 |
while(false !== $tmpItem = $pathInfo->read()){
|
| 226 |
liveuser |
15587 |
|
| 3 |
liveuser |
15588 |
#宣告儲存資訊的變數
|
|
|
15589 |
$item=array();
|
| 226 |
liveuser |
15590 |
|
| 3 |
liveuser |
15591 |
#儲存名稱
|
|
|
15592 |
$item["name"]=$tmpItem;
|
| 226 |
liveuser |
15593 |
|
| 3 |
liveuser |
15594 |
#預設不為資料夾
|
|
|
15595 |
$item["dir"]="false";
|
| 226 |
liveuser |
15596 |
|
| 3 |
liveuser |
15597 |
#若為資料夾
|
|
|
15598 |
if(is_dir($conf["path"]."/".$tmpItem)){
|
| 226 |
liveuser |
15599 |
|
| 3 |
liveuser |
15600 |
#設置為"true"
|
|
|
15601 |
$item["dir"]="true";
|
| 226 |
liveuser |
15602 |
|
| 3 |
liveuser |
15603 |
}#if end
|
| 226 |
liveuser |
15604 |
|
| 3 |
liveuser |
15605 |
#取得檔案識別器
|
|
|
15606 |
$finfo = finfo_open(FILEINFO_MIME);
|
| 226 |
liveuser |
15607 |
|
| 3 |
liveuser |
15608 |
#取得 info
|
|
|
15609 |
$item["info"]=@finfo_file($finfo,$conf["path"]."/".$tmpItem);
|
|
|
15610 |
|
|
|
15611 |
#取得檔案大小
|
|
|
15612 |
$item["size"]=filesize($conf["path"]."/".$tmpItem);
|
|
|
15613 |
|
|
|
15614 |
#close connection
|
|
|
15615 |
finfo_close($finfo);
|
| 226 |
liveuser |
15616 |
|
| 3 |
liveuser |
15617 |
#記錄該檔案資訊
|
|
|
15618 |
$result["content"][]=$item;
|
| 226 |
liveuser |
15619 |
|
| 3 |
liveuser |
15620 |
}#while end
|
| 226 |
liveuser |
15621 |
|
| 3 |
liveuser |
15622 |
#設置執行正常
|
|
|
15623 |
$result["status"]="true";
|
| 226 |
liveuser |
15624 |
|
| 3 |
liveuser |
15625 |
#回傳結果
|
|
|
15626 |
return $result;
|
| 226 |
liveuser |
15627 |
|
| 3 |
liveuser |
15628 |
}#function listInfo end
|
|
|
15629 |
|
|
|
15630 |
/*
|
|
|
15631 |
#函式說明:
|
|
|
15632 |
#取得目錄底下的詳細資訊.
|
|
|
15633 |
#回傳結果:
|
|
|
15634 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
15635 |
#$result["error"],錯誤訊息.
|
|
|
15636 |
#$result["function"],當前執行的函數名稱.
|
|
|
15637 |
#$result["size"],該清單的大小,單位為bytes.
|
|
|
15638 |
#$result["dataCount"],該清單的長度.
|
|
|
15639 |
#$result["path"],字串,檢視的路徑,必為"/"結尾.
|
|
|
15640 |
#$result["content"],指定目錄底下的所有檔案資訊.
|
|
|
15641 |
#$result["content"][$i]["nType&permission"],第$i個節點類型、權限.
|
|
|
15642 |
#$result["content"][$i]["nType"],第$i個節點類型,"-"代表檔案,"d"代表資料夾.
|
|
|
15643 |
#$result["content"][$i]["permission"],第$i個節點權限.
|
|
|
15644 |
#$result["content"][$i]["ownByUser"],第$i個節點擁有者賬號.
|
|
|
15645 |
#$result["content"][$i]["ownByGroup"],第$i個節點擁有者群組.
|
|
|
15646 |
#$result["content"][$i]["bytes"],第$i個節點大小.
|
|
|
15647 |
#$result["content"][$i]["date"],第$i個節點最後變更日期.
|
|
|
15648 |
#$result["content"][$i]["time"],第$i個節點最後異動時間.
|
|
|
15649 |
#$result["content"][$i]["timeDetail"],第$i個節點最後異動詳細時間.
|
|
|
15650 |
#$result["content"][$i]["timezone"],第$i個節點的時區.
|
|
|
15651 |
#$result["content"][$i]["name"],第$i個節點的名稱.
|
|
|
15652 |
#$result["content"][$i]["secondName"],第$i個節點為檔案時,若有附檔名,會記錄在這.
|
|
|
15653 |
#$result["content"][$i]["mimeType"],第$i個節點為檔案且可以讀取時,會有 mime type 可取得.
|
|
|
15654 |
#必填參數:
|
|
|
15655 |
#$conf["path"],字串,要檢視的路徑,若非"/"結尾,會自動補上.
|
|
|
15656 |
$conf["path"]="";
|
|
|
15657 |
#可省略參數:
|
|
|
15658 |
#無.
|
|
|
15659 |
#參考資料:
|
|
|
15660 |
#https://www.businessweekly.com.tw/careers/Blog/14307
|
|
|
15661 |
#備註:
|
|
|
15662 |
#無.
|
|
|
15663 |
*/
|
|
|
15664 |
public static function ls(&$conf){
|
| 226 |
liveuser |
15665 |
|
| 3 |
liveuser |
15666 |
#初始化要回傳的結果
|
|
|
15667 |
$result=array();
|
|
|
15668 |
|
|
|
15669 |
#取得當前執行的函數名稱
|
|
|
15670 |
$result["function"]=__FUNCTION__;
|
|
|
15671 |
|
|
|
15672 |
#如果沒有參數
|
|
|
15673 |
if(func_num_args()==0){
|
|
|
15674 |
|
|
|
15675 |
#設置執行失敗
|
|
|
15676 |
$result["status"]="false";
|
|
|
15677 |
|
|
|
15678 |
#設置執行錯誤訊息
|
|
|
15679 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
15680 |
|
|
|
15681 |
#回傳結果
|
|
|
15682 |
return $result;
|
|
|
15683 |
|
|
|
15684 |
}#if end
|
|
|
15685 |
|
|
|
15686 |
#取得參數
|
|
|
15687 |
$result["argu"]=$conf;
|
|
|
15688 |
|
|
|
15689 |
#如果 $conf 不為陣列
|
|
|
15690 |
if(gettype($conf)!=="array"){
|
|
|
15691 |
|
|
|
15692 |
#設置執行失敗
|
|
|
15693 |
$result["status"]="false";
|
|
|
15694 |
|
|
|
15695 |
#設置執行錯誤訊息
|
|
|
15696 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
15697 |
|
|
|
15698 |
#如果傳入的參數為 null
|
|
|
15699 |
if(is_null($conf)){
|
|
|
15700 |
|
|
|
15701 |
#設置執行錯誤訊息
|
|
|
15702 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
15703 |
|
|
|
15704 |
}#if end
|
|
|
15705 |
|
|
|
15706 |
#回傳結果
|
|
|
15707 |
return $result;
|
|
|
15708 |
|
|
|
15709 |
}#if end
|
| 226 |
liveuser |
15710 |
|
| 3 |
liveuser |
15711 |
#函式說明:
|
|
|
15712 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
15713 |
#回傳結果:
|
|
|
15714 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
15715 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
15716 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
15717 |
#$result["function"],當前執行的函式名稱.
|
|
|
15718 |
#$result["argu"],設置給予的參數.
|
|
|
15719 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
15720 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
15721 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
15722 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
15723 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
15724 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
15725 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
15726 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
15727 |
#必填參數:
|
|
|
15728 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
15729 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
15730 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
15731 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
15732 |
#可省略參數:
|
|
|
15733 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
15734 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("path");
|
|
|
15735 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
15736 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
15737 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
15738 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
15739 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
15740 |
#$conf["canNotBeEmpty"]=array();
|
|
|
15741 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
15742 |
#$conf["canBeEmpty"]=array();
|
|
|
15743 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
15744 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
15745 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
15746 |
#$conf["skipableVariableName"]=array();
|
|
|
15747 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
15748 |
#$conf["skipableVariableType"]=array();
|
|
|
15749 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
15750 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
15751 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
15752 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
15753 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
15754 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
15755 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
15756 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
15757 |
#參考資料:
|
|
|
15758 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
15759 |
#備註:
|
|
|
15760 |
#無.
|
|
|
15761 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
15762 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
15763 |
|
| 3 |
liveuser |
15764 |
#如果執行失敗
|
|
|
15765 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
15766 |
|
| 3 |
liveuser |
15767 |
#設置執行錯誤
|
|
|
15768 |
$result["status"]="false";
|
| 226 |
liveuser |
15769 |
|
| 3 |
liveuser |
15770 |
#設置錯誤訊息
|
|
|
15771 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
15772 |
|
| 3 |
liveuser |
15773 |
#回傳結果
|
|
|
15774 |
return $result;
|
| 226 |
liveuser |
15775 |
|
| 3 |
liveuser |
15776 |
}#if end
|
| 226 |
liveuser |
15777 |
|
| 3 |
liveuser |
15778 |
#如果參數檢查不通過
|
|
|
15779 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
15780 |
|
| 3 |
liveuser |
15781 |
#設置執行錯誤
|
|
|
15782 |
$result["status"]="false";
|
| 226 |
liveuser |
15783 |
|
| 3 |
liveuser |
15784 |
#設置錯誤訊息
|
|
|
15785 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
15786 |
|
| 3 |
liveuser |
15787 |
#回傳結果
|
|
|
15788 |
return $result;
|
| 226 |
liveuser |
15789 |
|
| 3 |
liveuser |
15790 |
}#if end
|
| 226 |
liveuser |
15791 |
|
| 3 |
liveuser |
15792 |
#確認 $conf["path"] 是否為 "/" 結尾
|
|
|
15793 |
#函式說明:
|
|
|
15794 |
#取得符合特定字首與字尾的字串
|
|
|
15795 |
#回傳結果:
|
|
|
15796 |
#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
|
|
|
15797 |
#$result["function"],當前執行的函數名稱.
|
|
|
15798 |
#$result["error"],錯誤訊息陣列.
|
|
|
15799 |
#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
|
|
|
15800 |
#$result["content"],符合條件的字串,去掉字首字尾後的結果.
|
|
|
15801 |
#$result["returnString"],爲符合字首字、尾條件的字串內容。
|
|
|
15802 |
#$result["argu"],使用的參數.
|
|
|
15803 |
#必填參數:
|
|
|
15804 |
#$conf["checkString"],字串,要檢查的字串.
|
|
|
15805 |
$conf["search::getMeetConditionsString"]["checkString"]=$conf["path"];
|
|
|
15806 |
#可省略參數:
|
|
|
15807 |
#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
15808 |
#$conf["frontWord"]="";
|
|
|
15809 |
#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
15810 |
$conf["search::getMeetConditionsString"]["tailWord"]="/";
|
|
|
15811 |
#參考資料:
|
|
|
15812 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
15813 |
#備註:
|
|
|
15814 |
#無.
|
|
|
15815 |
$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
|
|
|
15816 |
unset($conf["search::getMeetConditionsString"]);
|
| 226 |
liveuser |
15817 |
|
| 3 |
liveuser |
15818 |
#如果執行失敗
|
|
|
15819 |
if($getMeetConditionsString["status"]==="false"){
|
| 226 |
liveuser |
15820 |
|
| 3 |
liveuser |
15821 |
#設置執行錯誤
|
|
|
15822 |
$result["status"]="false";
|
| 226 |
liveuser |
15823 |
|
| 3 |
liveuser |
15824 |
#設置錯誤訊息
|
|
|
15825 |
$result["error"]=$getMeetConditionsString;
|
| 226 |
liveuser |
15826 |
|
| 3 |
liveuser |
15827 |
#回傳結果
|
|
|
15828 |
return $result;
|
| 226 |
liveuser |
15829 |
|
| 3 |
liveuser |
15830 |
}#if end
|
| 226 |
liveuser |
15831 |
|
| 3 |
liveuser |
15832 |
#如果沒有 "/" 結尾
|
|
|
15833 |
if($getMeetConditionsString["founded"]==="false"){
|
| 226 |
liveuser |
15834 |
|
| 3 |
liveuser |
15835 |
#於結尾加上 "/"
|
|
|
15836 |
$conf["path"]=$conf["path"]."/";
|
| 226 |
liveuser |
15837 |
|
| 3 |
liveuser |
15838 |
}#if end
|
| 226 |
liveuser |
15839 |
|
| 3 |
liveuser |
15840 |
#記錄真正的路徑
|
|
|
15841 |
$result["path"]=$conf["path"];
|
| 226 |
liveuser |
15842 |
|
| 3 |
liveuser |
15843 |
#函式說明:
|
|
|
15844 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
15845 |
#回傳結果:
|
|
|
15846 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
15847 |
#$result["error"],錯誤訊息陣列.
|
|
|
15848 |
#$result["function"],當前執行的函數名稱.
|
|
|
15849 |
#$result["argu"],使用的參數.
|
|
|
15850 |
#$result["cmd"],執行的指令內容.
|
|
|
15851 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
15852 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
15853 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
15854 |
#$result["running"],是否還在執行.
|
|
|
15855 |
#$result["pid"],pid.
|
|
|
15856 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
15857 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
|
|
|
15858 |
#必填參數:
|
|
|
15859 |
#$conf["command"],字串,要執行的指令.
|
|
|
15860 |
$conf["external::callShell"]["command"]="ls";
|
|
|
15861 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
15862 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
15863 |
#可省略參數:
|
|
|
15864 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
15865 |
$conf["external::callShell"]["argu"]=array("-al","--full-time","-t","-B",$conf["path"]);
|
|
|
15866 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
15867 |
#$conf["arguIsAddr"]=array();
|
|
|
15868 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
15869 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
15870 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
15871 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
15872 |
#$conf["enablePrintDescription"]="true";
|
|
|
15873 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
15874 |
#$conf["printDescription"]="";
|
|
|
15875 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
15876 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
15877 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
15878 |
#$conf["thereIsShellVar"]=array();
|
|
|
15879 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
15880 |
#$conf["username"]="";
|
|
|
15881 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
15882 |
#$conf["password"]="";
|
|
|
15883 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
15884 |
#$conf["useScript"]="";
|
|
|
15885 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
15886 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
15887 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
15888 |
#$conf["inBackGround"]="";
|
|
|
15889 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
15890 |
#$conf["getErr"]="false";
|
|
|
15891 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
15892 |
#$conf["doNotRun"]="false";
|
|
|
15893 |
#參考資料:
|
|
|
15894 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
15895 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
15896 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
15897 |
#備註:
|
|
|
15898 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
15899 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
15900 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
15901 |
unset($conf["external::callShell"]);
|
| 226 |
liveuser |
15902 |
|
| 3 |
liveuser |
15903 |
#debug
|
|
|
15904 |
#var_dump(__FILE__,__LINE__,$callShell);
|
| 226 |
liveuser |
15905 |
|
| 3 |
liveuser |
15906 |
#如果執行失敗
|
|
|
15907 |
if($callShell["status"]==="false"){
|
| 226 |
liveuser |
15908 |
|
| 3 |
liveuser |
15909 |
#設置執行錯誤
|
|
|
15910 |
$result["status"]="false";
|
| 226 |
liveuser |
15911 |
|
| 3 |
liveuser |
15912 |
#設置錯誤訊息
|
|
|
15913 |
$result["error"]=$callShell;
|
| 226 |
liveuser |
15914 |
|
| 3 |
liveuser |
15915 |
#回傳結果
|
|
|
15916 |
return $result;
|
| 226 |
liveuser |
15917 |
|
| 3 |
liveuser |
15918 |
}#if end
|
| 226 |
liveuser |
15919 |
|
| 3 |
liveuser |
15920 |
#初始化儲存檔案資訊為空
|
|
|
15921 |
$result["content"]=array();
|
| 226 |
liveuser |
15922 |
|
| 3 |
liveuser |
15923 |
#針對每行輸出
|
|
|
15924 |
foreach($callShell["output"] as $index=>$line){
|
| 226 |
liveuser |
15925 |
|
| 3 |
liveuser |
15926 |
#如果是第一筆
|
|
|
15927 |
if($index===0){
|
| 226 |
liveuser |
15928 |
|
| 3 |
liveuser |
15929 |
#取得資料筆數
|
|
|
15930 |
$result["dataCount"]=explode(" ",$line)[0];
|
| 226 |
liveuser |
15931 |
|
| 3 |
liveuser |
15932 |
#換下一輪
|
|
|
15933 |
continue;
|
| 226 |
liveuser |
15934 |
|
| 3 |
liveuser |
15935 |
}#if end
|
| 226 |
liveuser |
15936 |
|
| 3 |
liveuser |
15937 |
#函式說明:
|
|
|
15938 |
#將固定格式的字串分開,並回傳分開的結果.
|
|
|
15939 |
#回傳結果:
|
|
|
15940 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
15941 |
#$result["error"],錯誤訊息陣列
|
|
|
15942 |
#$result["function"],當前執行的函數名稱.
|
|
|
15943 |
#$result["argu"],使用的參數.
|
|
|
15944 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
15945 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
15946 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
15947 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
15948 |
#必填參數:
|
|
|
15949 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
15950 |
$conf["stringProcess::spiltString"]["stringIn"]=$line;
|
|
|
15951 |
#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
|
|
|
15952 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";
|
|
|
15953 |
#可省略參數:
|
|
|
15954 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
15955 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
15956 |
#參考資料:
|
|
|
15957 |
#無.
|
|
|
15958 |
#備註:
|
|
|
15959 |
#無.
|
|
|
15960 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
15961 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
15962 |
|
| 3 |
liveuser |
15963 |
#如果執行失敗
|
|
|
15964 |
if($spiltString["status"]==="false"){
|
| 226 |
liveuser |
15965 |
|
| 3 |
liveuser |
15966 |
#設置執行錯誤
|
|
|
15967 |
$result["status"]="false";
|
| 226 |
liveuser |
15968 |
|
| 3 |
liveuser |
15969 |
#設置錯誤訊息
|
|
|
15970 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
15971 |
|
| 3 |
liveuser |
15972 |
#回傳結果
|
|
|
15973 |
return $result;
|
| 226 |
liveuser |
15974 |
|
| 3 |
liveuser |
15975 |
}#if end
|
| 226 |
liveuser |
15976 |
|
| 3 |
liveuser |
15977 |
#如果沒有分割用的" "
|
|
|
15978 |
if($spiltString["found"]==="false"){
|
| 226 |
liveuser |
15979 |
|
| 3 |
liveuser |
15980 |
#設置執行錯誤
|
|
|
15981 |
$result["status"]="false";
|
| 226 |
liveuser |
15982 |
|
| 3 |
liveuser |
15983 |
#設置錯誤訊息
|
|
|
15984 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
15985 |
|
| 3 |
liveuser |
15986 |
#回傳結果
|
|
|
15987 |
return $result;
|
| 226 |
liveuser |
15988 |
|
| 3 |
liveuser |
15989 |
}#if end
|
| 226 |
liveuser |
15990 |
|
| 3 |
liveuser |
15991 |
#如果分割好的數量小於8
|
|
|
15992 |
if($spiltString["dataCounts"]<8){
|
| 226 |
liveuser |
15993 |
|
| 3 |
liveuser |
15994 |
#設置執行錯誤
|
|
|
15995 |
$result["status"]="false";
|
| 226 |
liveuser |
15996 |
|
| 3 |
liveuser |
15997 |
#設置錯誤訊息
|
|
|
15998 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
15999 |
|
| 3 |
liveuser |
16000 |
#回傳結果
|
|
|
16001 |
return $result;
|
| 226 |
liveuser |
16002 |
|
| 3 |
liveuser |
16003 |
}#if end
|
| 226 |
liveuser |
16004 |
|
| 3 |
liveuser |
16005 |
#初始化要儲存的檔案資訊陣列
|
|
|
16006 |
$fileInfo=array();
|
| 226 |
liveuser |
16007 |
|
| 3 |
liveuser |
16008 |
#取得 節點類型、權限
|
|
|
16009 |
$fileInfo["nType&permission"]=$spiltString["dataArray"][0];
|
| 226 |
liveuser |
16010 |
|
| 3 |
liveuser |
16011 |
#剔除結尾的 "."
|
|
|
16012 |
$fileInfo["nType&permission"]=substr($fileInfo["nType&permission"],0,strlen($fileInfo["nType&permission"])-1);
|
| 226 |
liveuser |
16013 |
|
| 3 |
liveuser |
16014 |
#取得節點類型
|
|
|
16015 |
$fileInfo["nType"]=$fileInfo["nType&permission"][0];
|
| 226 |
liveuser |
16016 |
|
| 3 |
liveuser |
16017 |
#取得節點權限
|
|
|
16018 |
$fileInfo["permission"]=substr($fileInfo["nType&permission"],1);
|
| 226 |
liveuser |
16019 |
|
| 3 |
liveuser |
16020 |
#取得擁有者賬號
|
|
|
16021 |
$fileInfo["ownByUser"]=$spiltString["dataArray"][2];
|
| 226 |
liveuser |
16022 |
|
| 3 |
liveuser |
16023 |
#取得群組擁有者群組
|
|
|
16024 |
$fileInfo["ownByGroup"]=$spiltString["dataArray"][3];
|
| 226 |
liveuser |
16025 |
|
| 3 |
liveuser |
16026 |
#取得size
|
|
|
16027 |
$fileInfo["bytes"]=$spiltString["dataArray"][4];
|
| 226 |
liveuser |
16028 |
|
|
|
16029 |
#取得最後異動日期
|
| 3 |
liveuser |
16030 |
$fileInfo["date"]=$spiltString["dataArray"][5];
|
| 226 |
liveuser |
16031 |
|
| 3 |
liveuser |
16032 |
#取得最後異動時間
|
|
|
16033 |
$fileInfo["time"]=explode(".",$spiltString["dataArray"][6])[0];
|
| 226 |
liveuser |
16034 |
|
| 3 |
liveuser |
16035 |
#取得最後異動的詳細時間
|
|
|
16036 |
$fileInfo["timeDetail"]=$spiltString["dataArray"][6];
|
| 226 |
liveuser |
16037 |
|
| 3 |
liveuser |
16038 |
#取得timezone資訊
|
|
|
16039 |
$fileInfo["timezone"]=$spiltString["dataArray"][7];
|
| 226 |
liveuser |
16040 |
|
| 3 |
liveuser |
16041 |
#函式說明:
|
|
|
16042 |
#將固定格式的字串分開,並回傳分開的結果.
|
|
|
16043 |
#回傳結果:
|
|
|
16044 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
16045 |
#$result["error"],錯誤訊息陣列
|
|
|
16046 |
#$result["function"],當前執行的函數名稱.
|
|
|
16047 |
#$result["argu"],使用的參數.
|
|
|
16048 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
16049 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
16050 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
16051 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
16052 |
#必填參數:
|
|
|
16053 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
16054 |
$conf["stringProcess::spiltString"]["stringIn"]=$line;
|
|
|
16055 |
#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
|
|
|
16056 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=$fileInfo["date"]." ".$fileInfo["timeDetail"]." ".$fileInfo["timezone"];
|
|
|
16057 |
#可省略參數:
|
|
|
16058 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
16059 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
16060 |
#參考資料:
|
|
|
16061 |
#無.
|
|
|
16062 |
#備註:
|
|
|
16063 |
#無.
|
|
|
16064 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
16065 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
16066 |
|
| 3 |
liveuser |
16067 |
#如果執行失敗
|
|
|
16068 |
if($spiltString["status"]==="false"){
|
| 226 |
liveuser |
16069 |
|
| 3 |
liveuser |
16070 |
#設置執行錯誤
|
|
|
16071 |
$result["status"]="false";
|
| 226 |
liveuser |
16072 |
|
| 3 |
liveuser |
16073 |
#設置錯誤訊息
|
|
|
16074 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
16075 |
|
| 3 |
liveuser |
16076 |
#回傳結果
|
|
|
16077 |
return $result;
|
| 226 |
liveuser |
16078 |
|
| 3 |
liveuser |
16079 |
}#if end
|
| 226 |
liveuser |
16080 |
|
| 3 |
liveuser |
16081 |
#如果沒有分割用的" "
|
|
|
16082 |
if($spiltString["found"]==="false"){
|
| 226 |
liveuser |
16083 |
|
| 3 |
liveuser |
16084 |
#設置執行錯誤
|
|
|
16085 |
$result["status"]="false";
|
| 226 |
liveuser |
16086 |
|
| 3 |
liveuser |
16087 |
#設置錯誤訊息
|
|
|
16088 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
16089 |
|
| 3 |
liveuser |
16090 |
#回傳結果
|
|
|
16091 |
return $result;
|
| 226 |
liveuser |
16092 |
|
| 3 |
liveuser |
16093 |
}#if end
|
| 226 |
liveuser |
16094 |
|
| 3 |
liveuser |
16095 |
#如果分割好的數量小於8
|
|
|
16096 |
if($spiltString["dataCounts"]<2){
|
| 226 |
liveuser |
16097 |
|
| 3 |
liveuser |
16098 |
#設置執行錯誤
|
|
|
16099 |
$result["status"]="false";
|
| 226 |
liveuser |
16100 |
|
| 3 |
liveuser |
16101 |
#設置錯誤訊息
|
|
|
16102 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
16103 |
|
| 3 |
liveuser |
16104 |
#回傳結果
|
|
|
16105 |
return $result;
|
| 226 |
liveuser |
16106 |
|
| 3 |
liveuser |
16107 |
}#if end
|
| 226 |
liveuser |
16108 |
|
| 3 |
liveuser |
16109 |
#取得節點名稱,剔除開頭的空白.
|
|
|
16110 |
$fileInfo["name"]=substr($spiltString["dataArray"][1],1);
|
| 226 |
liveuser |
16111 |
|
| 3 |
liveuser |
16112 |
#排除 "." 跟 ".."
|
|
|
16113 |
if($fileInfo["name"]==="." || $fileInfo["name"]===".."){
|
| 226 |
liveuser |
16114 |
|
| 3 |
liveuser |
16115 |
#跳過
|
|
|
16116 |
continue;
|
| 226 |
liveuser |
16117 |
|
| 3 |
liveuser |
16118 |
}#if end
|
| 226 |
liveuser |
16119 |
|
| 3 |
liveuser |
16120 |
#如果是檔案
|
|
|
16121 |
if($fileInfo["nType"]==="-"){
|
| 226 |
liveuser |
16122 |
|
| 3 |
liveuser |
16123 |
#取得mime type
|
|
|
16124 |
$fileInfo["mimeType"]=@mime_content_type($conf["path"].$fileInfo["name"]);
|
| 226 |
liveuser |
16125 |
|
| 3 |
liveuser |
16126 |
#如果讀取失敗
|
|
|
16127 |
if($fileInfo["mimeType"]===false){
|
| 226 |
liveuser |
16128 |
|
| 3 |
liveuser |
16129 |
#通常為沒有權限
|
| 226 |
liveuser |
16130 |
|
| 3 |
liveuser |
16131 |
#跳過該檔案
|
|
|
16132 |
continue;
|
| 226 |
liveuser |
16133 |
|
| 3 |
liveuser |
16134 |
}#if end
|
| 226 |
liveuser |
16135 |
|
| 3 |
liveuser |
16136 |
#確認檔案名稱中間含是否有 "."
|
|
|
16137 |
#函式說明:
|
|
|
16138 |
#取得關鍵字在字串的哪個位置(字首,字尾,中間)
|
|
|
16139 |
#回傳結果:
|
|
|
16140 |
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
|
|
|
16141 |
#$result["error"],錯誤訊息陣列.
|
|
|
16142 |
#$result["function"],當前執行的函數名稱.
|
|
|
16143 |
#$result["found"],是否有關鍵字存在,若為"true",代表存在;反之為"false".
|
|
|
16144 |
#$result["argu"],傳入的參數.
|
|
|
16145 |
#$result["head"],關鍵字是否在字串的開頭,"true"代表是,"false"代表不是.
|
|
|
16146 |
#$result["tail"],關鍵字是否在字串的尾端,"true"代表是,"false"代表不是.
|
|
|
16147 |
#$result["center"],關鍵字是否在字串的中間,"true"代表是,"false"代表不是.
|
|
|
16148 |
#$result["indexS"],關鍵字在被搜尋字串的哪個位置開始.
|
|
|
16149 |
#$result["indexE"],關鍵字在被搜尋字串的哪個位置結束.
|
|
|
16150 |
#必填參數:
|
|
|
16151 |
#$conf["inputStr"],字串,被搜尋的字串.
|
|
|
16152 |
$conf["search::findKeyWordPosition"]["inputStr"]=$fileInfo["name"];
|
|
|
16153 |
#$conf["keyWord"],字串,關鍵字.
|
|
|
16154 |
$conf["search::findKeyWordPosition"]["keyWord"]=".";
|
|
|
16155 |
#可省略參數:
|
|
|
16156 |
#無.
|
|
|
16157 |
#參考資料:
|
|
|
16158 |
#http://php.net/manual/en/function.strpos.php
|
|
|
16159 |
#備註:
|
|
|
16160 |
#無.
|
|
|
16161 |
$findKeyWordPosition=search::findKeyWordPosition($conf["search::findKeyWordPosition"]);
|
|
|
16162 |
unset($conf["search::findKeyWordPosition"]);
|
| 226 |
liveuser |
16163 |
|
| 3 |
liveuser |
16164 |
#如果執行失敗
|
|
|
16165 |
if($findKeyWordPosition["status"]==="false"){
|
| 226 |
liveuser |
16166 |
|
| 3 |
liveuser |
16167 |
#設置執行錯誤
|
|
|
16168 |
$result["status"]="false";
|
| 226 |
liveuser |
16169 |
|
| 3 |
liveuser |
16170 |
#設置錯誤訊息
|
|
|
16171 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
16172 |
|
| 3 |
liveuser |
16173 |
#回傳結果
|
|
|
16174 |
return $result;
|
| 226 |
liveuser |
16175 |
|
| 3 |
liveuser |
16176 |
}#if end
|
| 226 |
liveuser |
16177 |
|
| 3 |
liveuser |
16178 |
#如果含有 "." 存在
|
|
|
16179 |
if($findKeyWordPosition["found"]==="true"){
|
| 226 |
liveuser |
16180 |
|
| 3 |
liveuser |
16181 |
#如果 "." 是在中間,不是在尾巴.
|
|
|
16182 |
if($findKeyWordPosition["center"]==="true" && $findKeyWordPosition["tail"]==="false"){
|
| 226 |
liveuser |
16183 |
|
| 3 |
liveuser |
16184 |
#取得 "." 之後的內容
|
|
|
16185 |
#函式說明:
|
|
|
16186 |
#將字串特定關鍵字與其前面的內容剔除
|
|
|
16187 |
#回傳結果:
|
|
|
16188 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
16189 |
#$result["error"],錯誤訊息陣列.
|
|
|
16190 |
#$result["warning"],警告訊息鎮列.
|
|
|
16191 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
16192 |
#$result["function"],當前執行的函數名稱.
|
|
|
16193 |
#$result["argu"],使用的參數.
|
|
|
16194 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
16195 |
#$result["content"],處理好的的字串內容.
|
|
|
16196 |
#$result["deleted"],被移除的內容.
|
|
|
16197 |
#必填參數:
|
|
|
16198 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
16199 |
$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$fileInfo["name"];
|
|
|
16200 |
#$conf["keyWord"],字串,特定字串.
|
|
|
16201 |
$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=".";
|
|
|
16202 |
#可省略參數:
|
|
|
16203 |
#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
|
|
|
16204 |
$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
|
|
|
16205 |
#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
|
|
|
16206 |
#$conf["lastResult"]=$delStrBeforeKeyWord;
|
|
|
16207 |
#參考資料:
|
|
|
16208 |
#無.
|
|
|
16209 |
#備註:
|
|
|
16210 |
#無.
|
|
|
16211 |
$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
16212 |
unset($conf["stringProcess::delStrBeforeKeyWord"]);
|
| 226 |
liveuser |
16213 |
|
| 3 |
liveuser |
16214 |
#如果執行失敗
|
|
|
16215 |
if($delStrBeforeKeyWord["status"]==="false"){
|
| 226 |
liveuser |
16216 |
|
| 3 |
liveuser |
16217 |
#設置執行錯誤
|
|
|
16218 |
$result["status"]="false";
|
| 226 |
liveuser |
16219 |
|
| 3 |
liveuser |
16220 |
#設置錯誤訊息
|
|
|
16221 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
16222 |
|
| 3 |
liveuser |
16223 |
#回傳結果
|
|
|
16224 |
return $result;
|
| 226 |
liveuser |
16225 |
|
| 3 |
liveuser |
16226 |
}#if end
|
| 226 |
liveuser |
16227 |
|
| 3 |
liveuser |
16228 |
#如果該存在的 "." 不存在
|
|
|
16229 |
if($delStrBeforeKeyWord["founded"]==="false"){
|
| 226 |
liveuser |
16230 |
|
| 3 |
liveuser |
16231 |
#設置執行錯誤
|
|
|
16232 |
$result["status"]="false";
|
| 226 |
liveuser |
16233 |
|
| 3 |
liveuser |
16234 |
#設置錯誤訊息
|
|
|
16235 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
16236 |
|
| 3 |
liveuser |
16237 |
#回傳結果
|
|
|
16238 |
return $result;
|
| 226 |
liveuser |
16239 |
|
| 3 |
liveuser |
16240 |
}#if end
|
| 226 |
liveuser |
16241 |
|
| 3 |
liveuser |
16242 |
#取得附檔名
|
|
|
16243 |
$fileInfo["secondName"]=$delStrBeforeKeyWord["content"];
|
| 226 |
liveuser |
16244 |
|
| 3 |
liveuser |
16245 |
}#if end
|
| 226 |
liveuser |
16246 |
|
| 3 |
liveuser |
16247 |
}#if end
|
| 226 |
liveuser |
16248 |
|
| 3 |
liveuser |
16249 |
}#if end
|
| 226 |
liveuser |
16250 |
|
| 3 |
liveuser |
16251 |
#儲存檔案資訊
|
|
|
16252 |
$result["content"][]=$fileInfo;
|
| 226 |
liveuser |
16253 |
|
| 3 |
liveuser |
16254 |
}#foreach end
|
| 226 |
liveuser |
16255 |
|
| 3 |
liveuser |
16256 |
#設置清單的長度
|
|
|
16257 |
$result["dataCount"]=count($result["content"]);
|
| 226 |
liveuser |
16258 |
|
| 3 |
liveuser |
16259 |
#設置執行正常
|
|
|
16260 |
$result["status"]="true";
|
| 226 |
liveuser |
16261 |
|
| 3 |
liveuser |
16262 |
#回傳結果
|
|
|
16263 |
return $result;
|
| 226 |
liveuser |
16264 |
|
| 3 |
liveuser |
16265 |
}#function ls end
|
|
|
16266 |
|
|
|
16267 |
/*
|
|
|
16268 |
#函式說明:
|
|
|
16269 |
#將 ~ 轉換為家目錄路徑
|
|
|
16270 |
#回傳結果:
|
|
|
16271 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
16272 |
#$result["error"],錯誤訊息.
|
|
|
16273 |
#$result["function"],當前執行的函數名稱.
|
|
|
16274 |
#$result["content"],轉換好的內容.
|
|
|
16275 |
#必填參數:
|
|
|
16276 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
16277 |
$conf["fileArgu"]=__FILE__;
|
|
|
16278 |
#可省略參數:
|
|
|
16279 |
#無.
|
|
|
16280 |
#參考資料:
|
|
|
16281 |
#https://www.businessweekly.com.tw/careers/Blog/14307
|
|
|
16282 |
#備註:
|
|
|
16283 |
#無.
|
|
|
16284 |
*/
|
|
|
16285 |
public static function tildeToPath(&$conf){
|
| 226 |
liveuser |
16286 |
|
| 3 |
liveuser |
16287 |
#初始化要回傳的結果
|
|
|
16288 |
$result=array();
|
|
|
16289 |
|
|
|
16290 |
#取得當前執行的函數名稱
|
|
|
16291 |
$result["function"]=__FUNCTION__;
|
|
|
16292 |
|
|
|
16293 |
#如果沒有參數
|
|
|
16294 |
if(func_num_args()==0){
|
| 226 |
liveuser |
16295 |
|
| 3 |
liveuser |
16296 |
#設置執行失敗
|
|
|
16297 |
$result["status"]="false";
|
| 226 |
liveuser |
16298 |
|
| 3 |
liveuser |
16299 |
#設置執行錯誤訊息
|
|
|
16300 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
16301 |
|
| 3 |
liveuser |
16302 |
#回傳結果
|
|
|
16303 |
return $result;
|
| 226 |
liveuser |
16304 |
|
| 220 |
liveuser |
16305 |
}#if end
|
| 3 |
liveuser |
16306 |
|
|
|
16307 |
#取得參數
|
|
|
16308 |
$result["argu"]=$conf;
|
|
|
16309 |
|
|
|
16310 |
#如果 $conf 不為陣列
|
|
|
16311 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
16312 |
|
| 3 |
liveuser |
16313 |
#設置執行失敗
|
|
|
16314 |
$result["status"]="false";
|
| 226 |
liveuser |
16315 |
|
| 3 |
liveuser |
16316 |
#設置執行錯誤訊息
|
|
|
16317 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
16318 |
|
| 3 |
liveuser |
16319 |
#如果傳入的參數為 null
|
|
|
16320 |
if($conf===null){
|
| 226 |
liveuser |
16321 |
|
| 3 |
liveuser |
16322 |
#設置執行錯誤訊息
|
|
|
16323 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
16324 |
|
| 3 |
liveuser |
16325 |
}#if end
|
|
|
16326 |
|
|
|
16327 |
#回傳結果
|
|
|
16328 |
return $result;
|
| 226 |
liveuser |
16329 |
|
| 3 |
liveuser |
16330 |
}#if end
|
| 226 |
liveuser |
16331 |
|
| 3 |
liveuser |
16332 |
#函式說明:
|
|
|
16333 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
16334 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
16335 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
16336 |
#$result["function"],當前執行的函式名稱.
|
|
|
16337 |
#$result["argu"],設置給予的參數.
|
|
|
16338 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
16339 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
16340 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
16341 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
16342 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
16343 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
16344 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
16345 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
16346 |
#必填寫的參數:
|
|
|
16347 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
| 226 |
liveuser |
16348 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
| 3 |
liveuser |
16349 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
16350 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
16351 |
#可以省略的參數:
|
|
|
16352 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
16353 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
|
|
|
16354 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
16355 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
16356 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
16357 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
16358 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
16359 |
#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
|
|
|
16360 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
16361 |
#$conf["canBeEmpty"]=array();
|
|
|
16362 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
16363 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("web");
|
|
|
16364 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
16365 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("web");
|
| 226 |
liveuser |
16366 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
16367 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
16368 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
16369 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
|
|
16370 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
16371 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
16372 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
16373 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
16374 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
16375 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
16376 |
#參考資料來源:
|
|
|
16377 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
16378 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
16379 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
16380 |
|
| 3 |
liveuser |
16381 |
#如果檢查參數失敗
|
|
|
16382 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
16383 |
|
| 3 |
liveuser |
16384 |
#設置執行失敗
|
|
|
16385 |
$result["status"]="false";
|
| 226 |
liveuser |
16386 |
|
| 3 |
liveuser |
16387 |
#設置執行失敗訊息
|
|
|
16388 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
16389 |
|
| 3 |
liveuser |
16390 |
#回傳結果
|
|
|
16391 |
return $result;
|
| 226 |
liveuser |
16392 |
|
| 3 |
liveuser |
16393 |
}#if end
|
| 226 |
liveuser |
16394 |
|
| 3 |
liveuser |
16395 |
#如果檢查參數不通過
|
|
|
16396 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
16397 |
|
| 3 |
liveuser |
16398 |
#設置執行失敗
|
|
|
16399 |
$result["status"]="false";
|
| 226 |
liveuser |
16400 |
|
| 3 |
liveuser |
16401 |
#設置執行失敗訊息
|
|
|
16402 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
16403 |
|
| 3 |
liveuser |
16404 |
#回傳結果
|
|
|
16405 |
return $result;
|
| 226 |
liveuser |
16406 |
|
| 3 |
liveuser |
16407 |
}#if end
|
|
|
16408 |
|
|
|
16409 |
#函式說明:
|
|
|
16410 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
16411 |
#回傳結果:
|
|
|
16412 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
16413 |
#$result["error"],錯誤訊息陣列.
|
|
|
16414 |
#$result["function"],當前執行的函數名稱.
|
|
|
16415 |
#$result["argu"],使用的參數.
|
|
|
16416 |
#$result["cmd"],執行的指令內容.
|
|
|
16417 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
16418 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
16419 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
16420 |
#$result["running"],是否還在執行.
|
|
|
16421 |
#$result["pid"],pid.
|
|
|
16422 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
16423 |
#必填參數:
|
|
|
16424 |
#$conf["command"],字串,要執行的指令與.
|
|
|
16425 |
$conf["external::callShell"]["command"]="echo";
|
|
|
16426 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
16427 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
|
|
16428 |
#可省略參數:
|
|
|
16429 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
16430 |
$conf["external::callShell"]["argu"]=array("~");
|
|
|
16431 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
16432 |
#$conf["arguIsAddr"]=array();
|
|
|
16433 |
#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
|
|
|
16434 |
#$conf["plainArgu"]=array();
|
|
|
16435 |
#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
|
|
|
16436 |
#$conf["useApostrophe"]=array();
|
|
|
16437 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
16438 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
16439 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
16440 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
16441 |
#$conf["enablePrintDescription"]="true";
|
|
|
16442 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
16443 |
#$conf["printDescription"]="";
|
|
|
16444 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
16445 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
16446 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
16447 |
#$conf["thereIsShellVar"]=array();
|
|
|
16448 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
16449 |
#$conf["username"]="";
|
|
|
16450 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
16451 |
#$conf["password"]="";
|
|
|
16452 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
16453 |
#$conf["useScript"]="";
|
|
|
16454 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
16455 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
16456 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
16457 |
#$conf["inBackGround"]="";
|
|
|
16458 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
16459 |
#$conf["getErr"]="false";
|
|
|
16460 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
16461 |
#$conf["doNotRun"]="false";
|
|
|
16462 |
#參考資料:
|
|
|
16463 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
16464 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
16465 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
16466 |
#備註:
|
|
|
16467 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
16468 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
16469 |
unset($conf["external::callShell"]);
|
|
|
16470 |
|
|
|
16471 |
#如果執行失敗
|
|
|
16472 |
if($callShell["status"]==="false"){
|
| 226 |
liveuser |
16473 |
|
| 3 |
liveuser |
16474 |
#設置執行失敗
|
|
|
16475 |
$result["status"]="false";
|
| 226 |
liveuser |
16476 |
|
| 3 |
liveuser |
16477 |
#設置執行失敗訊息
|
|
|
16478 |
$result["error"]=$callShell;
|
| 226 |
liveuser |
16479 |
|
| 3 |
liveuser |
16480 |
#回傳結果
|
|
|
16481 |
return $result;
|
| 226 |
liveuser |
16482 |
|
| 3 |
liveuser |
16483 |
}#if end
|
| 226 |
liveuser |
16484 |
|
| 3 |
liveuser |
16485 |
#如果沒有預期的輸出
|
|
|
16486 |
if(!isset($callShell["output"][0])){
|
| 226 |
liveuser |
16487 |
|
| 3 |
liveuser |
16488 |
#設置執行失敗
|
|
|
16489 |
$result["status"]="false";
|
| 226 |
liveuser |
16490 |
|
| 3 |
liveuser |
16491 |
#設置執行失敗訊息
|
|
|
16492 |
$result["error"][]="沒有得到預期的輸出";
|
| 226 |
liveuser |
16493 |
|
| 3 |
liveuser |
16494 |
#設置執行失敗訊息
|
|
|
16495 |
$result["error"][]=$callShell;
|
| 226 |
liveuser |
16496 |
|
| 3 |
liveuser |
16497 |
#回傳結果
|
|
|
16498 |
return $result;
|
| 226 |
liveuser |
16499 |
|
| 3 |
liveuser |
16500 |
}#if end
|
| 226 |
liveuser |
16501 |
|
| 3 |
liveuser |
16502 |
#取得輸出
|
|
|
16503 |
$result["content"]=$callShell["output"][0];
|
| 226 |
liveuser |
16504 |
|
| 3 |
liveuser |
16505 |
#設置執行正常
|
|
|
16506 |
$result["status"]="true";
|
| 226 |
liveuser |
16507 |
|
| 3 |
liveuser |
16508 |
#回傳結果
|
|
|
16509 |
return $result;
|
| 226 |
liveuser |
16510 |
|
| 3 |
liveuser |
16511 |
}#function tildeToPath end
|
|
|
16512 |
|
|
|
16513 |
/*
|
|
|
16514 |
#函式說明:
|
|
|
16515 |
#建立軟連結.
|
|
|
16516 |
#回傳結果:
|
|
|
16517 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
16518 |
#$result["error"],錯誤訊息.
|
|
|
16519 |
#$result["function"],當前執行的函數名稱.
|
|
|
16520 |
#$result["content"],軟連結的資訊.
|
|
|
16521 |
#$result["cmd"],執行的指令陣列.
|
|
|
16522 |
#必填參數:
|
|
|
16523 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
16524 |
$conf["fileArgu"]=__FILE__;
|
|
|
16525 |
#$conf["linkTo"],字串,軟連結要指向哪邊.
|
|
|
16526 |
$conf["linkTo"]="";
|
|
|
16527 |
#可省略參數:
|
|
|
16528 |
#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
|
|
|
16529 |
#$conf["path"]="";
|
|
|
16530 |
#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
|
|
|
16531 |
#$conf["name"]="";
|
|
|
16532 |
#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
|
|
|
16533 |
#$conf["overWrite"]="true";
|
|
|
16534 |
#參考資料:
|
|
|
16535 |
#無.
|
|
|
16536 |
#備註:
|
|
|
16537 |
#無.
|
|
|
16538 |
*/
|
|
|
16539 |
public static function createLink(&$conf){
|
| 226 |
liveuser |
16540 |
|
| 3 |
liveuser |
16541 |
#初始化要回傳的結果
|
|
|
16542 |
$result=array();
|
|
|
16543 |
|
|
|
16544 |
#取得當前執行的函數名稱
|
|
|
16545 |
$result["function"]=__FUNCTION__;
|
|
|
16546 |
|
|
|
16547 |
#如果沒有參數
|
|
|
16548 |
if(func_num_args()==0){
|
| 226 |
liveuser |
16549 |
|
| 3 |
liveuser |
16550 |
#設置執行失敗
|
|
|
16551 |
$result["status"]="false";
|
| 226 |
liveuser |
16552 |
|
| 3 |
liveuser |
16553 |
#設置執行錯誤訊息
|
|
|
16554 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
16555 |
|
| 3 |
liveuser |
16556 |
#回傳結果
|
|
|
16557 |
return $result;
|
| 226 |
liveuser |
16558 |
|
| 220 |
liveuser |
16559 |
}#if end
|
| 3 |
liveuser |
16560 |
|
|
|
16561 |
#取得參數
|
|
|
16562 |
$result["argu"]=$conf;
|
|
|
16563 |
|
|
|
16564 |
#如果 $conf 不為陣列
|
|
|
16565 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
16566 |
|
| 3 |
liveuser |
16567 |
#設置執行失敗
|
|
|
16568 |
$result["status"]="false";
|
| 226 |
liveuser |
16569 |
|
| 3 |
liveuser |
16570 |
#設置執行錯誤訊息
|
|
|
16571 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
16572 |
|
| 3 |
liveuser |
16573 |
#如果傳入的參數為 null
|
|
|
16574 |
if($conf===null){
|
| 226 |
liveuser |
16575 |
|
| 3 |
liveuser |
16576 |
#設置執行錯誤訊息
|
|
|
16577 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
16578 |
|
| 3 |
liveuser |
16579 |
}#if end
|
|
|
16580 |
|
|
|
16581 |
#回傳結果
|
|
|
16582 |
return $result;
|
| 226 |
liveuser |
16583 |
|
| 3 |
liveuser |
16584 |
}#if end
|
| 226 |
liveuser |
16585 |
|
| 3 |
liveuser |
16586 |
#函式說明:
|
|
|
16587 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
16588 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
16589 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
16590 |
#$result["function"],當前執行的函式名稱.
|
|
|
16591 |
#$result["argu"],設置給予的參數.
|
|
|
16592 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
16593 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
16594 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
16595 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
16596 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
16597 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
16598 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
16599 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
16600 |
#必填寫的參數:
|
|
|
16601 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
| 226 |
liveuser |
16602 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
| 3 |
liveuser |
16603 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
16604 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
16605 |
#可以省略的參數:
|
|
|
16606 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
16607 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","linkTo");
|
|
|
16608 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
16609 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
16610 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
16611 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
16612 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
16613 |
#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
|
|
|
16614 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
16615 |
#$conf["canBeEmpty"]=array();
|
|
|
16616 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
16617 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("path","name","overWrite");
|
|
|
16618 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
16619 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("path","name","overWrite");
|
| 226 |
liveuser |
16620 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
16621 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
16622 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
16623 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"false");
|
|
|
16624 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
16625 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
16626 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
16627 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
16628 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
16629 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
16630 |
#參考資料來源:
|
|
|
16631 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
16632 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
16633 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
16634 |
|
| 3 |
liveuser |
16635 |
#如果檢查參數失敗
|
|
|
16636 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
16637 |
|
| 3 |
liveuser |
16638 |
#設置執行失敗
|
|
|
16639 |
$result["status"]="false";
|
| 226 |
liveuser |
16640 |
|
| 3 |
liveuser |
16641 |
#設置執行失敗訊息
|
|
|
16642 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
16643 |
|
| 3 |
liveuser |
16644 |
#回傳結果
|
|
|
16645 |
return $result;
|
| 226 |
liveuser |
16646 |
|
| 3 |
liveuser |
16647 |
}#if end
|
| 226 |
liveuser |
16648 |
|
| 3 |
liveuser |
16649 |
#如果檢查參數不通過
|
|
|
16650 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
16651 |
|
| 3 |
liveuser |
16652 |
#設置執行失敗
|
|
|
16653 |
$result["status"]="false";
|
| 226 |
liveuser |
16654 |
|
| 3 |
liveuser |
16655 |
#設置執行失敗訊息
|
|
|
16656 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
16657 |
|
| 3 |
liveuser |
16658 |
#回傳結果
|
|
|
16659 |
return $result;
|
| 226 |
liveuser |
16660 |
|
| 3 |
liveuser |
16661 |
}#if end
|
|
|
16662 |
|
|
|
16663 |
#如果是相對位置
|
|
|
16664 |
if(!(strpos($conf["linkTo"],"/")===0)){
|
| 226 |
liveuser |
16665 |
|
| 3 |
liveuser |
16666 |
#將 $conf["linkTo"] 轉換為針對產生位置的相對位置.
|
|
|
16667 |
#函式說明:
|
|
|
16668 |
#將多個路徑字串變成相對於當前路徑的相對路徑字串
|
|
|
16669 |
#回傳結果:
|
|
|
16670 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
16671 |
#$result["error"],錯誤訊息陣列.
|
| 226 |
liveuser |
16672 |
#$result["function"],函數名稱.
|
| 3 |
liveuser |
16673 |
#$result["argu"],使用的參數.
|
|
|
16674 |
#$result["content"],字串陣列,多個轉換好的相對路徑字串.
|
|
|
16675 |
#必填參數:
|
|
|
16676 |
#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
|
|
|
16677 |
$conf["fileAccess::getRelativePath"]["path"]=array($conf["linkTo"]);
|
|
|
16678 |
#$conf["fileArgu"],字串,當前路徑.
|
|
|
16679 |
$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
|
|
|
16680 |
#可省略參數:
|
|
|
16681 |
#$conf["baseFrom"],字串,指定要依據哪個位置為起點的起始位置,預設不指定,代表使用當前路徑.
|
|
|
16682 |
$conf["fileAccess::getRelativePath"]["baseFrom"]=$conf["path"];
|
|
|
16683 |
#參考資料:
|
|
|
16684 |
#無.
|
|
|
16685 |
#備註:
|
|
|
16686 |
#無.
|
|
|
16687 |
$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
|
|
|
16688 |
unset($conf["fileAccess::getRelativePath"]);
|
|
|
16689 |
|
|
|
16690 |
#如果執行失敗
|
|
|
16691 |
if($getRelativePath["status"]==="false"){
|
| 226 |
liveuser |
16692 |
|
| 3 |
liveuser |
16693 |
#設置執行失敗
|
|
|
16694 |
$result["status"]="false";
|
| 226 |
liveuser |
16695 |
|
| 3 |
liveuser |
16696 |
#設置執行失敗訊息
|
|
|
16697 |
$result["error"]=$getRelativePath;
|
| 226 |
liveuser |
16698 |
|
| 3 |
liveuser |
16699 |
#回傳結果
|
|
|
16700 |
return $result;
|
| 226 |
liveuser |
16701 |
|
| 3 |
liveuser |
16702 |
}#if end
|
|
|
16703 |
|
|
|
16704 |
/*
|
|
|
16705 |
#break point
|
|
|
16706 |
var_dump($conf);
|
|
|
16707 |
var_dump($getRelativePath);
|
|
|
16708 |
exit;
|
|
|
16709 |
*/
|
|
|
16710 |
|
|
|
16711 |
#取得執行的指令
|
|
|
16712 |
$result["cmd"][]=$getRelativePath["cmd"];
|
|
|
16713 |
|
|
|
16714 |
#取得正確的相對位置
|
|
|
16715 |
$conf["linkTo"]=$getRelativePath["content"][0];
|
| 226 |
liveuser |
16716 |
|
| 3 |
liveuser |
16717 |
}#if end
|
|
|
16718 |
|
|
|
16719 |
#初始化給 ln 指令的參數
|
|
|
16720 |
$paramsForLn=array("-s",$conf["linkTo"]);
|
|
|
16721 |
|
|
|
16722 |
#函式說明:
|
|
|
16723 |
#將字串特定關鍵字與其前面的內容剔除
|
|
|
16724 |
#回傳結果:
|
|
|
16725 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
16726 |
#$result["error"],錯誤訊息陣列.
|
|
|
16727 |
#$result["warning"],警告訊息鎮列.
|
|
|
16728 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
16729 |
#$result["function"],當前執行的函數名稱.
|
|
|
16730 |
#$result["oriStr"],要處理的原始字串內容.
|
| 226 |
liveuser |
16731 |
#$result["content"],處理好的的字串內容.
|
| 3 |
liveuser |
16732 |
#必填參數:
|
|
|
16733 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
16734 |
$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$conf["linkTo"];
|
|
|
16735 |
#$conf["keyWord"],字串,特定字串.
|
|
|
16736 |
$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="/";
|
|
|
16737 |
#可省略參數:
|
|
|
16738 |
#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
|
|
|
16739 |
$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
|
|
|
16740 |
#參考資料:
|
|
|
16741 |
#無.
|
|
|
16742 |
#備註:
|
|
|
16743 |
#無.
|
|
|
16744 |
$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
16745 |
unset($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
16746 |
|
|
|
16747 |
#var_dump(__LINE__." ".print_r($delStrBeforeKeyWord,true));
|
|
|
16748 |
|
|
|
16749 |
#如果執行失敗
|
|
|
16750 |
if($delStrBeforeKeyWord["status"]==="false"){
|
| 226 |
liveuser |
16751 |
|
| 3 |
liveuser |
16752 |
#設置執行失敗
|
|
|
16753 |
$result["status"]="false";
|
| 226 |
liveuser |
16754 |
|
| 3 |
liveuser |
16755 |
#設置執行失敗訊息
|
|
|
16756 |
$result["error"]=$delStrBeforeKeyWord;
|
| 226 |
liveuser |
16757 |
|
| 3 |
liveuser |
16758 |
#回傳結果
|
|
|
16759 |
return $result;
|
| 226 |
liveuser |
16760 |
|
| 3 |
liveuser |
16761 |
}#if end
|
| 226 |
liveuser |
16762 |
|
| 3 |
liveuser |
16763 |
#如果沒有找到 "/"
|
|
|
16764 |
if($delStrBeforeKeyWord["founded"]==="false"){
|
| 226 |
liveuser |
16765 |
|
| 3 |
liveuser |
16766 |
#設置 預設的 軟連名稱
|
|
|
16767 |
$softLink=$conf["linkTo"];
|
| 226 |
liveuser |
16768 |
|
| 3 |
liveuser |
16769 |
}#if end
|
|
|
16770 |
|
|
|
16771 |
#反之有 "/"
|
|
|
16772 |
else{
|
| 226 |
liveuser |
16773 |
|
| 3 |
liveuser |
16774 |
#設置 預設的 軟連結名稱
|
|
|
16775 |
$softLink=$delStrBeforeKeyWord["content"];
|
| 226 |
liveuser |
16776 |
|
| 3 |
liveuser |
16777 |
}#else end
|
|
|
16778 |
|
|
|
16779 |
/*
|
|
|
16780 |
#break point
|
|
|
16781 |
var_dump(__LINE__." ".$softLink);
|
|
|
16782 |
exit;
|
|
|
16783 |
*/
|
|
|
16784 |
|
|
|
16785 |
#預設欲建立的軟連結名稱
|
|
|
16786 |
$createdSoftLink=$softLink;
|
|
|
16787 |
|
|
|
16788 |
#如果有設置 path
|
|
|
16789 |
if(isset($conf["path"])){
|
| 226 |
liveuser |
16790 |
|
| 3 |
liveuser |
16791 |
#確認 path 存在
|
|
|
16792 |
#函式說明:
|
|
|
16793 |
#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
|
|
|
16794 |
#回傳結果:
|
|
|
16795 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
16796 |
#$result["error"],錯誤訊息陣列
|
|
|
16797 |
#$result["warning"],警告訊息陣列
|
|
|
16798 |
#必填參數:
|
|
|
16799 |
#$conf["dirPositionAndName"]="";#新建的位置與名稱
|
|
|
16800 |
$conf["fileAccess::createNewFolder"]["dirPositionAndName"]=$conf["path"];
|
|
|
16801 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
16802 |
$conf["fileAccess::createNewFolder"]["fileArgu"]=$conf["fileArgu"];
|
|
|
16803 |
#可省略參數:
|
|
|
16804 |
#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
|
|
|
16805 |
#$conf["dirPermission"]="";
|
|
|
16806 |
#參考資料:
|
|
|
16807 |
#mkdir=>http://php.net/manual/en/function.mkdir.php
|
|
|
16808 |
#chmod=>http://php.net/manual/en/function.chmod.php
|
|
|
16809 |
#參考資料:
|
|
|
16810 |
#無.
|
|
|
16811 |
#備註:
|
|
|
16812 |
#同 function createFolderAfterCheck.
|
|
|
16813 |
$createNewFolder=fileAccess::createNewFolder($conf["fileAccess::createNewFolder"]);
|
|
|
16814 |
unset($conf["fileAccess::createNewFolder"]);
|
| 226 |
liveuser |
16815 |
|
| 3 |
liveuser |
16816 |
#如果執行失敗
|
|
|
16817 |
if($createNewFolder["status"]==="false"){
|
| 226 |
liveuser |
16818 |
|
| 3 |
liveuser |
16819 |
#設置執行失敗
|
|
|
16820 |
$result["status"]="false";
|
| 226 |
liveuser |
16821 |
|
| 3 |
liveuser |
16822 |
#設置執行失敗訊息
|
|
|
16823 |
$result["error"]=$createNewFolder;
|
| 226 |
liveuser |
16824 |
|
| 3 |
liveuser |
16825 |
#回傳結果
|
|
|
16826 |
return $result;
|
| 226 |
liveuser |
16827 |
|
| 3 |
liveuser |
16828 |
}#if end
|
| 226 |
liveuser |
16829 |
|
| 3 |
liveuser |
16830 |
#var_dump(__LINE__." ".print_r($conf,true));
|
| 226 |
liveuser |
16831 |
|
| 3 |
liveuser |
16832 |
#預設要加 slash
|
|
|
16833 |
$slash="/";
|
| 226 |
liveuser |
16834 |
|
| 3 |
liveuser |
16835 |
#如果 path 為 "/" 結尾
|
|
|
16836 |
if($conf["path"][strlen($conf["path"])-1]==="/"){
|
| 226 |
liveuser |
16837 |
|
| 3 |
liveuser |
16838 |
#不用 slash
|
|
|
16839 |
$slash="";
|
| 226 |
liveuser |
16840 |
|
| 3 |
liveuser |
16841 |
}#if end
|
| 226 |
liveuser |
16842 |
|
| 3 |
liveuser |
16843 |
#如果有設置 name
|
|
|
16844 |
if(isset($conf["name"])){
|
| 226 |
liveuser |
16845 |
|
| 3 |
liveuser |
16846 |
#指定軟連結要放在哪邊
|
|
|
16847 |
$paramsForLn[]=$conf["path"].$slash.$conf["name"];
|
| 226 |
liveuser |
16848 |
|
| 3 |
liveuser |
16849 |
#更新欲建立的軟連結名稱
|
|
|
16850 |
$createdSoftLink=$conf["path"].$slash.$conf["name"];
|
| 226 |
liveuser |
16851 |
|
| 3 |
liveuser |
16852 |
/*
|
|
|
16853 |
#break point
|
|
|
16854 |
var_dump($conf["path"],$softLink,$createdSoftLink);
|
|
|
16855 |
exit;
|
|
|
16856 |
*/
|
| 226 |
liveuser |
16857 |
|
| 3 |
liveuser |
16858 |
}#if end
|
| 226 |
liveuser |
16859 |
|
| 3 |
liveuser |
16860 |
#反之
|
|
|
16861 |
else{
|
| 226 |
liveuser |
16862 |
|
| 3 |
liveuser |
16863 |
#指定軟連結要放在哪邊
|
|
|
16864 |
$paramsForLn[]=$conf["path"];
|
| 226 |
liveuser |
16865 |
|
| 3 |
liveuser |
16866 |
#更新欲建立的軟連結名稱
|
|
|
16867 |
$createdSoftLink=$conf["path"].$slash.$softLink;
|
| 226 |
liveuser |
16868 |
|
| 3 |
liveuser |
16869 |
/*
|
|
|
16870 |
#break point
|
|
|
16871 |
var_dump($conf["path"],$softLink,$createdSoftLink);
|
|
|
16872 |
exit;
|
|
|
16873 |
*/
|
| 226 |
liveuser |
16874 |
|
| 3 |
liveuser |
16875 |
}#else end
|
| 226 |
liveuser |
16876 |
|
| 3 |
liveuser |
16877 |
#var_dump($createdSoftLink);
|
| 226 |
liveuser |
16878 |
|
| 3 |
liveuser |
16879 |
}#if end
|
| 226 |
liveuser |
16880 |
|
| 3 |
liveuser |
16881 |
#反之如果有設置 name
|
|
|
16882 |
else if(isset($conf["name"])){
|
| 226 |
liveuser |
16883 |
|
| 3 |
liveuser |
16884 |
#指定軟連結的名稱
|
|
|
16885 |
$paramsForLn[]=$conf["name"];
|
| 226 |
liveuser |
16886 |
|
| 3 |
liveuser |
16887 |
#更新欲建立的軟連結名稱
|
|
|
16888 |
$createdSoftLink=$conf["name"];
|
| 226 |
liveuser |
16889 |
|
| 3 |
liveuser |
16890 |
#var_dump(__LINE__." ".$createdSoftLink);
|
| 226 |
liveuser |
16891 |
|
| 3 |
liveuser |
16892 |
}#if end
|
| 226 |
liveuser |
16893 |
|
| 3 |
liveuser |
16894 |
/*
|
|
|
16895 |
# break point
|
|
|
16896 |
var_dump($createdSoftLink);
|
|
|
16897 |
exit;
|
|
|
16898 |
*/
|
| 226 |
liveuser |
16899 |
|
| 3 |
liveuser |
16900 |
#如果要覆蓋既有的目標
|
|
|
16901 |
if($conf["overWrite"]==="true"){
|
| 226 |
liveuser |
16902 |
|
| 3 |
liveuser |
16903 |
#函式說明:
|
|
|
16904 |
#移除檔案
|
|
|
16905 |
#回傳結果:
|
|
|
16906 |
#$result["status"],"true"代表移除成功,"false"代表移除失敗.
|
|
|
16907 |
#$result["error"],錯誤訊息陣列
|
|
|
16908 |
#$result["warning"],警告訊息陣列
|
|
|
16909 |
#$result["function"],當前執行的函數名稱
|
|
|
16910 |
#必填參數:
|
|
|
16911 |
#$conf["fileAddress"],字串,要移除檔案的位置.
|
|
|
16912 |
$conf["fileAccess::delFile"]["fileAddress"]=$createdSoftLink;
|
|
|
16913 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
16914 |
$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
16915 |
#可省略參數:
|
|
|
16916 |
#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
|
|
|
16917 |
#$conf["commentsArray"]=array("");
|
|
|
16918 |
#$conf["allowDelSymlink"],字串,預設為"false",不移除軟連結;"true"代表要移除軟連結.
|
|
|
16919 |
$conf["fileAccess::delFile"]["allowDelSymlink"]="true";
|
|
|
16920 |
#$conf["allowDelFolder"],字串,預設為"false",不移除目錄;"true"代表要移除目錄.
|
|
|
16921 |
$conf["fileAccess::delFile"]["allowDelFolder"]="true";
|
|
|
16922 |
#參考資料:
|
|
|
16923 |
#無.
|
|
|
16924 |
#備註:
|
|
|
16925 |
#無.
|
|
|
16926 |
$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
|
| 226 |
liveuser |
16927 |
unset($conf["fileAccess::delFile"]);
|
|
|
16928 |
|
| 3 |
liveuser |
16929 |
/*
|
|
|
16930 |
#break point
|
|
|
16931 |
var_dump($delFile);
|
|
|
16932 |
exit;
|
|
|
16933 |
*/
|
| 226 |
liveuser |
16934 |
|
| 3 |
liveuser |
16935 |
#如果執行失敗
|
|
|
16936 |
if($delFile["status"]==="false"){
|
| 226 |
liveuser |
16937 |
|
| 3 |
liveuser |
16938 |
#設置執行失敗
|
|
|
16939 |
$result["status"]="false";
|
| 226 |
liveuser |
16940 |
|
| 3 |
liveuser |
16941 |
#設置執行失敗訊息
|
|
|
16942 |
$result["error"]=$delFile;
|
| 226 |
liveuser |
16943 |
|
| 3 |
liveuser |
16944 |
#回傳結果
|
|
|
16945 |
return $result;
|
| 226 |
liveuser |
16946 |
|
| 3 |
liveuser |
16947 |
}#if end
|
| 226 |
liveuser |
16948 |
|
| 3 |
liveuser |
16949 |
}#if end
|
|
|
16950 |
|
|
|
16951 |
#函式說明:
|
|
|
16952 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
16953 |
#回傳結果:
|
|
|
16954 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
16955 |
#$result["error"],錯誤訊息陣列.
|
|
|
16956 |
#$result["function"],當前執行的函數名稱.
|
|
|
16957 |
#$result["argu"],使用的參數.
|
|
|
16958 |
#$result["cmd"],執行的指令內容.
|
|
|
16959 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
16960 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
16961 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
16962 |
#$result["running"],是否還在執行.
|
|
|
16963 |
#$result["pid"],pid.
|
|
|
16964 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
16965 |
#必填參數:
|
|
|
16966 |
#$conf["command"],字串,要執行的指令與.
|
|
|
16967 |
$conf["external::callShell"]["command"]="ln";
|
|
|
16968 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
16969 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
|
|
16970 |
#可省略參數:
|
|
|
16971 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
16972 |
$conf["external::callShell"]["argu"]=$paramsForLn;
|
|
|
16973 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
16974 |
#$conf["arguIsAddr"]=array();
|
|
|
16975 |
#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
|
|
|
16976 |
#$conf["plainArgu"]=array();
|
|
|
16977 |
#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
|
|
|
16978 |
#$conf["useApostrophe"]=array();
|
|
|
16979 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
16980 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
16981 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
16982 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
16983 |
#$conf["enablePrintDescription"]="true";
|
|
|
16984 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
16985 |
#$conf["printDescription"]="";
|
|
|
16986 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
16987 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
16988 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
16989 |
#$conf["thereIsShellVar"]=array();
|
|
|
16990 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
16991 |
#$conf["username"]="";
|
|
|
16992 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
16993 |
#$conf["password"]="";
|
|
|
16994 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
16995 |
#$conf["useScript"]="";
|
|
|
16996 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
16997 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
16998 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
16999 |
#$conf["inBackGround"]="";
|
|
|
17000 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
17001 |
$conf["external::callShell"]["getErr"]="true";
|
|
|
17002 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
17003 |
#$conf["doNotRun"]="false";
|
|
|
17004 |
#參考資料:
|
|
|
17005 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
17006 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
17007 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
17008 |
#備註:
|
|
|
17009 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
17010 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
17011 |
unset($conf["external::callShell"]);
|
|
|
17012 |
|
|
|
17013 |
#如果執行失敗
|
|
|
17014 |
if($callShell["status"]==="false"){
|
| 226 |
liveuser |
17015 |
|
| 3 |
liveuser |
17016 |
#設置執行失敗
|
|
|
17017 |
$result["status"]="false";
|
| 226 |
liveuser |
17018 |
|
| 3 |
liveuser |
17019 |
#設置執行失敗訊息
|
|
|
17020 |
$result["error"]=$callShell;
|
| 226 |
liveuser |
17021 |
|
| 3 |
liveuser |
17022 |
#回傳結果
|
|
|
17023 |
return $result;
|
| 226 |
liveuser |
17024 |
|
| 3 |
liveuser |
17025 |
}#if end
|
| 226 |
liveuser |
17026 |
|
| 3 |
liveuser |
17027 |
#保存執行的指令
|
|
|
17028 |
$result["cmd"][]=$callShell["cmd"];
|
| 226 |
liveuser |
17029 |
|
| 3 |
liveuser |
17030 |
#初始化給 ls 指令的參數
|
|
|
17031 |
$paramsForLs=array("-l",$paramsForLn[count($paramsForLn)-1]);
|
| 226 |
liveuser |
17032 |
|
| 3 |
liveuser |
17033 |
#取得軟連結的資訊
|
|
|
17034 |
#函式說明:
|
|
|
17035 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
17036 |
#回傳結果:
|
|
|
17037 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
17038 |
#$result["error"],錯誤訊息陣列.
|
|
|
17039 |
#$result["function"],當前執行的函數名稱.
|
|
|
17040 |
#$result["argu"],使用的參數.
|
|
|
17041 |
#$result["cmd"],執行的指令內容.
|
|
|
17042 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
17043 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
17044 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
17045 |
#$result["running"],是否還在執行.
|
|
|
17046 |
#$result["pid"],pid.
|
|
|
17047 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
17048 |
#必填參數:
|
|
|
17049 |
#$conf["command"],字串,要執行的指令與.
|
|
|
17050 |
$conf["external::callShell"]["command"]="ls";
|
|
|
17051 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
17052 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
|
|
17053 |
#可省略參數:
|
|
|
17054 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
17055 |
$conf["external::callShell"]["argu"]=$paramsForLs;
|
|
|
17056 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
17057 |
#$conf["arguIsAddr"]=array();
|
|
|
17058 |
#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
|
|
|
17059 |
#$conf["plainArgu"]=array();
|
|
|
17060 |
#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
|
|
|
17061 |
#$conf["useApostrophe"]=array();
|
|
|
17062 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
17063 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
17064 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
17065 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
17066 |
#$conf["enablePrintDescription"]="true";
|
|
|
17067 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
17068 |
#$conf["printDescription"]="";
|
|
|
17069 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
17070 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
17071 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
17072 |
#$conf["thereIsShellVar"]=array();
|
|
|
17073 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
17074 |
#$conf["username"]="";
|
|
|
17075 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
17076 |
#$conf["password"]="";
|
|
|
17077 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
17078 |
#$conf["useScript"]="";
|
|
|
17079 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
17080 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
17081 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
17082 |
#$conf["inBackGround"]="";
|
|
|
17083 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
17084 |
$conf["external::callShell"]["getErr"]="true";
|
|
|
17085 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
17086 |
#$conf["doNotRun"]="false";
|
|
|
17087 |
#參考資料:
|
|
|
17088 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
17089 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
17090 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
17091 |
#備註:
|
|
|
17092 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
17093 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
17094 |
unset($conf["external::callShell"]);
|
|
|
17095 |
|
|
|
17096 |
#如果執行失敗
|
|
|
17097 |
if($callShell["status"]==="false"){
|
| 226 |
liveuser |
17098 |
|
| 3 |
liveuser |
17099 |
#設置執行失敗
|
|
|
17100 |
$result["status"]="false";
|
| 226 |
liveuser |
17101 |
|
| 3 |
liveuser |
17102 |
#設置執行失敗訊息
|
|
|
17103 |
$result["error"]=$callShell;
|
| 226 |
liveuser |
17104 |
|
| 3 |
liveuser |
17105 |
#回傳結果
|
|
|
17106 |
return $result;
|
| 226 |
liveuser |
17107 |
|
| 3 |
liveuser |
17108 |
}#if end
|
| 226 |
liveuser |
17109 |
|
| 3 |
liveuser |
17110 |
#保存執行的指令
|
|
|
17111 |
$result["cmd"][]=$callShell["cmd"];
|
| 226 |
liveuser |
17112 |
|
| 3 |
liveuser |
17113 |
#取得軟連結的資訊
|
|
|
17114 |
$result["content"]=$callShell["output"];
|
| 226 |
liveuser |
17115 |
|
| 3 |
liveuser |
17116 |
#設置執行正常
|
|
|
17117 |
$result["status"]="true";
|
| 226 |
liveuser |
17118 |
|
| 3 |
liveuser |
17119 |
#回傳結果
|
|
|
17120 |
return $result;
|
| 226 |
liveuser |
17121 |
|
| 3 |
liveuser |
17122 |
}#function createLink end
|
|
|
17123 |
|
|
|
17124 |
/*
|
|
|
17125 |
#函式說明:
|
|
|
17126 |
#針對特定目錄下的內容建立軟連結.
|
|
|
17127 |
#回傳結果:
|
|
|
17128 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
17129 |
#$result["error"],錯誤訊息.
|
|
|
17130 |
#$result["function"],當前執行的函數名稱.
|
|
|
17131 |
#$result["content"],字串陣列,每個建立的軟連結資訊.
|
|
|
17132 |
#必填參數:
|
|
|
17133 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
17134 |
$conf["fileArgu"]=__FILE__;
|
|
|
17135 |
#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
|
|
|
17136 |
$conf["linkToDir"]="";
|
|
|
17137 |
#可省略參數:
|
|
|
17138 |
#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
|
|
|
17139 |
#$conf["path"]="";
|
|
|
17140 |
#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
|
|
|
17141 |
#$conf["name"]=array(array("oriName","newName"));
|
|
|
17142 |
#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
|
|
|
17143 |
#$conf["overWrite"]="true";
|
|
|
17144 |
#參考資料:
|
|
|
17145 |
#無.
|
|
|
17146 |
#備註:
|
|
|
17147 |
#無.
|
|
|
17148 |
*/
|
|
|
17149 |
public static function createMultiLinkInDir(&$conf){
|
| 226 |
liveuser |
17150 |
|
| 3 |
liveuser |
17151 |
#初始化要回傳的結果
|
|
|
17152 |
$result=array();
|
|
|
17153 |
|
|
|
17154 |
#取得當前執行的函數名稱
|
|
|
17155 |
$result["function"]=__FUNCTION__;
|
|
|
17156 |
|
|
|
17157 |
#如果沒有參數
|
|
|
17158 |
if(func_num_args()==0){
|
| 226 |
liveuser |
17159 |
|
| 3 |
liveuser |
17160 |
#設置執行失敗
|
|
|
17161 |
$result["status"]="false";
|
| 226 |
liveuser |
17162 |
|
| 3 |
liveuser |
17163 |
#設置執行錯誤訊息
|
|
|
17164 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
17165 |
|
| 3 |
liveuser |
17166 |
#回傳結果
|
|
|
17167 |
return $result;
|
| 226 |
liveuser |
17168 |
|
| 220 |
liveuser |
17169 |
}#if end
|
| 3 |
liveuser |
17170 |
|
|
|
17171 |
#取得參數
|
|
|
17172 |
$result["argu"]=$conf;
|
|
|
17173 |
|
|
|
17174 |
#如果 $conf 不為陣列
|
|
|
17175 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
17176 |
|
| 3 |
liveuser |
17177 |
#設置執行失敗
|
|
|
17178 |
$result["status"]="false";
|
| 226 |
liveuser |
17179 |
|
| 3 |
liveuser |
17180 |
#設置執行錯誤訊息
|
|
|
17181 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
17182 |
|
| 3 |
liveuser |
17183 |
#如果傳入的參數為 null
|
|
|
17184 |
if($conf===null){
|
| 226 |
liveuser |
17185 |
|
| 3 |
liveuser |
17186 |
#設置執行錯誤訊息
|
|
|
17187 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
17188 |
|
| 3 |
liveuser |
17189 |
}#if end
|
|
|
17190 |
|
|
|
17191 |
#回傳結果
|
|
|
17192 |
return $result;
|
| 226 |
liveuser |
17193 |
|
| 3 |
liveuser |
17194 |
}#if end
|
| 226 |
liveuser |
17195 |
|
| 3 |
liveuser |
17196 |
#檢查參數
|
|
|
17197 |
#函式說明:
|
|
|
17198 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
17199 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
17200 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
17201 |
#$result["function"],當前執行的函式名稱.
|
|
|
17202 |
#$result["argu"],設置給予的參數.
|
|
|
17203 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
17204 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
17205 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
17206 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
17207 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
17208 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
17209 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
17210 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
17211 |
#必填寫的參數:
|
|
|
17212 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
| 226 |
liveuser |
17213 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
| 3 |
liveuser |
17214 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
17215 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
17216 |
#可以省略的參數:
|
|
|
17217 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
17218 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","linkToDir");
|
|
|
17219 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
17220 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
17221 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
17222 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
17223 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
17224 |
#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
|
|
|
17225 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
17226 |
#$conf["canBeEmpty"]=array();
|
|
|
17227 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
17228 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("path","name","overWrite");
|
|
|
17229 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
17230 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("path","name","overWrite");
|
| 226 |
liveuser |
17231 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
17232 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","string");
|
|
|
17233 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
17234 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(".",null,"false");
|
|
|
17235 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
17236 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
17237 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
17238 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
17239 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
17240 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
17241 |
#參考資料來源:
|
|
|
17242 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
17243 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
17244 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
17245 |
|
| 3 |
liveuser |
17246 |
#如果檢查參數失敗
|
|
|
17247 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
17248 |
|
| 3 |
liveuser |
17249 |
#設置執行失敗
|
|
|
17250 |
$result["status"]="false";
|
| 226 |
liveuser |
17251 |
|
| 3 |
liveuser |
17252 |
#設置執行失敗訊息
|
|
|
17253 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
17254 |
|
| 3 |
liveuser |
17255 |
#回傳結果
|
|
|
17256 |
return $result;
|
| 226 |
liveuser |
17257 |
|
| 3 |
liveuser |
17258 |
}#if end
|
| 226 |
liveuser |
17259 |
|
| 3 |
liveuser |
17260 |
#如果檢查參數不通過
|
|
|
17261 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
17262 |
|
| 3 |
liveuser |
17263 |
#設置執行失敗
|
|
|
17264 |
$result["status"]="false";
|
| 226 |
liveuser |
17265 |
|
| 3 |
liveuser |
17266 |
#設置執行失敗訊息
|
|
|
17267 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
17268 |
|
| 3 |
liveuser |
17269 |
#回傳結果
|
|
|
17270 |
return $result;
|
| 226 |
liveuser |
17271 |
|
| 3 |
liveuser |
17272 |
}#if end
|
| 226 |
liveuser |
17273 |
|
| 3 |
liveuser |
17274 |
#函式說明:
|
|
|
17275 |
#取得目錄底下所有目錄與檔案清單.
|
|
|
17276 |
#回傳結果:
|
|
|
17277 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
17278 |
#$result["error"],錯誤訊息陣列.
|
|
|
17279 |
#$result["function"],函數名稱.
|
|
|
17280 |
#$result["content"],陣列,目錄底下的檔案與子目錄.
|
|
|
17281 |
#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
|
|
|
17282 |
#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
|
|
|
17283 |
#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
|
|
|
17284 |
#$result["position"],目前的位置.
|
|
|
17285 |
#必填參數:
|
|
|
17286 |
#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
|
|
|
17287 |
$conf["fileAccess::getList"]["position"]=$conf["linkToDir"];
|
|
|
17288 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
17289 |
$conf["fileAccess::getList"]["fileArgu"]=$conf["fileArgu"];
|
|
|
17290 |
#可省略參數:
|
|
|
17291 |
#無
|
|
|
17292 |
#參考資料:
|
|
|
17293 |
#opendir=>http://php.net/manual/en/function.opendir.php
|
|
|
17294 |
#is_dir=>http://php.net/manual/en/function.is-dir.php
|
|
|
17295 |
#備註:
|
|
|
17296 |
#無.
|
|
|
17297 |
$getList=fileAccess::getList($conf["fileAccess::getList"]);
|
|
|
17298 |
unset($conf["fileAccess::getList"]);
|
| 226 |
liveuser |
17299 |
|
| 3 |
liveuser |
17300 |
#如果檢查參數失敗
|
|
|
17301 |
if($getList["status"]==="false"){
|
| 226 |
liveuser |
17302 |
|
| 3 |
liveuser |
17303 |
#設置執行失敗
|
|
|
17304 |
$result["status"]="false";
|
| 226 |
liveuser |
17305 |
|
| 3 |
liveuser |
17306 |
#設置執行失敗訊息
|
|
|
17307 |
$result["error"]=$getList;
|
| 226 |
liveuser |
17308 |
|
| 3 |
liveuser |
17309 |
#回傳結果
|
|
|
17310 |
return $result;
|
| 226 |
liveuser |
17311 |
|
| 3 |
liveuser |
17312 |
}#if end
|
| 226 |
liveuser |
17313 |
|
| 3 |
liveuser |
17314 |
#針對目標目錄底下的所有檔案
|
|
|
17315 |
foreach($getList["content"] as $oriName){
|
| 226 |
liveuser |
17316 |
|
| 3 |
liveuser |
17317 |
#如果有設定 $conf["name"]
|
|
|
17318 |
if(isset($conf["name"])){
|
| 226 |
liveuser |
17319 |
|
| 3 |
liveuser |
17320 |
#預設不指定新的軟連結名稱
|
|
|
17321 |
unset($newSoftLinkName);
|
| 226 |
liveuser |
17322 |
|
| 3 |
liveuser |
17323 |
#針對每個原始目標的名稱
|
|
|
17324 |
foreach($conf["name"] as $customName){
|
| 226 |
liveuser |
17325 |
|
| 3 |
liveuser |
17326 |
#如果是指定的目標
|
|
|
17327 |
if($oriName["name"]===$customName[0]){
|
| 226 |
liveuser |
17328 |
|
| 3 |
liveuser |
17329 |
#設置新的軟連結名稱
|
|
|
17330 |
$newSoftLinkName=$customName[1];
|
| 226 |
liveuser |
17331 |
|
| 3 |
liveuser |
17332 |
}#if end
|
| 226 |
liveuser |
17333 |
|
| 3 |
liveuser |
17334 |
}#foreach end
|
| 226 |
liveuser |
17335 |
|
| 3 |
liveuser |
17336 |
}#if end
|
| 226 |
liveuser |
17337 |
|
| 3 |
liveuser |
17338 |
#建立軟連結
|
|
|
17339 |
#函式說明:
|
|
|
17340 |
#建立軟連結.
|
|
|
17341 |
#回傳結果:
|
|
|
17342 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
17343 |
#$result["error"],錯誤訊息.
|
|
|
17344 |
#$result["function"],當前執行的函數名稱.
|
|
|
17345 |
#$result["content"],軟連結的資訊.
|
|
|
17346 |
#必填參數:
|
|
|
17347 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
17348 |
$conf["fileAccess::createLink"]["fileArgu"]=$conf["fileArgu"];
|
|
|
17349 |
#$conf["linkTo"],字串,軟連結要指向哪邊.
|
|
|
17350 |
$conf["fileAccess::createLink"]["linkTo"]=$conf["linkToDir"]."/".$oriName["name"];
|
|
|
17351 |
#可省略參數:
|
|
|
17352 |
#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
|
|
|
17353 |
$conf["fileAccess::createLink"]["path"]=$conf["path"];
|
| 226 |
liveuser |
17354 |
|
| 3 |
liveuser |
17355 |
#如果有新的軟連結名稱
|
|
|
17356 |
if(isset($newSoftLinkName)){
|
| 226 |
liveuser |
17357 |
|
| 3 |
liveuser |
17358 |
#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
|
|
|
17359 |
$conf["fileAccess::createLink"]["name"]=$newSoftLinkName;
|
| 226 |
liveuser |
17360 |
|
| 3 |
liveuser |
17361 |
}#if end
|
| 226 |
liveuser |
17362 |
|
| 3 |
liveuser |
17363 |
#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
|
|
|
17364 |
$conf["fileAccess::createLink"]["overWrite"]=$conf["overWrite"];
|
| 226 |
liveuser |
17365 |
|
| 3 |
liveuser |
17366 |
#參考資料:
|
|
|
17367 |
#無.
|
|
|
17368 |
#備註:
|
|
|
17369 |
#無.
|
|
|
17370 |
$createLink=fileAccess::createLink($conf["fileAccess::createLink"]);
|
|
|
17371 |
unset($conf["fileAccess::createLink"]);
|
| 226 |
liveuser |
17372 |
|
| 3 |
liveuser |
17373 |
#var_dump(__LINE__." ".print_r($createLink,true));
|
| 226 |
liveuser |
17374 |
|
| 3 |
liveuser |
17375 |
#如果檢查參數失敗
|
|
|
17376 |
if($createLink["status"]==="false"){
|
| 226 |
liveuser |
17377 |
|
| 3 |
liveuser |
17378 |
#設置執行失敗
|
|
|
17379 |
$result["status"]="false";
|
| 226 |
liveuser |
17380 |
|
| 3 |
liveuser |
17381 |
#設置執行失敗訊息
|
|
|
17382 |
$result["error"]=$createLink;
|
| 226 |
liveuser |
17383 |
|
| 3 |
liveuser |
17384 |
#回傳結果
|
|
|
17385 |
return $result;
|
| 226 |
liveuser |
17386 |
|
| 3 |
liveuser |
17387 |
}#if end
|
| 226 |
liveuser |
17388 |
|
| 3 |
liveuser |
17389 |
#儲存建立好的軟連結資訊
|
|
|
17390 |
$result["content"][]=$createLink["content"];
|
| 226 |
liveuser |
17391 |
|
| 3 |
liveuser |
17392 |
}#foreach end
|
| 226 |
liveuser |
17393 |
|
| 3 |
liveuser |
17394 |
#設置執行正常
|
|
|
17395 |
$result["status"]="true";
|
| 226 |
liveuser |
17396 |
|
| 3 |
liveuser |
17397 |
#回傳結果
|
|
|
17398 |
return $result;
|
| 226 |
liveuser |
17399 |
|
| 3 |
liveuser |
17400 |
}#function createMultiLink end
|
|
|
17401 |
|
|
|
17402 |
/*
|
|
|
17403 |
#函式說明:
|
|
|
17404 |
#更新檔案的內容.
|
|
|
17405 |
#回傳結果:
|
|
|
17406 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
17407 |
#$result["error"],錯誤訊息.
|
|
|
17408 |
#$result["function"],當前執行的函數名稱.
|
| 220 |
liveuser |
17409 |
#$result["content"],更新的資訊.
|
|
|
17410 |
#$result["content"][$lineIndex]["ori"],原始 $lineIndex+1 行的內容,若為null則代表不存在.
|
|
|
17411 |
#$result["content"][$lineIndex]["new"],新 $lineIndex+1 行的內容,若為null則代表不存在.
|
| 3 |
liveuser |
17412 |
#必填參數:
|
|
|
17413 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
17414 |
$conf["fileArgu"]=__FILE__;
|
|
|
17415 |
#$conf["file"],字串,要更新的檔案位置與名稱.
|
|
|
17416 |
$conf["file"]="";
|
|
|
17417 |
#可省略參數:
|
|
|
17418 |
#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
|
|
|
17419 |
#$conf["overWriteWith"]=array();
|
|
|
17420 |
#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
|
|
|
17421 |
#$conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
|
|
|
17422 |
#$conf["replaceLike"],字串,預設為"false",代表要完全符合關鍵字才能進行整行替換;反之為"true".
|
|
|
17423 |
#$conf["replaceLike"]="false";
|
|
|
17424 |
#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
|
|
|
17425 |
#$conf["addToTailWhenNoMatch"]="false";
|
|
|
17426 |
#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
|
|
|
17427 |
#$conf["addToTailBeforeThat"]="?\>";
|
| 220 |
liveuser |
17428 |
#$conf["replaceSpecifyLine"],字串陣列,將指定的行取代成指定的內容,元素的key為原始檔案的行索引,若key為$i+1,則代表第$i行;元素的數值就為該行的新內容.
|
|
|
17429 |
#$conf["replaceSpecifyLine"]=array();
|
|
|
17430 |
#$conf["outputPath"],字串,檔案要輸出到哪個位置,預設不指定,直接取代原始檔案的內容.
|
|
|
17431 |
#$conf["outputPath"]="";
|
| 3 |
liveuser |
17432 |
#參考資料:
|
|
|
17433 |
#無.
|
|
|
17434 |
#備註:
|
|
|
17435 |
#無.
|
|
|
17436 |
*/
|
|
|
17437 |
public static function updateFile(&$conf){
|
| 226 |
liveuser |
17438 |
|
| 3 |
liveuser |
17439 |
#初始化要回傳的結果
|
|
|
17440 |
$result=array();
|
|
|
17441 |
|
|
|
17442 |
#取得當前執行的函數名稱
|
|
|
17443 |
$result["function"]=__FUNCTION__;
|
|
|
17444 |
|
|
|
17445 |
#如果沒有參數
|
|
|
17446 |
if(func_num_args()==0){
|
| 226 |
liveuser |
17447 |
|
| 3 |
liveuser |
17448 |
#設置執行失敗
|
|
|
17449 |
$result["status"]="false";
|
| 226 |
liveuser |
17450 |
|
| 3 |
liveuser |
17451 |
#設置執行錯誤訊息
|
|
|
17452 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
17453 |
|
| 3 |
liveuser |
17454 |
#回傳結果
|
|
|
17455 |
return $result;
|
| 226 |
liveuser |
17456 |
|
| 220 |
liveuser |
17457 |
}#if end
|
| 3 |
liveuser |
17458 |
|
|
|
17459 |
#取得參數
|
|
|
17460 |
$result["argu"]=$conf;
|
|
|
17461 |
|
|
|
17462 |
#如果 $conf 不為陣列
|
|
|
17463 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
17464 |
|
| 3 |
liveuser |
17465 |
#設置執行失敗
|
|
|
17466 |
$result["status"]="false";
|
| 226 |
liveuser |
17467 |
|
| 3 |
liveuser |
17468 |
#設置執行錯誤訊息
|
|
|
17469 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
17470 |
|
| 3 |
liveuser |
17471 |
#如果傳入的參數為 null
|
|
|
17472 |
if($conf===null){
|
| 226 |
liveuser |
17473 |
|
| 3 |
liveuser |
17474 |
#設置執行錯誤訊息
|
|
|
17475 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
17476 |
|
| 3 |
liveuser |
17477 |
}#if end
|
|
|
17478 |
|
|
|
17479 |
#回傳結果
|
|
|
17480 |
return $result;
|
| 226 |
liveuser |
17481 |
|
| 3 |
liveuser |
17482 |
}#if end
|
| 226 |
liveuser |
17483 |
|
| 3 |
liveuser |
17484 |
#檢查參數
|
|
|
17485 |
#函式說明:
|
|
|
17486 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
17487 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
17488 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
17489 |
#$result["function"],當前執行的函式名稱.
|
|
|
17490 |
#$result["argu"],設置給予的參數.
|
|
|
17491 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
17492 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
17493 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
17494 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
17495 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
17496 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
17497 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
17498 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
17499 |
#必填寫的參數:
|
|
|
17500 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
| 220 |
liveuser |
17501 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
| 3 |
liveuser |
17502 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
17503 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
17504 |
#可以省略的參數:
|
|
|
17505 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
17506 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","file");
|
|
|
17507 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
17508 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
17509 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
17510 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
17511 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
17512 |
#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("file");
|
|
|
17513 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
17514 |
#$conf["canBeEmpty"]=array();
|
|
|
17515 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
| 220 |
liveuser |
17516 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("overWriteWith","replaceWith","addToTailWhenNoMatch","addToTailBeforeThat","replaceLike","replaceSpecifyLine","outputPath");
|
| 3 |
liveuser |
17517 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
| 220 |
liveuser |
17518 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("overWriteWith","replaceWith","addToTailWhenNoMatch","addToTailBeforeThat","replaceLike","replaceSpecifyLine","outputPath");
|
| 226 |
liveuser |
17519 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 220 |
liveuser |
17520 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","array","string","string","string","array","string");
|
| 3 |
liveuser |
17521 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
| 220 |
liveuser |
17522 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"false",null,"false",null,null);
|
| 3 |
liveuser |
17523 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
17524 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
17525 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
17526 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
17527 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
17528 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
17529 |
#參考資料來源:
|
|
|
17530 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
17531 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
17532 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
17533 |
|
| 3 |
liveuser |
17534 |
#如果檢查參數失敗
|
|
|
17535 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
17536 |
|
| 3 |
liveuser |
17537 |
#設置執行失敗
|
|
|
17538 |
$result["status"]="false";
|
| 226 |
liveuser |
17539 |
|
| 3 |
liveuser |
17540 |
#設置執行失敗訊息
|
|
|
17541 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
17542 |
|
| 3 |
liveuser |
17543 |
#回傳結果
|
|
|
17544 |
return $result;
|
| 226 |
liveuser |
17545 |
|
| 3 |
liveuser |
17546 |
}#if end
|
| 226 |
liveuser |
17547 |
|
| 3 |
liveuser |
17548 |
#如果檢查參數不通過
|
|
|
17549 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
17550 |
|
| 3 |
liveuser |
17551 |
#設置執行失敗
|
|
|
17552 |
$result["status"]="false";
|
| 226 |
liveuser |
17553 |
|
| 3 |
liveuser |
17554 |
#設置執行失敗訊息
|
|
|
17555 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
17556 |
|
| 3 |
liveuser |
17557 |
#回傳結果
|
|
|
17558 |
return $result;
|
| 226 |
liveuser |
17559 |
|
| 3 |
liveuser |
17560 |
}#if end
|
| 226 |
liveuser |
17561 |
|
| 3 |
liveuser |
17562 |
#檢查檔案是否存在
|
|
|
17563 |
#函式說明:
|
|
|
17564 |
#檢查多個檔案與資料夾是否存在.
|
|
|
17565 |
#回傳的結果:
|
|
|
17566 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
17567 |
#$result["error"],錯誤訊息陣列.
|
|
|
17568 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
17569 |
#$result["argu"],使用的參數.
|
|
|
17570 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
17571 |
#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
|
|
|
17572 |
#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
|
|
|
17573 |
#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
|
|
|
17574 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
17575 |
#必填參數:
|
|
|
17576 |
#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
17577 |
$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["file"]);
|
|
|
17578 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
17579 |
$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
17580 |
#可省略參數:
|
|
|
17581 |
#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
|
|
|
17582 |
$conf["disableWebSearch"]="true";
|
|
|
17583 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
17584 |
$conf["userDir"]="false";
|
|
|
17585 |
#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
|
|
|
17586 |
$conf["web"]="false";
|
|
|
17587 |
#參考資料:
|
|
|
17588 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
17589 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
17590 |
#備註:
|
|
|
17591 |
#函數file_exists檢查的路徑為檔案系統的路徑
|
|
|
17592 |
#$result["varName"][$i]結果未實作
|
|
|
17593 |
$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
|
|
|
17594 |
unset($conf["fileAccess::checkMultiFileExist"]);
|
| 226 |
liveuser |
17595 |
|
| 3 |
liveuser |
17596 |
#如果檢查參數失敗
|
|
|
17597 |
if($checkMultiFileExist["status"]==="false"){
|
| 226 |
liveuser |
17598 |
|
| 3 |
liveuser |
17599 |
#設置執行失敗
|
|
|
17600 |
$result["status"]="false";
|
| 226 |
liveuser |
17601 |
|
| 3 |
liveuser |
17602 |
#設置執行失敗訊息
|
|
|
17603 |
$result["error"]=$checkMultiFileExist;
|
| 226 |
liveuser |
17604 |
|
| 3 |
liveuser |
17605 |
#回傳結果
|
|
|
17606 |
return $result;
|
| 226 |
liveuser |
17607 |
|
| 3 |
liveuser |
17608 |
}#if end
|
| 226 |
liveuser |
17609 |
|
| 3 |
liveuser |
17610 |
#如果目標檔案不存在
|
|
|
17611 |
if($checkMultiFileExist["allExist"]==="false"){
|
| 226 |
liveuser |
17612 |
|
| 3 |
liveuser |
17613 |
#設置執行失敗
|
|
|
17614 |
$result["status"]="false";
|
| 226 |
liveuser |
17615 |
|
| 3 |
liveuser |
17616 |
#設置執行失敗訊息
|
|
|
17617 |
$result["error"]=$checkMultiFileExist;
|
| 226 |
liveuser |
17618 |
|
| 3 |
liveuser |
17619 |
#回傳結果
|
|
|
17620 |
return $result;
|
| 226 |
liveuser |
17621 |
|
| 3 |
liveuser |
17622 |
}#if end
|
| 226 |
liveuser |
17623 |
|
| 220 |
liveuser |
17624 |
#預設要寫入的位置為原始檔案
|
|
|
17625 |
$file2write=$conf["file"];
|
| 226 |
liveuser |
17626 |
|
| 220 |
liveuser |
17627 |
#如果有設置 outputPath
|
|
|
17628 |
if(isset($conf["outputPath"])){
|
| 226 |
liveuser |
17629 |
|
| 220 |
liveuser |
17630 |
#寫入檔案的路徑與名稱
|
|
|
17631 |
$file2write=$conf["outputPath"]."/".$conf["file"];
|
| 226 |
liveuser |
17632 |
|
| 220 |
liveuser |
17633 |
}#if end
|
| 226 |
liveuser |
17634 |
|
| 3 |
liveuser |
17635 |
#如果有設置 overWriteWith
|
|
|
17636 |
if(isset($conf["overWriteWith"])){
|
| 226 |
liveuser |
17637 |
|
| 3 |
liveuser |
17638 |
#函式說明:
|
|
|
17639 |
#將多行字串寫入到檔案
|
|
|
17640 |
#回傳結果:
|
|
|
17641 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
17642 |
#$result["error"],錯誤訊息陣列.
|
|
|
17643 |
#$result["function"],當前執行函數的名稱.
|
|
|
17644 |
#必填參數:
|
|
|
17645 |
#$conf["fileName"],字串,爲要編輯的檔案名稱
|
| 220 |
liveuser |
17646 |
$conf["fileAccess::writeMultiLine"]["fileName"]=$file2write;
|
| 3 |
liveuser |
17647 |
#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
|
|
|
17648 |
$conf["fileAccess::writeMultiLine"]["inputString"]=$conf["overWriteWith"];
|
|
|
17649 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
17650 |
$conf["fileAccess::writeMultiLine"]["fileArgu"]=$conf["fileArgu"];
|
| 220 |
liveuser |
17651 |
#$conf["fastWrite"],字串,“true”代表要一次寫入多行內容;預設為"false"代表一次寫入一行,比較安全,但行數一多會需要等待多時.
|
|
|
17652 |
$conf["fileAccess::writeMultiLine"]["fastWrite"]="true";
|
| 3 |
liveuser |
17653 |
#可省略參數:
|
|
|
17654 |
#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
|
|
|
17655 |
#參考資料:
|
|
|
17656 |
#無.
|
|
|
17657 |
#備註:
|
|
|
17658 |
#無.
|
|
|
17659 |
$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
|
|
|
17660 |
unset($conf["fileAccess::writeMultiLine"]);
|
| 226 |
liveuser |
17661 |
|
| 3 |
liveuser |
17662 |
#如果執行失敗
|
|
|
17663 |
if($writeMultiLine["status"]==="false"){
|
| 226 |
liveuser |
17664 |
|
| 3 |
liveuser |
17665 |
#設置執行失敗
|
|
|
17666 |
$result["status"]="false";
|
| 226 |
liveuser |
17667 |
|
| 3 |
liveuser |
17668 |
#設置執行失敗訊息
|
|
|
17669 |
$result["error"]=$writeMultiLine;
|
| 226 |
liveuser |
17670 |
|
| 3 |
liveuser |
17671 |
#回傳結果
|
|
|
17672 |
return $result;
|
| 226 |
liveuser |
17673 |
|
| 3 |
liveuser |
17674 |
}#if end
|
| 226 |
liveuser |
17675 |
|
| 220 |
liveuser |
17676 |
#取得原始檔案的內容
|
|
|
17677 |
#函式說明:
|
|
|
17678 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
17679 |
#回傳的變數說明:
|
|
|
17680 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
|
|
|
17681 |
#$result["error"],錯誤訊息提示.
|
|
|
17682 |
#$result["warning"],警告訊息.
|
|
|
17683 |
#$result["function"],當前執行的函數名稱.
|
|
|
17684 |
#$result["fileContent"],爲檔案的內容陣列.
|
|
|
17685 |
#$result["lineCount"],爲檔案內容總共的行數.
|
|
|
17686 |
#$result["fullContent"],為檔案的完整內容.
|
|
|
17687 |
#$result["base64data"],為檔案的base64內容.
|
|
|
17688 |
#$result["mimeType"],為檔案的mime type.
|
|
|
17689 |
#必填參數:
|
|
|
17690 |
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
|
|
|
17691 |
$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["file"];
|
|
|
17692 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
17693 |
$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
|
|
|
17694 |
#可省略參數:
|
|
|
17695 |
#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
|
|
|
17696 |
$conf["fileAccess::getFileContent"]["web"]="false";
|
|
|
17697 |
#參考資料:
|
|
|
17698 |
#file(),取得檔案內容的行數.
|
|
|
17699 |
#file=>http:#php.net/manual/en/function.file.php
|
|
|
17700 |
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
|
|
|
17701 |
#filesize=>http://php.net/manual/en/function.filesize.php
|
|
|
17702 |
#參考資料:
|
|
|
17703 |
#無.
|
|
|
17704 |
#備註:
|
|
|
17705 |
#無.
|
|
|
17706 |
$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
|
|
|
17707 |
unset($conf["fileAccess::getFileContent"]);
|
| 226 |
liveuser |
17708 |
|
| 220 |
liveuser |
17709 |
#如果執行失敗
|
|
|
17710 |
if($getFileContent["status"]==="false"){
|
| 226 |
liveuser |
17711 |
|
| 220 |
liveuser |
17712 |
#設置執行失敗
|
|
|
17713 |
$result["status"]="false";
|
| 226 |
liveuser |
17714 |
|
| 220 |
liveuser |
17715 |
#設置執行失敗訊息
|
|
|
17716 |
$result["error"]=$getFileContent;
|
| 226 |
liveuser |
17717 |
|
| 220 |
liveuser |
17718 |
#回傳結果
|
|
|
17719 |
return $result;
|
| 226 |
liveuser |
17720 |
|
| 220 |
liveuser |
17721 |
}#if end
|
| 226 |
liveuser |
17722 |
|
| 220 |
liveuser |
17723 |
#無窮迴圈
|
|
|
17724 |
for($i=0;$i>=0;$i++){
|
| 226 |
liveuser |
17725 |
|
| 220 |
liveuser |
17726 |
#如果有舊或新的行內容存在
|
|
|
17727 |
if( isset($getFileContent["fileContent"][$i]) || isset($conf["overWriteWith"][$i]) ){
|
| 226 |
liveuser |
17728 |
|
| 220 |
liveuser |
17729 |
#初始化暫存舊行內容的變數
|
|
|
17730 |
$oriLine=null;
|
| 226 |
liveuser |
17731 |
|
| 220 |
liveuser |
17732 |
#初始化暫存新行內容的變數
|
|
|
17733 |
$newLine=null;
|
| 226 |
liveuser |
17734 |
|
| 220 |
liveuser |
17735 |
#如果存在原行內容
|
|
|
17736 |
if(isset($getFileContent["fileContent"][$i])){
|
| 226 |
liveuser |
17737 |
|
| 220 |
liveuser |
17738 |
#儲存原行內容
|
|
|
17739 |
$oriLine=$getFileContent["fileContent"][$i];
|
| 226 |
liveuser |
17740 |
|
| 220 |
liveuser |
17741 |
}#if end
|
| 226 |
liveuser |
17742 |
|
| 220 |
liveuser |
17743 |
#如果存在新行內容
|
|
|
17744 |
if(isset($conf["overWriteWith"][$i])){
|
| 226 |
liveuser |
17745 |
|
| 220 |
liveuser |
17746 |
#儲存新行內容
|
|
|
17747 |
$newLine=$conf["overWriteWith"][$i];
|
| 226 |
liveuser |
17748 |
|
| 220 |
liveuser |
17749 |
}#if end
|
| 226 |
liveuser |
17750 |
|
| 220 |
liveuser |
17751 |
#設置更新的資訊
|
|
|
17752 |
$result["content"][$i]=array("ori"=>$oriLine,"new"=>$newLine);
|
| 226 |
liveuser |
17753 |
|
| 220 |
liveuser |
17754 |
}#if end
|
| 226 |
liveuser |
17755 |
|
| 220 |
liveuser |
17756 |
#反之
|
|
|
17757 |
else{
|
| 226 |
liveuser |
17758 |
|
| 220 |
liveuser |
17759 |
#結束迴圈
|
|
|
17760 |
break;
|
| 226 |
liveuser |
17761 |
|
| 220 |
liveuser |
17762 |
}#else end
|
| 226 |
liveuser |
17763 |
|
| 220 |
liveuser |
17764 |
}#for end
|
| 226 |
liveuser |
17765 |
|
| 3 |
liveuser |
17766 |
}#if end
|
| 226 |
liveuser |
17767 |
|
| 220 |
liveuser |
17768 |
#反之如果有設置 "replaceWith"
|
|
|
17769 |
else if(isset($conf["replaceWith"])){
|
| 226 |
liveuser |
17770 |
|
| 3 |
liveuser |
17771 |
#取得檔案的內容
|
|
|
17772 |
#函式說明:
|
|
|
17773 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
17774 |
#回傳的變數說明:
|
|
|
17775 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
|
|
|
17776 |
#$result["error"],錯誤訊息提示.
|
|
|
17777 |
#$result["warning"],警告訊息.
|
|
|
17778 |
#$result["function"],當前執行的函數名稱.
|
|
|
17779 |
#$result["fileContent"],爲檔案的內容陣列.
|
|
|
17780 |
#$result["lineCount"],爲檔案內容總共的行數.
|
|
|
17781 |
#$result["fullContent"],為檔案的完整內容.
|
|
|
17782 |
#$result["base64data"],為檔案的base64內容.
|
|
|
17783 |
#$result["mimeType"],為檔案的mime type.
|
|
|
17784 |
#必填參數:
|
|
|
17785 |
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
|
|
|
17786 |
$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["file"];
|
|
|
17787 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
17788 |
$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
|
|
|
17789 |
#可省略參數:
|
|
|
17790 |
#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
|
|
|
17791 |
$conf["fileAccess::getFileContent"]["web"]="false";
|
|
|
17792 |
#參考資料:
|
|
|
17793 |
#file(),取得檔案內容的行數.
|
|
|
17794 |
#file=>http:#php.net/manual/en/function.file.php
|
|
|
17795 |
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
|
|
|
17796 |
#filesize=>http://php.net/manual/en/function.filesize.php
|
|
|
17797 |
#參考資料:
|
|
|
17798 |
#無.
|
|
|
17799 |
#備註:
|
|
|
17800 |
#無.
|
|
|
17801 |
$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
|
|
|
17802 |
unset($conf["fileAccess::getFileContent"]);
|
| 226 |
liveuser |
17803 |
|
| 3 |
liveuser |
17804 |
#如果執行失敗
|
|
|
17805 |
if($getFileContent["status"]==="false"){
|
| 226 |
liveuser |
17806 |
|
| 3 |
liveuser |
17807 |
#設置執行失敗
|
|
|
17808 |
$result["status"]="false";
|
| 226 |
liveuser |
17809 |
|
| 3 |
liveuser |
17810 |
#設置執行失敗訊息
|
|
|
17811 |
$result["error"]=$getFileContent;
|
| 226 |
liveuser |
17812 |
|
| 3 |
liveuser |
17813 |
#回傳結果
|
|
|
17814 |
return $result;
|
| 226 |
liveuser |
17815 |
|
| 3 |
liveuser |
17816 |
}#if end
|
| 226 |
liveuser |
17817 |
|
| 3 |
liveuser |
17818 |
#取得原始檔案的每行內容
|
|
|
17819 |
$oriFileContentByLine=&$getFileContent["fileContent"];
|
| 226 |
liveuser |
17820 |
|
| 3 |
liveuser |
17821 |
#針對每個 replaceWith 條件
|
|
|
17822 |
foreach($conf["replaceWith"] as $replaceInfo){
|
| 226 |
liveuser |
17823 |
|
| 3 |
liveuser |
17824 |
#預設尚未找到符合的關鍵字
|
|
|
17825 |
$foundKeyWord=false;
|
| 226 |
liveuser |
17826 |
|
| 3 |
liveuser |
17827 |
#取得要替換的目標字串
|
|
|
17828 |
$oriStr=$replaceInfo[0];
|
| 226 |
liveuser |
17829 |
|
| 3 |
liveuser |
17830 |
#取得要替換成的字串內容
|
|
|
17831 |
$newStr=$replaceInfo[1];
|
| 226 |
liveuser |
17832 |
|
| 3 |
liveuser |
17833 |
#針對每行原始內容
|
|
|
17834 |
foreach($oriFileContentByLine as $index => $line){
|
| 226 |
liveuser |
17835 |
|
| 3 |
liveuser |
17836 |
#函式說明:
|
|
|
17837 |
#檢查字串裡面有無指定的關鍵字
|
|
|
17838 |
#回傳結果:
|
|
|
17839 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
17840 |
#$result["error"],錯誤訊息
|
|
|
17841 |
#$result["function"],當前執行的函數名稱.
|
|
|
17842 |
#$result["argu"],使用的參數.
|
|
|
17843 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
17844 |
#$result["keyWordCount"],找到的關鍵字數量.
|
|
|
17845 |
#必填參數:
|
|
|
17846 |
#$conf["keyWord"],字串,想要搜尋的關鍵字.
|
|
|
17847 |
$conf["search::findKeyWord"]["keyWord"]=$oriStr;
|
|
|
17848 |
#$conf["string"],字串,要被搜尋的字串內容
|
|
|
17849 |
$conf["search::findKeyWord"]["string"]=$line;
|
|
|
17850 |
#可省略參數:
|
| 226 |
liveuser |
17851 |
|
| 3 |
liveuser |
17852 |
#如果要完全符合關鍵字
|
|
|
17853 |
if($conf["replaceLike"]==="false"){
|
| 226 |
liveuser |
17854 |
|
| 3 |
liveuser |
17855 |
#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
17856 |
$conf["search::findKeyWord"]["completeEqual"]="true";
|
| 226 |
liveuser |
17857 |
|
| 3 |
liveuser |
17858 |
}#if end
|
| 226 |
liveuser |
17859 |
|
| 3 |
liveuser |
17860 |
#參考資料:
|
|
|
17861 |
#無.
|
|
|
17862 |
#備註:
|
|
|
17863 |
#無.
|
|
|
17864 |
$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
|
|
|
17865 |
unset($conf["search::findKeyWord"]);
|
| 226 |
liveuser |
17866 |
|
| 3 |
liveuser |
17867 |
#如果執行失敗
|
|
|
17868 |
if($findKeyWord["status"]==="false"){
|
| 226 |
liveuser |
17869 |
|
| 3 |
liveuser |
17870 |
#設置執行失敗
|
|
|
17871 |
$result["status"]="false";
|
| 226 |
liveuser |
17872 |
|
| 3 |
liveuser |
17873 |
#設置執行失敗訊息
|
|
|
17874 |
$result["error"]=$findKeyWord;
|
| 226 |
liveuser |
17875 |
|
| 3 |
liveuser |
17876 |
#回傳結果
|
|
|
17877 |
return $result;
|
| 226 |
liveuser |
17878 |
|
| 3 |
liveuser |
17879 |
}#if end
|
| 226 |
liveuser |
17880 |
|
| 3 |
liveuser |
17881 |
#如果有找到關鍵字
|
|
|
17882 |
if($findKeyWord["founded"]==="true"){
|
| 226 |
liveuser |
17883 |
|
| 220 |
liveuser |
17884 |
#設置更新的資訊
|
|
|
17885 |
$result["content"][$lineIndex]=array("ori"=>$oriFileContentByLine[$index],"new"=>$newStr);
|
| 226 |
liveuser |
17886 |
|
| 3 |
liveuser |
17887 |
#更新該行內容
|
|
|
17888 |
$oriFileContentByLine[$index]=$newStr;
|
| 226 |
liveuser |
17889 |
|
| 3 |
liveuser |
17890 |
#設置有找到符合的關鍵字
|
|
|
17891 |
$foundKeyWord=true;
|
| 226 |
liveuser |
17892 |
|
| 3 |
liveuser |
17893 |
}#if end
|
| 226 |
liveuser |
17894 |
|
| 3 |
liveuser |
17895 |
}#foreach end
|
| 226 |
liveuser |
17896 |
|
| 3 |
liveuser |
17897 |
#如果沒有找到關鍵字
|
|
|
17898 |
if($foundKeyWord===false){
|
| 226 |
liveuser |
17899 |
|
| 3 |
liveuser |
17900 |
#如果要新增內容
|
|
|
17901 |
if($conf["addToTailWhenNoMatch"]==="true"){
|
| 226 |
liveuser |
17902 |
|
| 3 |
liveuser |
17903 |
#如果有設置 addToTailBeforeThat
|
|
|
17904 |
if(isset($conf["addToTailBeforeThat"])){
|
| 226 |
liveuser |
17905 |
|
| 3 |
liveuser |
17906 |
#預設沒有找到符合的關鍵字
|
|
|
17907 |
$foundKeyWord=false;
|
| 226 |
liveuser |
17908 |
|
| 3 |
liveuser |
17909 |
#初始化要記錄要 append 回去的各行內容.
|
|
|
17910 |
$linesToAppend=array();
|
| 226 |
liveuser |
17911 |
|
| 3 |
liveuser |
17912 |
#倒敘,針對每行內容
|
|
|
17913 |
for($i=count($oriFileContentByLine)-1;$i>=0;$i--){
|
| 226 |
liveuser |
17914 |
|
| 3 |
liveuser |
17915 |
#儲存要 append 回去的行內容
|
|
|
17916 |
$linesToAppend[]=$oriFileContentByLine[$i];
|
| 226 |
liveuser |
17917 |
|
| 3 |
liveuser |
17918 |
#如果找到關鍵字了
|
|
|
17919 |
if($oriFileContentByLine[$i]===$conf["addToTailBeforeThat"]){
|
| 226 |
liveuser |
17920 |
|
| 3 |
liveuser |
17921 |
#設置有找到符合的關鍵字
|
|
|
17922 |
$foundKeyWord=true;
|
| 226 |
liveuser |
17923 |
|
| 220 |
liveuser |
17924 |
#設置更新的資訊
|
|
|
17925 |
$result["content"][$lineIndex]=array("ori"=>$oriFileContentByLine[$i],"new"=>$line);
|
| 226 |
liveuser |
17926 |
|
| 3 |
liveuser |
17927 |
#更新該行內容
|
|
|
17928 |
$oriFileContentByLine[$i]=$line;
|
| 226 |
liveuser |
17929 |
|
| 3 |
liveuser |
17930 |
#倒敘陣列
|
|
|
17931 |
$linesToAppend=array_reverse($linesToAppend);
|
| 226 |
liveuser |
17932 |
|
| 3 |
liveuser |
17933 |
#針對每行要 append 回去的內容
|
|
|
17934 |
foreach($linesToAppend as $lineToAppend){
|
| 226 |
liveuser |
17935 |
|
| 3 |
liveuser |
17936 |
#append 行內容
|
|
|
17937 |
$oriFileContentByLine[]=$lineToAppend;
|
| 226 |
liveuser |
17938 |
|
| 220 |
liveuser |
17939 |
#設置更新的資訊
|
|
|
17940 |
$result["content"][count($oriFileContentByLine)-1]=array("ori"=>null,"new"=>$lineToAppend);
|
| 226 |
liveuser |
17941 |
|
| 3 |
liveuser |
17942 |
}#foreach end
|
| 226 |
liveuser |
17943 |
|
| 3 |
liveuser |
17944 |
}#if end
|
| 226 |
liveuser |
17945 |
|
| 3 |
liveuser |
17946 |
}#for end
|
| 226 |
liveuser |
17947 |
|
| 3 |
liveuser |
17948 |
#如果沒有找到關鍵字
|
|
|
17949 |
if($foundKeyWord===false){
|
| 226 |
liveuser |
17950 |
|
| 3 |
liveuser |
17951 |
#設置執行失敗
|
|
|
17952 |
$result["status"]="false";
|
| 226 |
liveuser |
17953 |
|
| 3 |
liveuser |
17954 |
#設置錯誤訊息
|
|
|
17955 |
$result["error"]="can't find \"".$conf["addToTailBeforeThat"]."\" to insert before it.";
|
| 226 |
liveuser |
17956 |
|
| 3 |
liveuser |
17957 |
#回傳結果
|
|
|
17958 |
return $result;
|
| 226 |
liveuser |
17959 |
|
| 3 |
liveuser |
17960 |
}#if end
|
| 226 |
liveuser |
17961 |
|
| 3 |
liveuser |
17962 |
}#if end
|
| 226 |
liveuser |
17963 |
|
| 3 |
liveuser |
17964 |
}#if end
|
| 226 |
liveuser |
17965 |
|
| 3 |
liveuser |
17966 |
}#if end
|
| 226 |
liveuser |
17967 |
|
| 3 |
liveuser |
17968 |
}#foreach end
|
| 226 |
liveuser |
17969 |
|
| 3 |
liveuser |
17970 |
#函式說明:
|
|
|
17971 |
#將多行字串寫入到檔案
|
|
|
17972 |
#回傳結果:
|
|
|
17973 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
17974 |
#$result["error"],錯誤訊息陣列.
|
|
|
17975 |
#$result["function"],當前執行函數的名稱.
|
|
|
17976 |
#必填參數:
|
|
|
17977 |
#$conf["fileName"],字串,爲要編輯的檔案名稱
|
| 220 |
liveuser |
17978 |
$conf["fileAccess::writeMultiLine"]["fileName"]=$file2write;
|
| 3 |
liveuser |
17979 |
#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
|
|
|
17980 |
$conf["fileAccess::writeMultiLine"]["inputString"]=$oriFileContentByLine;
|
|
|
17981 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
17982 |
$conf["fileAccess::writeMultiLine"]["fileArgu"]=$conf["fileArgu"];
|
|
|
17983 |
#可省略參數:
|
|
|
17984 |
#$conf["fileAccess::writeMultiLine"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
|
| 220 |
liveuser |
17985 |
#$conf["fastWrite"],字串,“true”代表要一次寫入多行內容;預設為"false"代表一次寫入一行,比較安全,但行數一多會需要等待多時.
|
|
|
17986 |
$conf["fileAccess::writeMultiLine"]["fastWrite"]="true";
|
| 3 |
liveuser |
17987 |
#參考資料:
|
|
|
17988 |
#無.
|
|
|
17989 |
#備註:
|
|
|
17990 |
#無.
|
|
|
17991 |
$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
|
|
|
17992 |
unset($conf["fileAccess::writeMultiLine"]);
|
| 226 |
liveuser |
17993 |
|
| 3 |
liveuser |
17994 |
#如果執行失敗
|
|
|
17995 |
if($writeMultiLine["status"]==="false"){
|
| 226 |
liveuser |
17996 |
|
| 3 |
liveuser |
17997 |
#設置執行失敗
|
|
|
17998 |
$result["status"]="false";
|
| 226 |
liveuser |
17999 |
|
| 3 |
liveuser |
18000 |
#設置執行失敗訊息
|
|
|
18001 |
$result["error"]=$writeMultiLine;
|
| 226 |
liveuser |
18002 |
|
| 3 |
liveuser |
18003 |
#回傳結果
|
|
|
18004 |
return $result;
|
| 226 |
liveuser |
18005 |
|
| 3 |
liveuser |
18006 |
}#if end
|
| 226 |
liveuser |
18007 |
|
| 3 |
liveuser |
18008 |
}#if end
|
| 226 |
liveuser |
18009 |
|
| 220 |
liveuser |
18010 |
#反之如果有設置 replaceSpecifyLine
|
|
|
18011 |
else if(isset($conf["replaceSpecifyLine"])){
|
| 226 |
liveuser |
18012 |
|
| 220 |
liveuser |
18013 |
#讀取原始檔案內容
|
|
|
18014 |
#函式說明:
|
|
|
18015 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
18016 |
#回傳的變數說明:
|
|
|
18017 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
|
|
|
18018 |
#$result["error"],錯誤訊息提示.
|
|
|
18019 |
#$result["warning"],警告訊息.
|
|
|
18020 |
#$result["function"],當前執行的函數名稱.
|
|
|
18021 |
#$result["fileContent"],爲檔案的內容陣列.
|
|
|
18022 |
#$result["lineCount"],爲檔案內容總共的行數.
|
|
|
18023 |
#$result["fullContent"],為檔案的完整內容.
|
|
|
18024 |
#$result["base64dataOnly"],檔案的base64data.
|
|
|
18025 |
#$result["base64data"],為在網頁上給予src參數的數值.
|
|
|
18026 |
#$result["mimeType"],為檔案的mime type.
|
|
|
18027 |
#必填參數:
|
|
|
18028 |
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
|
|
|
18029 |
$conf["fileAcceess::getFileContent"]["filePositionAndName"]=$conf["file"];
|
|
|
18030 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
18031 |
$conf["fileAcceess::getFileContent"]["fileArgu"]=__FILE__;
|
|
|
18032 |
#可省略參數:
|
|
|
18033 |
#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
|
|
|
18034 |
#$conf["web"]="true";
|
|
|
18035 |
#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
|
|
|
18036 |
#$conf["createIfnotExist"]="false";
|
|
|
18037 |
#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
|
|
|
18038 |
#$conf["autoDeleteSpaceOnEachLineStart"]="false";
|
|
|
18039 |
#參考資料:
|
|
|
18040 |
#file(),取得檔案內容的行數.
|
|
|
18041 |
#file=>http:#php.net/manual/en/function.file.php
|
|
|
18042 |
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
|
|
|
18043 |
#filesize=>http://php.net/manual/en/function.filesize.php
|
|
|
18044 |
#參考資料:
|
|
|
18045 |
#無.
|
|
|
18046 |
#備註:
|
|
|
18047 |
#無.
|
|
|
18048 |
$getFileContent=fileAccess::getFileContent($conf["fileAcceess::getFileContent"]);
|
|
|
18049 |
unset($conf["fileAcceess::getFileContent"]);
|
| 226 |
liveuser |
18050 |
|
| 220 |
liveuser |
18051 |
#如果執行失敗
|
|
|
18052 |
if($getFileContent["status"]==="false"){
|
| 226 |
liveuser |
18053 |
|
| 220 |
liveuser |
18054 |
#設置執行失敗
|
|
|
18055 |
$result["status"]="false";
|
| 226 |
liveuser |
18056 |
|
| 220 |
liveuser |
18057 |
#設置執行失敗訊息
|
|
|
18058 |
$result["error"]=$getFileContent;
|
| 226 |
liveuser |
18059 |
|
| 220 |
liveuser |
18060 |
#回傳結果
|
|
|
18061 |
return $result;
|
| 226 |
liveuser |
18062 |
|
| 220 |
liveuser |
18063 |
}#if end
|
| 226 |
liveuser |
18064 |
|
| 220 |
liveuser |
18065 |
#針對每個要更新的行
|
|
|
18066 |
foreach($conf["replaceSpecifyLine"] as $lineIndex => $newLineContent){
|
| 226 |
liveuser |
18067 |
|
| 220 |
liveuser |
18068 |
#設置更新的資訊
|
|
|
18069 |
$result["content"][$lineIndex]=array("ori"=>$getFileContent["fileContent"][$lineIndex],"new"=>$newLineContent);
|
| 226 |
liveuser |
18070 |
|
| 220 |
liveuser |
18071 |
#更新行內容
|
|
|
18072 |
$getFileContent["fileContent"][$lineIndex]=$newLineContent;
|
| 226 |
liveuser |
18073 |
|
| 220 |
liveuser |
18074 |
}#foreach end
|
| 226 |
liveuser |
18075 |
|
| 220 |
liveuser |
18076 |
#debug
|
|
|
18077 |
#var_dump(__FILE__,__LINE__,count($getFileContent["fileContent"]));
|
| 226 |
liveuser |
18078 |
|
| 220 |
liveuser |
18079 |
#將變更寫入到檔案裡面
|
|
|
18080 |
#函式說明:
|
|
|
18081 |
#將多行字串寫入到檔案
|
|
|
18082 |
#回傳結果:
|
|
|
18083 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
18084 |
#$result["error"],錯誤訊息陣列.
|
|
|
18085 |
#$result["function"],當前執行函數的名稱.
|
|
|
18086 |
#必填參數:
|
|
|
18087 |
#$conf["fileName"],字串,爲要編輯的檔案名稱
|
|
|
18088 |
$conf["fileAccess::writeMultiLine"]["fileName"]=$file2write;
|
|
|
18089 |
#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
|
|
|
18090 |
$conf["fileAccess::writeMultiLine"]["inputString"]=$getFileContent["fileContent"];
|
|
|
18091 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
18092 |
$conf["fileAccess::writeMultiLine"]["fileArgu"]=__FILE__;
|
|
|
18093 |
#可省略參數:
|
|
|
18094 |
$conf["fileAccess::writeMultiLine"]["writeMethod"]="w";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
|
|
|
18095 |
#$conf["fastWrite"],字串,“true”代表要一次寫入多行內容;預設為"false"代表一次寫入一行,比較安全,但行數一多會需要等待多時.
|
|
|
18096 |
$conf["fileAccess::writeMultiLine"]["fastWrite"]="true";
|
|
|
18097 |
#參考資料:
|
|
|
18098 |
#無.
|
|
|
18099 |
#備註:
|
|
|
18100 |
#無.
|
|
|
18101 |
$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
|
|
|
18102 |
unset($conf["fileAccess::writeMultiLine"]);
|
| 226 |
liveuser |
18103 |
|
| 220 |
liveuser |
18104 |
#如果執行失敗
|
|
|
18105 |
if($writeMultiLine["status"]==="false"){
|
| 226 |
liveuser |
18106 |
|
| 220 |
liveuser |
18107 |
#設置執行失敗
|
|
|
18108 |
$result["status"]="false";
|
| 226 |
liveuser |
18109 |
|
| 220 |
liveuser |
18110 |
#設置執行失敗訊息
|
|
|
18111 |
$result["error"]=$writeMultiLine;
|
| 226 |
liveuser |
18112 |
|
| 220 |
liveuser |
18113 |
#回傳結果
|
|
|
18114 |
return $result;
|
| 226 |
liveuser |
18115 |
|
| 220 |
liveuser |
18116 |
}#if end
|
| 226 |
liveuser |
18117 |
|
| 220 |
liveuser |
18118 |
#debug
|
|
|
18119 |
#var_dump(__FILE__,__LINE__,$writeMultiLine);exit(1);
|
| 226 |
liveuser |
18120 |
|
| 220 |
liveuser |
18121 |
}#if end
|
| 226 |
liveuser |
18122 |
|
| 3 |
liveuser |
18123 |
#設置執行正常
|
|
|
18124 |
$result["status"]="true";
|
| 226 |
liveuser |
18125 |
|
| 3 |
liveuser |
18126 |
#回傳結果
|
|
|
18127 |
return $result;
|
| 226 |
liveuser |
18128 |
|
| 3 |
liveuser |
18129 |
}#function updateFile end
|
| 226 |
liveuser |
18130 |
|
| 3 |
liveuser |
18131 |
/*
|
|
|
18132 |
#函式說明:
|
|
|
18133 |
#輔助使用PHP內建的chmod函式.
|
|
|
18134 |
#回傳結果:
|
|
|
18135 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
18136 |
#$result["error"],錯誤訊息.
|
|
|
18137 |
#$result["function"],當前執行的函式名稱.
|
|
|
18138 |
#$result["argu"],使用的參數.
|
|
|
18139 |
#$result["cmd"],執行的指令.
|
|
|
18140 |
#$result["content"],執行的結果陣列,如果參數 "recursive" 跟 "excludeSelf" 都有設定的話,就會回傳該結果.
|
|
|
18141 |
#必填參數:
|
|
|
18142 |
#$conf["mode"],字串,要變成什麼權限.
|
|
|
18143 |
$conf["mode"]="";
|
|
|
18144 |
#$conf["target"],字串,需要變更權限的目標.
|
|
|
18145 |
$conf["target"]="";
|
|
|
18146 |
#可省略參數:
|
|
|
18147 |
#無.
|
|
|
18148 |
#參考資料:
|
|
|
18149 |
#無.
|
|
|
18150 |
#備註:
|
|
|
18151 |
#無.
|
|
|
18152 |
*/
|
|
|
18153 |
public static function chmod(&$conf){
|
| 226 |
liveuser |
18154 |
|
| 3 |
liveuser |
18155 |
#初始化要回傳的結果
|
|
|
18156 |
$result=array();
|
|
|
18157 |
|
|
|
18158 |
#取得當前執行的函數名稱
|
|
|
18159 |
$result["function"]=__FUNCTION__;
|
|
|
18160 |
|
|
|
18161 |
#如果沒有參數
|
|
|
18162 |
if(func_num_args()==0){
|
|
|
18163 |
|
|
|
18164 |
#設置執行失敗
|
|
|
18165 |
$result["status"]="false";
|
|
|
18166 |
|
|
|
18167 |
#設置執行錯誤訊息
|
|
|
18168 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
18169 |
|
|
|
18170 |
#回傳結果
|
|
|
18171 |
return $result;
|
|
|
18172 |
|
|
|
18173 |
}#if end
|
|
|
18174 |
|
|
|
18175 |
#取得參數
|
|
|
18176 |
$result["argu"]=$conf;
|
|
|
18177 |
|
|
|
18178 |
#如果 $conf 不為陣列
|
|
|
18179 |
if(gettype($conf)!=="array"){
|
|
|
18180 |
|
|
|
18181 |
#設置執行失敗
|
|
|
18182 |
$result["status"]="false";
|
|
|
18183 |
|
|
|
18184 |
#設置執行錯誤訊息
|
|
|
18185 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
18186 |
|
|
|
18187 |
#如果傳入的參數為 null
|
|
|
18188 |
if(is_null($conf)){
|
|
|
18189 |
|
|
|
18190 |
#設置執行錯誤訊息
|
|
|
18191 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
18192 |
|
|
|
18193 |
}#if end
|
|
|
18194 |
|
|
|
18195 |
#回傳結果
|
|
|
18196 |
return $result;
|
|
|
18197 |
|
|
|
18198 |
}#if end
|
| 226 |
liveuser |
18199 |
|
| 3 |
liveuser |
18200 |
#函式說明:
|
|
|
18201 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
18202 |
#回傳結果:
|
|
|
18203 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
18204 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
18205 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
18206 |
#$result["function"],當前執行的函式名稱.
|
|
|
18207 |
#$result["argu"],設置給予的參數.
|
|
|
18208 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
18209 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
18210 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
18211 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
18212 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
18213 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
18214 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
18215 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
18216 |
#必填參數:
|
|
|
18217 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
18218 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
18219 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
18220 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
18221 |
#可省略參數:
|
|
|
18222 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
18223 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("mode","target");
|
|
|
18224 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
18225 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
18226 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
18227 |
#$conf["canBeEmptyString"]="false";
|
|
|
18228 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
18229 |
#$conf["canNotBeEmpty"]=array();
|
|
|
18230 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
18231 |
#$conf["canBeEmpty"]=array();
|
|
|
18232 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
18233 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
18234 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
18235 |
#$conf["skipableVariableName"]=array();
|
|
|
18236 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
18237 |
#$conf["skipableVariableType"]=array();
|
|
|
18238 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
18239 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
18240 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
18241 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
18242 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
18243 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
18244 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
18245 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
18246 |
#參考資料:
|
|
|
18247 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
18248 |
#備註:
|
|
|
18249 |
#無.
|
|
|
18250 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
18251 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
18252 |
|
| 3 |
liveuser |
18253 |
#如果檢查參數失敗
|
|
|
18254 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
18255 |
|
| 3 |
liveuser |
18256 |
#設置執行失敗
|
|
|
18257 |
$result["status"]="false";
|
|
|
18258 |
|
|
|
18259 |
#設置錯誤資訊
|
|
|
18260 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
18261 |
|
| 3 |
liveuser |
18262 |
#回傳結果
|
|
|
18263 |
return $result;
|
| 226 |
liveuser |
18264 |
|
| 3 |
liveuser |
18265 |
}#if end
|
| 226 |
liveuser |
18266 |
|
| 3 |
liveuser |
18267 |
#如果檢查參數不通過
|
|
|
18268 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
18269 |
|
| 3 |
liveuser |
18270 |
#設置執行失敗
|
|
|
18271 |
$result["status"]="false";
|
|
|
18272 |
|
|
|
18273 |
#設置錯誤資訊
|
|
|
18274 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
18275 |
|
| 3 |
liveuser |
18276 |
#回傳結果
|
|
|
18277 |
return $result;
|
| 226 |
liveuser |
18278 |
|
| 3 |
liveuser |
18279 |
}#if end
|
| 226 |
liveuser |
18280 |
|
| 3 |
liveuser |
18281 |
#將$conf["mode"]轉換為10進位的整數
|
|
|
18282 |
$conf["mode"]=(int)base_convert($conf["mode"],8,10);
|
| 226 |
liveuser |
18283 |
|
| 3 |
liveuser |
18284 |
#變更 target 的檔案權限為代碼
|
| 226 |
liveuser |
18285 |
$chmod=chmod($conf["target"],$conf["mode"]);
|
|
|
18286 |
|
| 3 |
liveuser |
18287 |
#如果改變檔案權限失敗
|
|
|
18288 |
if($chmod===false){
|
| 226 |
liveuser |
18289 |
|
| 3 |
liveuser |
18290 |
#設置執行失敗
|
|
|
18291 |
$result["status"]="false";
|
| 226 |
liveuser |
18292 |
|
| 3 |
liveuser |
18293 |
#設置錯誤訊息
|
|
|
18294 |
$result["error"][]="改變 ".$conf["target"]." 檔案的權限資訊為 ".$conf["mode"]." 失敗,通常只有系統帳戶才能變更之.";
|
| 226 |
liveuser |
18295 |
|
| 3 |
liveuser |
18296 |
#回傳結果
|
| 226 |
liveuser |
18297 |
return $result;
|
|
|
18298 |
|
| 3 |
liveuser |
18299 |
}#if end
|
| 226 |
liveuser |
18300 |
|
| 3 |
liveuser |
18301 |
#設置執行正常
|
|
|
18302 |
$result["status"]="true";
|
| 226 |
liveuser |
18303 |
|
| 3 |
liveuser |
18304 |
#回傳結果
|
|
|
18305 |
return $result;
|
| 226 |
liveuser |
18306 |
|
| 3 |
liveuser |
18307 |
}#function chmod end
|
|
|
18308 |
|
|
|
18309 |
}#class fileAccess end
|
|
|
18310 |
|
| 226 |
liveuser |
18311 |
?>
|