duan198299 2014-04-16 14:37
浏览 26
已采纳

将单选按钮值放入链接

I am making a website which will stream a selected video. I could make it show the file list. What I want is, when I select a file from list, it pastes filename into source link for video streaming. I cannot get this file name from the list that I got. Can anyone help me, please? Don't be mad, I'm just a beginner in this.

<form action="" method="post">
<?php

//scans files and sorts by date

$files = glob('/media/*.MP4');
usort($files, function($a, $b) {
    return filemtime($a) < filemtime($b);
});

// outputs a list of files, sorted by name

foreach($files as $file){
    printf('<p><tr><td><input type="radio" id="%1$s" name="box"></td>
            <td><label for="%1$s">%1$s</td></label>
            <td><label for="%1$s">%2$s</td></label></tr></p>', 
            basename($file), date('F d Y, H:i:s', filemtime($file)));
}

?>

<input type="submit" name="submit1" value="Submit"><INPUT type="reset">
</form>

<video width="320" height="240" controls>
  <source src="/media/<?php printf($_POST); ?>" type="video/mp4">  <--- I want to put the file name in this line

</video>
  • 写回答

1条回答 默认 最新

  • du7133 2014-04-16 14:50
    关注

    According to this line:

    printf('<p><tr><td><input type="radio" id="%1$s" name="box"></td>
            <td><label for="%1$s">%1$s</td></label>
            <td><label for="%1$s">%2$s</td></label></tr></p>', 
            basename($file), date('F d Y, H:i:s', filemtime($file)));
    

    Your input name is 'box'. You can access it after the form submission via $_POST['box'], something along the lines of:

    <?php if(isset($_POST['box'])) { // This will hide the video prior to submission ?>
        <video width="320" height="240" controls>
          <source src="/media/<?php echo $_POST['box']; ?>" type="video/mp4"> 
        </video>
    <?php } ?>
    

    Update

    Admittedly I should have seen this sooner, but your input name is being repeated many times. You don't want to have two elements in the same form that share the same name. You need to differentiate it them somehow, and in general you can achieve having many elements with the same name by simply making it an array:

    printf('<p><tr><td><input type="radio" id="%1$s" name="box[]"></td>
    

    Now you should be able to see an array when you submit and var_dump( $_POST['box'] )

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化