gpt4 book ai didi

php - 如何使用 PHP 和 MySQL 将视频插入数据库并在页面上获取

转载 作者:行者123 更新时间:2023-11-29 22:59:49 25 4
gpt4 key购买 nike

这是我的代码,用于在数据库中上传视频或移动到文件夹。在此代码中视频已上传但未将文件插入数据库....?

请帮助我如何使用 PHP + MySQL 将视频插入数据库?

<html>
<head>
</head>
<body>
<form ACTION="test.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label><br>
<input type="file" name="video"><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>

<?php
if(isset($_FILES['video']))
{
$name = $_FILES['video']['name'];
$type = explode('.',$name);
$type = end($type);
$size= $_FILES['video']['size'];
$random_name = rand();
$tmp= $_FILES['video']['tmp_name'];


if($type !='mp4' && $type !='MP4' && $type !='flv')
{
$message ="Video Format Not Supported";
}
else
{
move_uploaded_file($tmp, 'videos/'.$random_name.'.'.$type);

mysql_query("INSERT INTO 'videos' VALUES ('', '$name',
'videos/$random_name.$type')");

$message ="Successfully Uploaded";
}

echo "$message <br/> <br/>";
}
?>

最佳答案

我从我的文件中复制了这段代码,希望这可以解决您的问题。

$vdo=$_FILES['uf']['name'];     $target_path = "video/";
$target_path = $target_path . basename( $_FILES['uf']['name']);
$target_path . basename( $_FILES['uf']['name']);
if(move_uploaded_file($_FILES['uf']['tmp_name'], $target_path))
{ $host="mysqlbhost.com";
$username="me";
$password="me";
$db_name="db";
$tbl_name="video";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db ("$db_name")or die("cannot select DB");
$sql="INSERT INTO $tbl_name(video)
VALUES('$vdo')";
$result=mysql_query($sql);
echo "<div id='rslt'>"; echo "Thanks! video has been sent to ";

关于php - 如何使用 PHP 和 MySQL 将视频插入数据库并在页面上获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28555393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com