你好我有一个进程,上传一个.mp3格式的文件,将其转换为base64,然后将其保存在数据库中,当你拉动文件(从数据库)播放它只播放6秒的文件?我似乎无法找出我出错的地方。 我只是在我正在创建的网站的测试阶段,但我希望在我完全放弃网站之前做到这一点,我已经设置了完美的图像,但音频和视频我遇到了重大问题用。 这是上传表单的代码
<form action="action2.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /><br />
<input type="text" name="user_id" value="<?php echo $_SESSION['user_id'] ?>" hidden="" />
<input type="submit" name="submit" value="Submit" />
</form>
这是上传,存储,编码和删除文件的部分。
<?php
require 'assests/classes/init.php';
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
$allowedExts = array("mp3","wav","ogg");
if ((($_FILES["file"]["type"] == "audio/mpeg")
|| ($_FILES["file"]["type"] == "audio/x-mpeg")
|| ($_FILES["file"]["type"] == "audio/mp3")
|| ($_FILES["file"]["type"] == "audio/x-mp3")
|| ($_FILES["file"]["type"] == "audio/mpeg3")
|| ($_FILES["file"]["type"] == "audio/x-mpeg3")
|| ($_FILES["file"]["type"] == "audio/mpg")
|| ($_FILES["file"]["type"] == "audio/x-mpg")
|| ($_FILES["file"]["type"] == "audio/x-mpegaudio")
|| ($_FILES["file"]["type"] == "audio/wav")
|| ($_FILES["file"]["type"] == "audio/x-wav")
|| ($_FILES["file"]["type"] == "audio/ogg"))
&& ($_FILES["file"]["size"] < 2000000000000000000000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1048576) . " MB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
echo (20000000 / 1024);
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
var_dump($_FILES);
$byte_array = file_get_contents("upload/" . $_FILES["file"]["name"]);
$audio = base64_encode($byte_array);
unlink('upload/'.$_FILES["file"]["name"]);
$jk = new users;
$jk->audio_upload($_POST['user_id'],$audio);
echo $audio;
var_dump($jk->audio_upload($_POST['user_id'],$audio));
var_dump($audio);
}
}
}
else
{
echo "Invalid file";
}
var_dump($_FILES);
var_dump($extension);
?>
然后我用它来玩它
<?php
$jk = new users;
$audio = $jk->testing_audio_base_64($_SESSION['user_id']);
var_dump($audio);
?>
<audio controls >
<?php echo '<source src="data:audio/mp3;base64, '.$audio.'" >'?>
Your browser does not support the audio element.
</audio>
但它只显示6秒的文件? 我在这里做错了吗?