嵌入Youtube视频的最佳方式是什么? [英] What is the best way to embed Youtube videos?

查看:117
本文介绍了嵌入Youtube视频的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个视频网站,我希望我的用户能够从Youtube上传或嵌入视频。 Youtube API似乎不提供来自其网站的视频上传,或者是吗?
所以我尝试使用PHP通过 iframe 嵌入视频。以下是代码:

I'm building a video website and I want my users to be able to upload or embed videos from Youtube. The Youtube API doesn't seem to provide video upload from their website, or do they? So I tried to embed videos via an iframe with PHP. Here is the code:

<?php
$source=$_POST['source'];
?>

<html>
<div id="bo"><?php echo $source;?></div>
<form action="altupload.php" method="post">
<input type="text" name="source">
<input type="submit">
</form>
</html>

但我得到的是:

<html><div id="bo"><iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/tZa5hyb0_wA\" frameborder=\"0\" allowfullscreen></iframe></div>`

<html>
<form action="altupload.php" method="post">
<input type="text" name="source">
<input type="submit">
</form>
</html>

有人可以推荐一些其他方法吗?谢谢

Can anyone recommend some other ways to do it? Thanks

推荐答案

允许用户仅从URL上传YouTube视频ID:

Allow the user upload only youtube video ID from URL as :

http://www.youtube.com/watch?v=Vw5FDZRGTL0

视频ID: Vw5FDZRGTL0

您可以设置IFrame标签的其他选项:

and you can set other options of IFrame tag :

<iframe width="420" height="315" src="http://www.youtube.com/embed/<?php echo $videoID; ?>" frameborder="0" allowfullscreen></iframe>  

祝你好运

这篇关于嵌入Youtube视频的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆