From cf6306aff5fe5a99ad3f6cf59237a2fdd4cd46df Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Thu, 28 Dec 2023 18:40:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=85=E5=9C=A8=E5=BC=82=E5=B8=B8=E6=97=B6?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/public/convert.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/web/public/convert.php b/web/public/convert.php index 44dbbdd0..8f83b134 100644 --- a/web/public/convert.php +++ b/web/public/convert.php @@ -7,17 +7,23 @@ define('ROOT_PATH', dirname(__DIR__, 2)); $id = date('Ymd_H_') . uniqid(); -$file = ROOT_PATH . '/logs/' . $id . '.py'; -$out_file = ROOT_PATH . '/logs/' . $id . '.php'; +$py_file = ROOT_PATH . '/logs/' . $id . '.py'; +$php_file = ROOT_PATH . '/logs/' . $id . '.php'; -file_put_contents($file, $_POST['code']); +file_put_contents($py_file, $_POST['code']); $conv = ROOT_PATH . '/conv.php'; -$cmd = 'php ' . $conv . ' ' . $file; -$out = shell_exec($cmd); +$cmd = 'php ' . $conv . ' ' . $py_file; +$code = shell_exec($cmd); echo json_encode([ - 'data' => ['code' => $out,] + 'data' => ['code' => $code,] ]); -file_put_contents($out_file, $out); +file_put_contents($php_file, $code); + +// 运行正常,删除历史文件 +if (str_starts_with($code, '