0

当 url .../print.php 加载时,我希望打印上传到目标目录的最新文件的名称,并将同一文件同时发送到连接到服务器的打印机。有了这里的代码,只有当 shell_exec(lsp /file/path) 直接引用文件时,我才能做我想做的一切。

我设置了一个函数来确定上传的最新文件以及文件路径,但我想做一些类似 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";

?>

我在网上看到了很多关于如何完成这项工作的不同建议,但他们都指定了一个略有不同的过程,而且没有一个对我有用。有人可以帮忙吗?

4

0 回答 0