Skip to content

Instantly share code, notes, and snippets.

@fu-sen fu-sen/upload.php
Last active May 23, 2020

Embed
What would you like to do?
MixJuice より送った IchigoJam プログラムをファイル保存 | MixJuice / IchigoJam BASIC 1.1.1+ https://15jamrecipe.jimdofree.com/mixjuice/%E3%82%B3%E3%83%B3%E3%83%86%E3%83%B3%E3%83%84%E3%81%AE%E4%BD%9C%E6%88%90%E3%81%A8%E5%85%AC%E9%96%8B/
<?php
/*
MixJuice Program Upload Sample | MixJuice / IchigoJam BASIC 1.1.1-
Copyright (c) 2016-2020 Keiichi SHIGA (BALLOON a.k.a. Fu-sen.)
The MIT License (MIT) - https://gist.github.com/fu-sen/e101bdcb80eead4ab85eea89c74a6965
Display of how to use:
?"MJ GET <server.name>/upload.php
Upload program (MixJuice):
?"MJ POST START <server.name>/upload.php":LIST:?"MJ POST END
Upload program (MicJack):
?"MJ POST START <server.name>/upload.php":LIST:?"MJ POST END":?"MJ GET <server.name>/last
Get the program:
?"MJ GET <server.name>/<file name>
*/
date_default_timezone_set('Asia/Tokyo');
$url = "EXAMPLE.NET.EU.ORG";
$ua = $_SERVER['HTTP_USER_AGENT'];
if (strpos($ua, 'MixJuice') === false)
{
print <<<EOT
<html>
<body>
what?
</body>
</html>
EOT;
exit;
}
if (strpos($ua, 'MicJack') === false)
{
$command = <<<EOT
'?"MJ POST START {$url}/upload.php":LIST:?"MJ POST END
EOT;
}
else
{
$command = <<<EOT
'?"MJ POST START {$url}/upload.php":LIST:?"MJ POST END":?"MJ GET {$url}/last
EOT;
}
// Output of the GET method
if ( $_SERVER["REQUEST_METHOD"] != "POST" )
{
print <<<EOT
'Use the command:
{$command}
EOT;
exit;
}
$program = file_get_contents('php://input');
$filename = date("YmdHis");
$uploadfile = __DIR__ . "/" . $filename;
$lastfile = __DIR__ . "/last";
if ( is_file ( $upload ) )
{
print <<<EOT
'File Write Error
'Run the command again.
{$command}
EOT;
exit;
}
$header = <<<EOT
CLS
NEW
EOT;
file_put_contents($uploadfile, $header, FILE_APPEND | LOCK_EX);
file_put_contents($uploadfile, $program, FILE_APPEND | LOCK_EX);
$footer = <<<EOT
'OK
EOT;
file_put_contents($uploadfile, $footer, FILE_APPEND | LOCK_EX);
$last = <<<EOT
'Last generated file is
'?"MJ GET {$url}/{$filename}
EOT;
file_put_contents($lastfile, $last);
print <<<EOT
'Program file was generated.
'?"MJ GET {$url}/{$filename}
EOT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.