On Tue, 21 Mar 2017, Sven Axelsson wrote:

Here's a simple solution in PHP to upload a Lilypond file to lilybin
and download the result after execution.

I am getting this error message:

        PHP Warning:  getopt() expects at most 2 parameters, 3 given in lilybin 
on line 14


I really appreciate your efforts. I feel I'm almost getting what I'm seaching for. Almost.

bash, python, php - I'm trying different roads. Good learning experience, and I might end up with something I could actually use :-)

Martin


--->>> snip lilybin <<<---
#!/usr/bin/env php
<?php
function do_curl($url, $opts)
{
   $curl = curl_init($url);
   curl_setopt_array($curl, $opts);
   $result = curl_exec($curl);
   curl_close($curl);

   return $result;
}

$optind = 0;
$opts = getopt('d', $argv, $optind);
$files = array_slice($argv, $optind);
if (count($files) !== 1) {
   die("Usage: lilybin [-d] file\n");
}

if (isset($opts['d'])) {
   $url = 'https://s3-us-west-2.amazonaws.com/lilybin-scores/' . $files[0];
   $file = fopen($files[0], 'w');
   do_curl($url, array(CURLOPT_FILE => $file));
   fclose($file);
} else {
   $url = 
'https://7icpm9qr6a.execute-api.us-west-2.amazonaws.com/prod/prepare_preview/stable';
   $result = json_decode(do_curl($url, array(
       CURLOPT_HTTPHEADER => array('Content-Type: application/json'),
       CURLOPT_POST => 1,
       CURLOPT_POSTFIELDS => json_encode(array('code' =>
file_get_contents($files[0]))),
       CURLOPT_RETURNTRANSFER => true,
   )));
   if (!$result->id) {
       echo "ERROR:\n{$result->stderr}";
       exit(1);
   } else {
       echo $argv[0], ' -d ', $result->id, ".pdf\n";
   }
}
--->>> end snip lilybin <<<---

--
Sven Axelsson
++++++++++[>++++++++++>+++++++++++>++++++++++>++++++
++++<<<<<-]>++++.+.++++.>+++++.>+.<<-.>>+.>++++.<<.
+++.>-.<<++.>>----.<++.>>>++++++.<<<<.>>++++.<----.


_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to