[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: (fwd)
From: |
Sven Axelsson |
Subject: |
Re: (fwd) |
Date: |
Wed, 22 Mar 2017 11:20:02 +0100 |
On 22 March 2017 at 00:53, Martin Tarenskeen <address@hidden> wrote:
>
>
> 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.
Oops. That third argument was added in PHP 7.1. Here's a version that
should work with older versions too.
--->>> 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;
}
$opts = getopt('d', $argv);
$sep = array_search('--', $argv);
$files = array_slice($argv, $sep ? ++$sep : count($opts) + 1);
if (count($files) === 0 || count($files) > 2) {
die("Usage: lilybin [-d] file [file]\n");
}
if (isset($opts['d'])) {
$url = 'https://s3-us-west-2.amazonaws.com/lilybin-scores/' . $files[0];
$file = fopen(@$files[1] ?: $files[0], 'w');
do_curl($url, [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, [
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => json_encode(['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
++++++++++[>++++++++++>+++++++++++>++++++++++>++++++
>++++<<<<<-]>++++.+.++++.>+++++.>+.<<-.>>+.>++++.<<.
+++.>-.<<++.>>----.<++.>>>++++++.<<<<.>>++++.<----.
- Re: (fwd), Martin Tarenskeen, 2017/03/21
- Re: (fwd), Urs Liska, 2017/03/21
- Re: (fwd), Martin Tarenskeen, 2017/03/21
- Re: (fwd), Sven Axelsson, 2017/03/21
- Re: (fwd), Martin Tarenskeen, 2017/03/21
- Re: (fwd),
Sven Axelsson <=
- Message not available
- Re: (fwd), Sven Axelsson, 2017/03/22
- Re: (fwd), Martin Tarenskeen, 2017/03/22
- Re: (fwd), Sven Axelsson, 2017/03/22
- Message not available
- lilybin php script (was: Re: (fwd)), Martin Tarenskeen, 2017/03/23
- Re: lilybin php script (was: Re: (fwd)), Trevor, 2017/03/23
- Re: lilybin php script (was: Re: (fwd)), Martin Tarenskeen, 2017/03/23
- Re: lilybin php script (was: Re: (fwd)), Martin Tarenskeen, 2017/03/24
- Re: lilybin php script (was: Re: (fwd)), Martin Tarenskeen, 2017/03/27
Re: (fwd), Dmytro O. Redchuk, 2017/03/21