I want to test 4 files in Linux server through PHP, and the display result should show in the text area. let me know whats the correct way to solve this.
Sh test_batch.sh
$ {dict_file} $ {locale} $ {keyboard_layout} $ {golden_test_file} $
{auto_correction_file} (optional)
if (isset($_POST['files'])) {
foreach ($_POST['files'] as $value) {
echo $dir . $value . '<br />';
$result = shell_exec('sudo sh test_batch.sh $dir .$value. ');
}
}else {
exit('No files selected');
}
}
?>
<br/>
<table>
<tr>
<td><b>Result to Display and Save:</b></td></tr>
<tr>
<td colspan="3">
<textarea disabled id="inputTextToSave" style="width:512px;height:256px" value = "'.$result.'"></textarea>`
First of all, you should refrain from ever using sudo in a web script to do anything. What if someone decided to feed your server the string "&& rm -rf /" in your $_POST and that got concatenated into your sudo sh test_batch.sh $dir .$value string? That would make for a very bad day.
Instead, consider implementing whatever test_batch.sh does into some kind of worker script that processes requests queued to it (you could do this in Perl, PHP, with Node.JS...there are a few ways.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.