-1

I have prepared this php webservice

<?php
$user_name = "root";
$user_pass = "";
$host_name = "localhost";
$db_name = "dbupload";

$con = mysqli_connect($host_name,$user_name,$user_pass,$db_name);

if ($con) {
  $image = $_POST["image"];
  $name = $_POST["name"];
  $sql = "insert into imageinfo(name) values ('$name')";
  $upload_path = "B:/Smart_Music/Emotion_Model/images/$name.jpg";

  if (mysqli_query($con,$sql)) {
    file_put_contents($upload_path,base64_decode($image));
    $reponse=array();
        $reponse["response"]="Image Uploaded Successfully";
        echo json_encode($reponse);
  }  
  else {
    $reponse=array();
   $reponse["response"]="Failure";
   echo json_encode($reponse);
  }
}
else {
  $reponse=array();
 $reponse["response"]="Failure";
 echo json_encode($reponse);
}
mysqli_close($con);

?>

What I want to achieve is to execute automaticlly some windows commands after sending the response.

this is the commands :

cd /d B:\Smart_Music\Emotion_Model\src
activate Emotion
python image_emotion_demo.py ../images/Selected_Photo.jpg
1
  • Have you looked at the php exec(), passthru() and system() functions? It sounds like what you are looking for. A word of caution - sending user input to these commands can be very dangerous. May 26, 2020 at 14:07

1 Answer 1

0

You can use exec or shell_exec

<?php 

// Use ls command to shell_exec 
// function 
$output = shell_exec('ls'); 

// Display the list of all file 
// and directory 
echo "<pre>$output</pre>"; 
?> 

Output will be for me

gfg.php
index.html
geeks.php

Be sure if its not a local machine this functions is not disabled for security reasons

2
  • I want to use that in my local machine May 26, 2020 at 16:06
  • okey its not problem now you can just use the shell_exec and you will be good May 26, 2020 at 22:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.