php使用linux命令判断文件是否存在
Linux一句命令之判断文件是否存在
[ -f qipa250.txt ] && echo yes || echo no
-f 文件名字文件存在则为真。
执行[ -f qipa250.txt ]为真则执行echo yes,由于或语句||的存在echo no不再执行。
特别注意的是,这里的逻辑与和逻辑或值得仔细思考。
php调用linux命令方法
//指定文件路径
$pdf_file_url='/data/web/QipaFile/qipa250.pdf';
//命令
$pdf_file_exists = '[ -f ' . $pdf_file_url . ' ] && echo true || echo false';
//执行
echo $pdf_file_exists_result = system($pdf_file_exists);
得到true或false