-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

5
  • So the script succeeds when you run it from CLI, and fails when you request it through a Web server, right? Commented Oct 22, 2016 at 7:02
  • yup it succeed in the terminal CLI but failed in the xampp web sever Commented Oct 22, 2016 at 7:03
  • I'd have printed the command somewhere, then tried to run it from CLI Commented Oct 22, 2016 at 7:49
  • Just to make sure that the command actually works. If it works, then maybe you're seeing a cached variant on the web page. Commented Oct 22, 2016 at 7:55
  • I able to run in command but I need to work it on php script but I dont know why it cant works I have already follow the tutorial the same step but still cant works and no pdf is generated but it return successful that is the weirdest part Commented Oct 22, 2016 at 7:57

1 Answer 1

0

You need to escape the shell arguments, otherwise the shell may interpret its special characters:

$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));

Provide full (absolute) path to your unoconv/0.7/bin/unoconv executable, as it seems unavailable from your $PATH environment variable:

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

Alternatively, include the absolute path to unoconv/0.7/bin/ directory into the $PATH environment variable before calling the shell. Refer to this post, for instance.

Obviously, the $source_file should be in the current directory. Otherwise, the command will fail to access it.

Sign up to request clarification or add additional context in comments.

3 Comments

Erm how do I do that? Is it called the terminal and put in it?
/Applications/XAMPP/xamppfiles/htdocs/phpdocx/unoconv/0.7/bin/unoconv you mean like this the real path?
it is still the same it give me this usage: unoconv [options] file [file2 ..] Convert from and to any format supported by LibreOffice unoconv options: -c, --connection=string use a custom connection string -d, --doctype=type specify document type (document, graphics, presentation, spreadsheet) -e, --export=name=value set export filter options eg. -e PageRange=1-2 -f, --format=format specify the output format -F, --field=name=value replace user-defined text field with value eg. -F Client_Name="Oracle" -i, --import=string set import filter option string eg. -i utf8 -l but it said successful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.