escapeshellarg()只是用來轉義shell命令的部分參數

escapeshellarg()的說明是這裏php

原來覺得這個函數能夠用來把一整條shell命令轉義像這樣:html

$sh = 'mysql -uroot -proot -Dtest < /var/www/test.com/sql/user (1).sql';
shell_exec(escapeshellarg($sh));

 

一試就出錯了。。。。mysql

QQ截圖20160322215218

仔細看了下文檔才知道應該用來轉義部分參數sql

shell_exec('mysql -uroot -proot -Dtest < ' . escapeshellarg('/var/www/test.com/sql/user (1).sql'));

問我之前爲何沒出錯?由於我之前是改寫人家的代碼,而後文檔沒看仔細猜着是那麼個意思。。。shell

相關文章
相關標籤/搜索