【发布时间】:2019-11-21 21:23:21
【问题描述】:
我在 php 中有一个函数。我想在 javascript 函数中调用它。怎么做? 我的php函数是
<?php
function image_save(){
$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);
}
?>
【问题讨论】:
-
本质上你不能在 javascript 函数中调用 php 函数。如果您使用ajax发出请求并使用回调来处理您的PHP函数的响应,则可以调用php函数
-
要么提交表单,要么使用 ajax
标签: javascript php