Why can't one of my PHP exec() commands open a file?
In my PHP script, there are three exec() commands, all of which can open files located in $_SERVER['DOCUMENT_ROOT']. Two of the commands can also open files in the sub-directories (all directories and files have the same permissions), but one of the commands (case "3") cannot. I tested the 3 commands in terminal as the same Apache user, in the same sub-directories, and they all worked. I also tested the script in the PHP CLI and they worked there as well. Here is a snippet of the code:
switch($_POST['Convert'])
{
case "1":
$FileNameConvert .= ".pdf";
$command = "convert '{$FileName}' '{$FileNameConvert}'";
break;
case "2":
$FileNameConvert .= ".html";
$command = "pdftohtml '{$FileName}' '{$FileNameConvert}'";
break;
case "3":
$FileNameConvert = "RotatedPDF.pdf";
$command = "pdftk '{$FileName}' cat 1-endsouth output '{$FileNameConvert}'";
break;
default:
echo "error";
exit();
}
echo exec($command,$op,$result);
Apache's error log shows:
I/O Error: Couldn't open file '$FileName': No such file or directory.
Error: Unable to find file.
Error: Failed to open PDF file:
$FileName
Why does the following command not work?
$command = "pdftk '{$FileName}' cat 1-endsouth output '{$FileNameConvert}'";