-1

When I run this phpscript in my mac xampp it return successful but not pdf file is generated. But when I run from mac terminal it able to create the pdf file from the docx file.

 <?php
    $source_file = 'c++ documentation.docx';
    $cmd = "unoconv/0.7/bin/unoconv";
    $command = sprintf("/Applications/XAMPP/xamppfiles/htdocs/phpdocx/unoconv/0.7/bin/unoconv -h -v -f pdf -o /phpdocx/docimages/testing.pdf %s 2>&1",
  escapeshellarg($source_file));
    echo shell_exec($command);

    echo "yoyo";

    if(shell_exec($command)){
        echo "successful";
    }else{
        echo "failed";
    }
?>

This is my edited code and it said sprintf(): Too few argument!

This is the part where it give this message but it said successful and not pdf files were found

4

1 に答える 1

0

シェル引数をエスケープする必要があります。エスケープしないと、シェルが特殊文字を解釈する可能性があります。

$source_file = 'c++ documentation.docx';
$command = sprintf("unoconv/0.7/bin/unoconv -h -v -f pdf -o /phpdocx/docimages/testing.pdf %s 2>&1",
  escapeshellarg($source_file));

環境変数unoconv/0.7/bin/unoconvからは利用できないように見えるため、実行可能ファイルへのフル (絶対) パスを指定します。$PATH

$command = sprintf("/path/to/unoconv/0.7/bin/unoconv -h -v -f pdf -o /phpdocx/docimages/testing.pdf %s 2>&1",
  escapeshellarg($source_file));

または、シェルを呼び出す前unoconv/0.7/bin/に、ディレクトリへの絶対パスを環境変数に含めます。たとえば、この$PATH投稿を参照してください。

明らかに$source_file、現在のディレクトリにある必要があります。そうしないと、コマンドはアクセスに失敗します。

于 2016-10-22T07:10:30.533 に答える