I am working on a php code as shown below in which I am converting mp4 files into mp3 using system command ffmpeg.
<?php
$mp4_files = preg_grep('~\.(mp4)$~', scandir($src_dir));
if (isset($_GET['go'])) {
foreach ($mp4_files as $f) // Line#A
{
$parts = pathinfo($f);
switch ($parts['extension'])
{
case 'mp4' :
$filePath = $src_dir . DS . $f;
system('ffmpeg -i ' . $filePath . ' -map 0:2 -ac 1 ' . $destination_dir . DS . $parts['filename'] . '.mp3', $result); // Through this command conversion happens.
}
}
}
?>
Once the conversion is complete, I am parsing everything into table as shown below:
<form action="" method="POST">
<table>
<tr>
<th style="width:8%; text-align:center;" >Action/Status</th>
</tr>
<?php
$mp4_files = array_values($mp4_files);
$mp3_files = array_values($mp3_files);
foreach ($programs as $key => $program) {
$file = $mp4_files[$key];
$file2 = $mp3_files[$key]; // file2 is in mp3 folder
?>
<tr>
<td style="width:5%; text-align:center;"><button style="width:90px;" type="button" name="go" class="btn btn-outline-primary">Go</button</td> <!-- Line#B --> <!-- Go Button -->
</tr>
<?php } ?>
</table>
</form>
Problem Statement:
I am wondering what changes I should make in the php code above that on click of a Go button (Line#B), foreach loop (Line#A) is called.