Thursday 25 October 2012

php for youtube upload by using url


<form action="tube.php" method="post">
<input type="text" name="id" />
<input type="text" name="you" />
<input type="submit" value="submit" />
</form>
<?php  $con=mysql_connect("localhost","root","");
mysql_select_db("tube",$con);
$long = $_POST['you'];
$id = $_POST['id'];
mysql_query("INSERT INTO `youtube`(`id`, `url`) VALUES ('$id','$long')") or die("unable to connect");
$query=mysql_query("SELECT `id`, `url` FROM `youtube` where `id`=1");
while($res=mysql_fetch_array($query))
{
   
?>
<?php

$longString = $res['url'];
$len=strlen($longString );

?>
<?php
if($len>43)
{
 ?>
<iframe width="560" height="315"  id="cs" src="
<?php


$b = substr($longString , strpos($longString , 'watch?v') + 1);


$c = substr($b, 0, strpos($b, '&'));

$str2 = substr($c, 7);


/*
echo substr_replace($c, '', 15) . "<br />\n";
echo "<br>";
$d = substr($a, 0, strpos($a, '='));
print $d; // prints 9999 */

$mn=substr_replace($longString , 'embed/', 23);

$mn .=$str2;

echo $mn;





?>" frameborder="0" allowfullscreen></iframe><?php } else {?>


<?php

$separator = 'embed/';
$separatorlength = strlen($separator) ;
$maxlength =53 - $separatorlength;
$start = $maxlength / 2 ;
$trunc =  strlen($longString) - $maxlength;

$st= substr_replace($longString, $separator, $start);
echo "<br>";
$st.=substr($longString,31);




?>
<iframe width="560" height="315" src="<?php echo $st; ?>" frameborder="0" allowfullscreen></iframe><?php } ?> <br /><br /><br /> <?php }?>

No comments:

Post a Comment