텍스트 파일이 아닌 pdftotext의 결과를 PHP 변수로 가져옵니다.
-
07-07-2019 - |
문제
pdftotext는 pdf 파일을 가져 와서 텍스트를 .txt 파일로 변환합니다.
pdftotext가 텍스트 파일 대신 PHP 변수로 결과를 보내려면 어떻게해야합니까?
나는 내가 달려야한다고 가정합니다 exec('pdftotext /path/file.pdf')
,하지만 결과를 어떻게 되 찾을 수 있습니까?
해결책
stdout/stderr를 캡처해야합니다.
function cmd_exec($cmd, &$stdout, &$stderr)
{
$outfile = tempnam(".", "cmd");
$errfile = tempnam(".", "cmd");
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("file", $outfile, "w"),
2 => array("file", $errfile, "w")
);
$proc = proc_open($cmd, $descriptorspec, $pipes);
if (!is_resource($proc)) return 255;
fclose($pipes[0]); //Don't really want to give any input
$exit = proc_close($proc);
$stdout = file($outfile);
$stderr = file($errfile);
unlink($outfile);
unlink($errfile);
return $exit;
}
다른 팁
$result = shell_exec("pdftotext file.pdf -");
그만큼 -
pdftotext는 결과를 파일 대신 stdout에 반환하도록 지시합니다.
제휴하지 않습니다 StackOverflow