2011-10-22 169 views
0

我有一臺運行ubuntu 10.10的linux服務器,在安裝了apache和php的maverick中,在/ var/www目錄中有一個下載目錄。我已經使用OSFile經理和修改,以包括一個函數來這裏分割文件是代碼:在Linux服務器上執行PHP exec split命令

function spl($fname){ 
global $folder; 
if (!$fname == ""){ 
    maintop("Split"); 
    $dirfile = $folder.$fname; 

    \\escape directory path 
    $dirfile = str_replace(" ","\ ",$dirfile); 
    $dirfile = str_replace("(","\(",$dirfile); 
    $dirfile = str_replace(")","\)",$dirfile); 
    $command = "split -d -b1024m ".$dirfile." ".$fname."_"; 
    echo "Command: ".$command; 
    echo"<br />"; 


    $returnval =0; 
    unset($output2); 
    $output = exec($command,$output2,$returnval); 

    //echo results 
    echo($output); 
    echo"<br />"; 
    print_r($output2); 
    echo"<br />"; 
    echo($returnval); 
    echo"<br />"; 
    mainbottom(); 
} 
    else 
    home(); 
} 

該命令不執行。文件和目錄是正確的,但它返回退出代碼1,並且Array()作爲輸出值,我創建了一個包含幾個用戶的組,我已經使該組成爲下載的所有者/並且讓它讀取寫入並執行權限,這個組包括www-data。

任何幫助將apreciated

+0

提示1:使用'addcslashes'或'escapeshellarg'。提示2:如果不捕獲任何錯誤消息,請查看'error.log'。 – mario

+0

error.log位於何處?我試過escapeshellarg,但它沒有對文件路徑做任何事情。 –

+0

這是一個網絡服務器文件。經常在文根上面。如果需要,Escapeshellarg可以在單引號和反斜線之間添加單引號。 – mario

回答

0

如果你沒有得到從EXEC和任何錯誤信息error.log保持爲空,然後使用此包裝器執行:

exec("sh -c \" $cmd 2>&1 \""); 

2>&1stderr通道重定向到stdout,以便它顯示在結果數組中。
In the shell, what does " 2>&1 " mean?

另一種選擇是proc_open在那裏你可以分別讀取每個通道,但更多的工作來設置。

0

試試這個文件分割類

Split and merge files

或本使用EXEC Split big files using PHP using exec

+0

嗨,我正在尋找你已經鏈接的類,會讓你知道它是否有效。我是在這個問題上,我正確執行命令(我已經測試了它的外殼),但它不工作k通過PHP –