【发布时间】:2019-10-19 10:10:17
【问题描述】:
我正在编写如下所示的 php 代码,其中我使用系统命令 ffmpeg 将 mp4 文件转换为 mp3。
<?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.
}
}
}
?>
转换完成后,我将所有内容解析为如下所示的表格:
<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>
问题陈述:
我想知道在点击 Go 按钮 (Line#B)、foreach 循环 (Line#A) 时我应该在上面的 php 代码中进行哪些更改。
【问题讨论】:
-
您需要使用 JavaScript 将动作附加到客户端上的按钮。
-
阅读 AJAX 教程。
-
@Barmar 我修改了我的问题。我粘贴了错误的代码。