I am calling a PHP script from JavaScript. Whenever my function is called, I want to set tag=image
. How can I do that?
function httpGetAsync(theUrl, callback) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
callback(xmlHttp.responseText);
}
}
xmlHttp.open("POST", theUrl, true);
xmlHttp.send(null);
}
httpGetAsync('storeImage.php');
The file storeImage.php looks like
<?php
$img = $_POST['tag'];
$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 = 't' . '.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);
echo $output;
?>