将视频存储在phpmyadmin数据库中


Storing a video in phpmyadmin database

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

我试图将文件路径作为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。你可以制作任何你想要的链接文本;可能仅提取文件名,或者通过从数据库中的CCD_。

此外,在将结果插入数据库之前,您应该对其进行URL转义。PHP提供了几个可以做到这一点的函数(每个函数都有不同于其他函数的特定变体,所以在做出决定之前应该对每个函数进行评估)。