2014-04-03 34 views
0

這裏是我的腳本殼牌PHP命令和瀏覽器不返回相同的輸出

test.php的

function doc2text($filename){ 

    $name = pathinfo($filename,PATHINFO_FILENAME); 
    $count = exec('abiword --to=txt '.$filename.' && wc -w classes/'.$name.'.txt'); 
    $count = explode(" ",$count); 
    var_dump($count); 
    return $count[0]; 

} 

echo doc2text('classes/demo.pdf'); 

當我運行該腳本在命令行像這樣:

php test.php 

var_dump正常輸出:

array(2) { 
    [0]=> 
    string(4) "1663" 
    [1]=> 
    string(16) "classes/demo.txt" 
} 

但是,當我在我的瀏覽器上運行相同的頁面數組爲空:

array(1) { [0]=> string(0) "" } 

這真是奇怪......任何線索它爲什麼這樣做呢?

回答

0

abiword可能不在web服務器環境的路徑中。試試:/path/to/abiword。此外,$filename將需要位於正在運行的PHP腳本的目錄中,或者您需要指定路徑。

還可以使用錯誤報告:

error_reporting(E_ALL); 
ini_set('display_errors', '1'); 
+0

這是因爲從AbiWord的創建demo.txt文件 – Warface