I am working on a php code as shown below in which I am converting mp4 files into mp3 using system command ffmpeg on click of any Go button from table row as shown below in an image.
<?php
if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['go-button']))
{
foreach ($mp4_files as $f)
{
$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);
}
}
}
?>
<table>
<tr>
<th>MP4 Name</th>
<th>Action/Status</th>
</tr>
<?php
$file = $mp4_files[$key];
?>
<tr>
<td><?php echo basename($file); ?></td>
<td><button style="width:90px;" type="submit" name="go-button" value="Go" class="btn btn-outline-primary">Go</button</td> <!-- Line#B -->
</tr>
</table>
The above html/php code display the following content:
Problem Statement:
I am wondering what changes I should make in the php code above so that the Go button (Line#B) targets the mp4 file present in the same row.
At this moment, on click of a Go button from any table row, conversion of all mp4 files into mp3 start happening.
Let say $mp4_files have two files:
- 36031P.mp4
- hello.mp4
-> 1st row Go button should target 1st file(36031P.mp4).
-> 2nd row Go button should target 2nd file(hello.mp4).
This is what I have tried but adding break is targeting only the 1st file in $mp4_files but that too click of any Go button.
foreach ($mp4_files as $f)
{
// my stuff
break;
}