gpt4 book ai didi

php - 将视频存储在 phpmyadmin 数据库中

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

我创建了一个数据库来显示视频内容。我尝试将视频剪辑作为 longblob 存储在数据库中,但文件大小太大。我的视频剪辑是高清录制的,这是获得清晰图像所必需的。

我尝试将文件路径作为 varchar 存储在我的数据库中,尽管我不确定我是否做得正确。我正在将视频的位置存储在我的计算机上。

我的文件路径之一如下:C:/wamp/www/com904/eNISAT/Password/Change Password Tutorial.wmv。

我尝试从表中选择所有内容以在 php 页面 displayVideos.php 上显示视频,但我在 html 表中以文本形式获取文件路径输出。

这是我的 displayVideos.php 文件中的代码。

<?php

require_once("db_connection.php");


//Start session
/*
Sessions is a mechanism to preserve data across subsequent accesses. Using sessions, a website is able to maintain state, that is,
remember which requests they received previously. Without sessions, websites would not have progressed beyond simple static HTML pages.
*/
session_start();

//Select database
$database = "com904";
$db = mysql_select_db($database) or die("Unable to select database");

include_once 'db_connection.php';
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>File Uploading With PHP and MySql</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body bgcolor="sky blue">
<center>
<div id="header">
<h1> Click on each video to view your tutorials <h1/>
</div>
<div id="body">
<table width="80%" border="1"bgcolor = "white">

<tr>
<th colspan="4">Your eNISAT Tutorials
</tr>
<tr>
<td>Support Question</td>
<td>Video</td>
</tr>
<?php

$sql="SELECT * FROM enisatquestion";
$result_set=mysql_query($sql);
while($row=mysql_fetch_array($result_set))
{
?>
<tr>
<td><?php echo $row['eNISATQuestion'] ?></td>
<td><?php echo $row['eNISATVideo'] ?></td>
</tr>
<?php
}
?>
</table>

</div>
</body>
</html>

最佳答案

您几乎肯定希望在数据库中实际存储相对 URL (com904/eNISAT/Password/Change Password Tutorial.wmv),而不是绝对 URL,而且绝对不是路径正如您所做的那样,在磁盘上。即使您决定显示绝对 URL,您也可以通过 PHP 代码来实现,而不是将主机名存储在数据库中。

调整存储路径后,您需要调整输出的显示。令人惊讶的是,没有一个教程涉及这个问题。不要打印 URL,而是尝试打印一个以 URL 作为链接目标的 href。您可以随意设置链接文本;可能仅提取文件名或从数据库中的 title 字段中提取。

此外,在将结果插入数据库之前,您应该对结果进行 URL 转义。 PHP 提供了几个可以执行此操作的函数(每个函数与其他函数都有特定的变化,因此您应该在做出决定之前评估每个函数)。

关于php - 将视频存储在 phpmyadmin 数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34757081/

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