placing PHP variable inside of shell_exec( ) to run lsp command

泪湿孤枕 提交于 2019-12-25 03:34:28

问题


When the url .../print.php loads, I want the name of the latest file uploaded to the target directory to be printed and for that same file to simultaneously be sent to the printer connected to the server. With this code here, I am able to do everything that I want ONLY when the shell_exec(lsp /file/path) refers directly to a file.

I have a function set up that determines the latest file uploaded and also the filepath, but I want to do something like shell_exec(lsp $filepath).

<?php
$path = "/var/www/html/work/uploads";

$latest_ctime = 0;
$latest_filename = '';
$output = shell_exec('lpr'.$filepath);

$d = dir($path);
while (false !== ($entry = $d->read())) {
  $filepath = "{$path}/{$entry}";
  if (is_file($filepath) && filectime($filepath) > $latest_ctime) {
    $latest_ctime = filectime($filepath);
    $latest_filename = $entry;
  }
}

echo "$output Printing: $latest_filename";

?>

I've seen many different suggestions online for how to make this work, but they were all specifying a slightly different process and none of them worked for me. Can anybody please help?

来源:https://stackoverflow.com/questions/29724718/placing-php-variable-inside-of-shell-exec-to-run-lsp-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!