2013-03-09 89 views
2

我正在建立一個視頻網站,我希望我的用戶能夠從Youtube上傳或嵌入視頻。 Youtube API似乎沒有提供從他們的網站上傳視頻,或者他們? 所以我試圖通過iframe與PHP嵌入視頻。下面是代碼:嵌入Youtube視頻的最佳方式是什麼?

<?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> 

任何人都可以推薦一些其他的方式來做到這一點?由於

回答

2

允許用戶僅上載YouTube視頻ID從網址爲:

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

視頻ID:Vw5FDZRGTL0

,你可以設置IFrame標記的其他選項:

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

好運

+0

非常感謝,這工作! – user2120032 2013-03-09 13:47:14

+0

非常感謝,投我:) – 2013-03-09 14:29:20

0

您需要使用addslashes()功能:

echo Addslashes($source); 
+0

不,不工作 – user2120032 2013-03-09 13:31:29