PHP 使用 echo 和
我的 html5 表单可以使用一个提交按钮上传多个 mp3 文件,但我希望它们全部立即显示(嵌入)在带有标签的页面上。目前我只能得到一个。
问:如何设置显示其他 id(audio-player2、audioplayer3 等)的 echo?
我尝试用相同的东西添加第二个回声并替换audio-player2,但它(可以理解)播放相同的文件。大概是因为 (name="files[]")
这里是 html:
<form method="post" enctype="multipart/form-data">
<input type="file" name="files[]" multiple="multiple">
<input type="submit" value="upload!">
</form>
here's the php:
<?php
if (isset($_FILES['files'])){
foreach ($_FILES['files']['tmp_name'] as $key => $tmp_name){
move_uploaded_file($tmp_name, "uploaded/{$_FILES['files']['name'][$key]}");
}
echo "<br><audio preload controls src='uploaded/{$_FILES['files']['name'][$key]}' id='audio-player1' name='audio-player1'></audio><br>";
}
?>
I have my html5 form working to upload multiple mp3 files with one submit button but I want them all to immediately appear (embed) on the page with the tag. Currently I can only get one.
Q: How do I set echo for the other id's (audio-player2, audioplayer3 etc) to appear?
I have tried adding a second echo with the same stuff and substituting audio-player2 but it (understandably) plays the same file. presumably because of (name="files[]")
here's the html:
<form method="post" enctype="multipart/form-data">
<input type="file" name="files[]" multiple="multiple">
<input type="submit" value="upload!">
</form>
here's the php:
<?php
if (isset($_FILES['files'])){
foreach ($_FILES['files']['tmp_name'] as $key => $tmp_name){
move_uploaded_file($tmp_name, "uploaded/{$_FILES['files']['name'][$key]}");
}
echo "<br><audio preload controls src='uploaded/{$_FILES['files']['name'][$key]}' id='audio-player1' name='audio-player1'></audio><br>";
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 echo 语句移至 foreach 循环内并添加计数变量:
Move the echo statement inside the foreach loop and add a counting variable:
您需要将 echo 语句移至循环中。
You would need to move your echo statement in to the loop.