<?php
/*
* Easy Python Launcher
*
* Programmed by Chun Kang (2021-08-03) for Johnny Kang
*
**/
extract( $_POST);
extract( $_GET);
extract( $_COOKIE);
extract( $_SERVER);
function findfiles( $path, $regexp="", $order=0)
{
$r = scandir( $path, $order); // $order: 0->ascending / 1->descending
if ($r==false) $ret=$r;
else
{
$ret=array();
$i=count($r)-1;
for($i=0; $i<count($r); $i++)
{
if (
(($regexp=="") || preg_match('/' . $regexp . '/', $r[$i]))
&& strlen($r[$i])
&& $r[$i]!='.'
&& $r[$i]!='..'
) $ret[]=$r[$i];
}
}
return $ret;
}
if (strlen($p))
{
header("Content-Type: text/html; charset=UTF-8");
if (preg_match("/\.py$/", $p))
{
echo shell_exec("python {$p}");
}
else
{
echo shell_exec("python {$p}.py");
}
}
else
{
$code_list = findfiles( ".", ".py");
if (@count($code_list))
{
echo "Your codes available<br>";
echo "<hr>";
foreach($code_list as $filename)
{
echo "<a href=\"?p=" . urlencode($filename) . "\">{$filename}</a><br>";
}
}
else
{
echo "You can run your code like below:<br><br>";
echo "http://{$_SERVER['SERVER_NAME']}{$PHP_SELF}?p=[your_python_filename]";
}
}
?> |