开发者

Using PHP Form to Embed Video

开发者 https://www.devze.com 2023-04-12 07:55 出处:网络
I want to use a PHP form to embed a video onto a web page. Not sure why this isn\'t working as the page source has the embed 开发者_运维技巧code but nothing is showing up on the page. Here\'s the PHP

I want to use a PHP form to embed a video onto a web page. Not sure why this isn't working as the page source has the embed 开发者_运维技巧code but nothing is showing up on the page. Here's the PHP I'm using:

test.php

<html>
<head></head>

<form action="" method="post">
Embed Code: <input type="text" name="embedCode" />
<input type="submit" />
</form>

<?php echo $_POST['embedCode']; ?>

</html>

The 'embedCode' should be able to handle any generic video embedding code such as or and shouldn't be specific to YouTube or anything else.


The URL part must be the src of the embed. For a youtube video it would be like this:

<html>
<head></head>

<form action="" method="post">
URL: <input type="text" name="url" />
<input type="submit" />
</form>

<iframe width="560" height="315" src="<?php echo $_POST['url']; ?>" frameborder="0" allowfullscreen></iframe>

</html>

That should work. There are a few problems with this simple solution though:

  • you're trying to echo something that doesn't exist in most cases (when the page is loaded without the form being posted) -> check if the the form has been posted first
  • there is no input validation on what links are posted. You might want to make sure it's a valid (youtube?) link that's being posted before embedding it

Cheers


In your code there is a quote missing

<?php echo $_POST['url]; ?>

should be

<?php echo $_POST['url']; ?>

And for embeding a video if you just echo the url, it is not gonna embed. You have to use the embed code for whatever kind of video it is for eg: Flash Player for flv/Flash Stream,WMP for wmv/asf streams,etc

You have to use the embed code and echo the url in the place were url is in the embed player

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号