0

我要插入的数据是 blob 或文件这是用于学校项目的,讲师说现在将其插入数据库。

这就是我现在拥有的

function stop() {
  cancelAnimationFrame(rafId);
  endTime = Date.now();
  $('#stop-me').disabled = true;
  document.title = ORIGINAL_DOC_TITLE;

  toggleActivateRecordButton();

  console.log('frames captured: ' + frames.length + ' => ' +
              ((endTime - startTime) / 1000) + 's video');

  embedVideoPreview();
};

function embedVideoPreview(opt_url) {
  var url = opt_url || null;
  var video = $('#video-preview video') || null;
  var downloadLink = $('#video-preview a[download]') || null;

  if (!video) {
    video = document.createElement('video');
    video.autoplay = true;
    video.controls = true;
    video.loop = true;
    //video.style.position = 'absolute';
    //video.style.top = '70px';
    //video.style.left = '10px';
    video.style.width = canvas.width + 'px';
    video.style.height = canvas.height + 'px';
    $('#video-preview').appendChild(video);

    downloadLink = document.createElement('a');
    downloadLink.download = 'capture.webm';
    downloadLink.textContent = '[ download video ]';
    downloadLink.title = 'Download your .webm video';
    var p = document.createElement('p');
    p.appendChild(downloadLink);

    $('#video-preview').appendChild(p);

  } else {
    window.URL.revokeObjectURL(video.src);
  }

  if (!url) {
    var webmBlob = Whammy.fromImageArray(frames, 1000 / 60);
    url = window.URL.createObjectURL(webmBlob);
  }

  video.src = url;
  downloadLink.href = url;

这就是我从同一页面将其插入数据库的方式,我也不确定视频 blob 的创建位置。

  <?php
    require("connect.php");
    $namey = video;
    $up = mysql_query("INSERT INTO video VALUES ($namey)");
  ?>
4

1 回答 1

0

好的,假设您有一个供用户上传视频的输入...

<form action="upload.php" method="post" enctype="multipart/form-data">
    <input type="file" name="VideoToUpload" />
    <input type="submit" value="Upload Video" />
</form>

然后在您的新upload.php文件中,您将要处理并保存文件

$allowedExts = array("mp4", "mov");
$extension = end(explode(".", $_FILES["VideoToUpload"]["name"]));
if (($_FILES["VideoToUpload"]["type"] == "video/mp4") || ($_FILES["VideoToUpload"]["type"] == "video/quicktime")):
    if($_FILES["VideoToUpload"]["error"] > 0):
        echo "Error: " . $_Files["VideoToUpload"]["error"];
    else:
        move_uploaded_file($_FILES["VideoToUpload"]["tmp_name"], dirname(__FILE__) . "/FolderWhereIWantMyVideoSaved/" . $_FILES["VideoToUpload"]["name"]);
    endif;
endif;
$VideoURL = "http://domain/and/path/to/FolderWhereIWantMyVideoSaved/" . $_FILES["VideoToUpload"];
$mysqli = new mysqli('ip.of.data.base', 'DatabaseName', 'Password', 'Username');    
$stmt = $mysqli->prepare("INSERT INTO Videos (Name, Type, URL) VALUES (?,?,?)") or die ($mysqli->error);
$stmt->bind_param('sss', $_FILES["VideoToUpload"]["name"],$_FILES["VideoToUpload"]["type"], $VideoURL);
$stmt->execute() or die ($mysqli->error);
$stmt->close();
$mysqli->close();

现在该文件已保存在服务器上,并且该文件的 URL 在数据库中。因此,要显示视频,您要做的就是。

$mysqli = new mysqli('ip.of.data.base', 'DatabaseName', 'Password', 'Username');    
$stmt = $mysqli->prepare("SELECT Name, Type, URL FROM Videos WHERE ID=?") or die ($mysqli->error);
$stmt->execute() or die($mysqli->error);
$stmt->bind_result($Name, $Type, $URL);
$stmt->store_result();
$stmt->fetch();
...
<video width="320" height="240" controls>
    <source src="<?= $URL ?>" type="<?= $Type ?>">
    Your browser does not support the video tag.
</video>
...
$stmt->close();
$mysqli->close();
于 2013-06-29T14:43:21.677 回答