开发者

How to use relative paths in exec command?

开发者 https://www.devze.com 2022-12-10 01:41 出处:网络
How to run external program from PHP with exec command using relative paths? <?php exec(\'program_name ......\');

How to run external program from PHP with exec command using relative paths?

 <?php

  exec('program_name ......');

 ?>

This works only if program_name.exe is in the same directory as the PHP script. For example exec('something/program_name ......'); doesn't work if php script is 开发者_高级运维not in the 'something' directory.


You can use realpath to turn relative path into an absolute one before calling exec()

$rel = 'something/program_name';
$abs = realpath($rel);
exec($abs);


Make it absolute, relative paths are evil.

exec(dirname(__FILE__) . 'program_name ......');
0

精彩评论

暂无评论...
验证码 换一张
取 消