帮助使用 MySQL 和 PHP 上传视频

发布于 2024-11-19 10:28:03 字数 757 浏览 5 评论 0原文

我正在编写一些与 MySQL 交互的 PHP,以 1. 上传和 2. 显示 Quicktime .mov 文件。我已经很容易地使用图像格式完成了类似的事情,但这给了我一些问题。上传正在工作,因为数据正在插入 SQL 表,并且客户端正在从我的 viewvideo.php 脚本中获取某些内容。然而,问题是客户端接收到的数据不能解析为 Quicktime 电影,这意味着在整个过程中的某个地方出了问题……或者数据可能编码不正确?以下是我的两个脚本的重要部分:

上传:

$name = $_FILES["file"]["tmp_name"];
$contents = file_get_contents($name);
mysql_query("INSERT INTO videos(id,data,title,description) VALUES($n,'$contents','$title','$description')");

显示:

$x = mysql_query("SELECT data FROM videos WHERE id=$id");
$results = mysql_fetch_array($x);
$data = $results[0];
header("Content-Type: video/quicktime");
echo $data;
exit;

目前我唯一的假设是,当我将 ' ' 放在 $contents 周围时,它会弄乱字符串的编码。 SQL 服务器暂时关闭进行维护,所以我必须等待测试。任何帮助表示赞赏。

I'm writing some PHP that will interact with MySQL to 1. upload and 2. display a Quicktime .mov file. I have done similar things with image formats quite easily, but this one is giving me some issues. The upload is working in the sense that data is being inserted into the SQL table, and the client is getting something from my viewvideo.php script. However, the problem is that the data that the client receives isn't parsible as a Quicktime movie, meaning that somewhere along the line, something went wrong.. or maybe the data is encoded incorrectly? Here are the important segments of my two scripts:

The upload:

$name = $_FILES["file"]["tmp_name"];
$contents = file_get_contents($name);
mysql_query("INSERT INTO videos(id,data,title,description) VALUES($n,'$contents','$title','$description')");

The display:

$x = mysql_query("SELECT data FROM videos WHERE id=$id");
$results = mysql_fetch_array($x);
$data = $results[0];
header("Content-Type: video/quicktime");
echo $data;
exit;

My only hypothesis at the moment is that when I put the ' ' around $contents, it messes up the encoding of the string. The SQL server is temporarily down for maintenance, so I will have to wait to test this. Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往日情怀 2024-11-26 10:28:03

用数据库来做这件事是个坏主意。 Blob 仅适用于二进制数据 =< 256KB。请参阅此处

我建议您只需使用 a 上传 .mov 文件

<input type="file" .../>

,然后直接通过 HTTP 访问这些文件,或者使用播放器插件(例如在 Flash 中)之类的东西从服务器流式传输它们。

Bad idea to do this with a Database. Blobs are just for binary data =< 256KB. See here.

I would suggest you simply upload the .mov-files using a

<input type="file" .../>

and then access the files directly via HTTP or stream them from the Server using something like a player-plugin (in Flash for example).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文