【发布时间】:2026-02-12 17:15:01
【问题描述】:
这是我从数据库中检索视频的代码,在上传时我已将视频复制到 mysql 的 htdocs 文件夹并存储到数据库的路径,而我尝试检索视频时它说错误 mime type not matched,这是我的数据库it has only two column, this is my htdocs folder contains of video
代码:
<?php
error_reporting(1);
$servername="localhost";
$username="root";
$password="";
$dbname="demo1";
$conn=new mysqli($servername,$username,$password,$dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
extract($_POST);
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
if($upd)
{
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if($imageFileType != "mp4" && $imageFileType != "avi" && $imageFileType != "mov" && $imageFileType != "3gp" && $imageFileType != "mpeg")
{
echo "File Format Not Suppoted";
}
else
{
$video_path=$_FILES['fileToUpload']['name'];
$sql = "INSERT INTO video (path) VALUES('$video_path')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],$target_file);
echo "uploaded ";
}
}
//display all uploaded video
if($_POST['disp'])
{
// echo "came in";
$query=mysqli_query($conn,"select * from video");
while($all_video=mysqli_fetch_array($query))
{
//echo "test_upload/uploads/".$all_video['path'];
?>
<h1>test_upload/uploads/<?php echo $all_video['path']; ?></h1>
<video width="300" height="200" controls>
<source src="test_upload/uploads/<?php echo $all_video['path']; ?>" type="video/mp4">
</video>
<?php } } ?>
【问题讨论】:
-
您将 mime 类型静态设置为 type="video/mp4" 但正在寻找 mp4、avi 或 mov 文件