如何在单击html按钮时调用php代码的特定部分?
我正在编写一个php代码,如下所示,我正在使用系统命令ffmpeg将mp4文件转换成mp3如何在单击html按钮时调用php代码的特定部分?,php,html,button,Php,Html,Button,我正在编写一个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);
<?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>
行动/状态
去
按钮应为type=“submit”
,以便在单击表单时提交表单。或者将表单更改为method=“GET”
,或者将$\u GET['go']
更改为$\u POST['go']
。如果要允许任何一种方法,请使用$\u REQUEST['go']
<td style="width:5%; text-align:center;"><button style="width:90px;" type="submit" name="go" class="btn btn-outline-primary">Go</button</td> <!-- Line#B --> <!-- Go Button -->
Go
您需要使用JavaScript将操作附加到客户端的按钮上。请阅读关于AJAX的教程。@Barmar我已经修改了我的问题。我粘贴了错误的代码。isset($\u GET['go'])
如果在html按钮中粘贴name=“go”
,则该设置将不为真?抱歉,这部分答案是错误的。但是您需要使form方法与您正在使用的变量相匹配。对不起,我有点困惑。答案的哪一部分你说错了?我在上面发布的一个。我说您需要在按钮中添加值
属性的部分。您似乎不理解客户端代码和服务器端代码之间的区别。