在HTML中編寫一些簡單的嵌入式PHP來執行python腳本,該腳本使用一些循環根據HTML表單中多個文件輸入的可能性多次運行腳本。它對單數運行正常,但就目前而言,在運行多個文件時似乎重複了一些,並且仔細檢查,似乎python腳本收到的變量第一次不正確。我不知道它爲什麼這樣做,它可能是非常明顯的。所有幫助讚賞。exec()和變量傳遞給Python腳本的問題
$len = count($_FILES["inputFile"]["name"]);
echo "length";
echo $len;
for($i = 0; $i < $len; $i++){
$dataIn = $_FILES["inputFile"]["tmp_name"][$i];
$originalName = $_FILES["inputFile"]["name"][$i];
echo "TMP Name:";
echo $dataIn;
echo "OriginalName";
echo $originalName;
exec("python /home/will/public_html/OrderAnalyser.py '$dataIn' '$originalName' 2>&1",$output);
foreach ($output as $out){
echo $out;
echo "<br />";
}
}
輸出看起來是這樣的:
Executing...
length2TMP Name:/var/www/tmp/phpHzJFtQOriginalNamemicro_b001.jsonAnalysis Starting on file:
Input File: /var/www/tmp/phpHzJFtQ
Original Name: micro_b001.json
"nodeID":20,
firstNode:
20
Finished Finding Argument Order,
List is as follows:
['20', '21', '22', '23', '24']
Top Node is:
24
There is NO subargument of node:
24
Analysis Complete
TMP Name:/var/www/tmp/php9vQumSOriginalNamemicro_b002.jsonAnalysis Starting on file:
Input File: /var/www/tmp/phpHzJFtQ
Original Name: micro_b001.json
"nodeID":20,
firstNode:
20
Finished Finding Argument Order,
List is as follows:
['20', '21', '22', '23', '24']
Top Node is:
24
There is NO subargument of node:
24
Analysis Complete
Analysis Starting on file:
Input File: /var/www/tmp/php9vQumS
Original Name: micro_b002.json
"nodeID":20,
firstNode:
20
Finished Finding Argument Order,
List is as follows:
['20', '21', '22', '23', '24']
Top Node is:
22
20
is child of
22
21
is child of
22
Subargument of node:
22
is:
Post Order
There is NO subargument of node:
20
There is NO subargument of node:
21
Analysis Complete
Completed...
正如在這裏可以看到,一旦它與第一個文件(micro_b001.json),它應該移動到micro_b002完成。 PHP中的echo顯示PHP中的變量是正確的,但從python腳本中看到的打印顯示它正在使用來自初始(micro_b001)的變量再次運行。這是爲什麼發生?正如你所看到的,一旦它由於某種原因再次運行第一個,它會實際運行第二個,然後完成。爲什麼它做這個奇怪的重複?我無法弄清楚。
(另外,我意識到這是有漏洞的代碼,等等,它現在並不重要)
非常感謝你,我要把這一個嘗試儘快。道歉,我對PHP – SneakySpriggs
很缺乏經驗@SneakySpriggs不道歉,這只是PHP預期會做出最令人意想不到的事情。 –