所以我能够将mp3文件上传到mysql,我现在正试图将mp3文件从上传它的用户输出到我的索引页面。我创建了一个名为Post.php的页面,这里是代码:
<?php
class Post {
private $user_obj;
private $con;
public function __construct($con, $user)
{
$this->con = $con;
$this->user_obj = new User($con, $user);
}
public function loadPostsFriends() {
$str = "";
$data = mysqli_query($this->con, "SELECT * FROM posts WHERE
deleted='no' ORDER BY id DESC");
while($row = mysqli_fetch_array($data)) {
$id = $row['id'];
$file = $row['file'];
$file_open = fopen($file, "a+");
$added_by = $row['added_by'];
$date_time = $row['date_added'];
$str .= "<div class='status_post'>
<div class='post_profile_pic'>
<img src='$profile_pic' width='50'>
</div>
<div class='posted_by'>
<a href='$added_by'> $username </a> $user_to
$time_message
</div>
<div id='post_file'>
<audio controls>
<source src='echo fgets($file_open);'
type='audio/mpeg'>
</source>
fclose($file_open);
</audio><br>
</div>
</div>";
}
echo $str;
}
}
<?
这是索引页面上的输出代码:
<?php
$post = new Post($con, $userLoggedIn);
$post->loadPostsFriends();
?>
我排除了$ added_by和$ date_time的代码,但所有信息都输出到索引页面,音频文件除外。我不知道如何从mysqli中检索音频文件并将其显示在音频标签中,以便人们可以按下播放并收听它。我知道它连接到文件,但只是不显示它。