-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

user3711175
  • 109
  • 2
  • 16
  • So the script succeeds when you run it from CLI, and fails when you request it through a Web server, right? – Ruslan Osmanov Oct 22 '16 at 07:02
  • yup it succeed in the terminal CLI but failed in the xampp web sever – user3711175 Oct 22 '16 at 07:03
  • I'd have printed the command somewhere, then tried to run it from CLI – Ruslan Osmanov Oct 22 '16 at 07: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. – Ruslan Osmanov Oct 22 '16 at 07: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 – user3711175 Oct 22 '16 at 07:57

1 Answers1

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.

Community
  • 1
  • 1
Ruslan Osmanov
  • 20,486
  • 7
  • 46
  • 60
  • Erm how do I do that? Is it called the terminal and put in it? – user3711175 Oct 22 '16 at 07:12
  • /Applications/XAMPP/xamppfiles/htdocs/phpdocx/unoconv/0.7/bin/unoconv you mean like this the real path? – user3711175 Oct 22 '16 at 07:16
  • 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 – user3711175 Oct 22 '16 at 07:19