HTML form should be like the blow if your form and PHP code are on the same page.
<form action="" method="POST">
#Updading based on comment
<button type="submit" class="">Submit</button>
</form>
Remove the function fun(){}
Add the following :
if(isset($_POST)){
$img = $_POST['image'];
$folderPath = "C:/xampp/htdocs/";
$image_parts = explode(";base64,", $img);
$image_type_aux = explode("image/", $image_parts[0]);
$image_type = $image_type_aux[1];
$image_base64 = base64_decode($image_parts[1]);
$fileName = '1'. '.jpeg';
$file = $folderPath . $fileName;
file_put_contents($file, $image_base64);
print_r($fileName);
$command = escapeshellcmd("python C:/xampp/htdocs/generate_graph.py");
$output = shell_exec($command);
}
Since your action is empty then it will hit the current page and if
condition will work because of form submitting as POST
method.
Hope it will help.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…