Friday 30 November 2012

Create thumbnails for Youtube & Vimeo Videos using PHP

Here we are going to see how to generate thumbnail images from youtube and vimeo videos. This article will be useful when creating a video gallery.

Creating thumbnails of Youtube videos

Creating thumbnails for Youtube is an easy task to perform, actually PHP code is not necessary to perform this.

Each YouTube video has 4 generated images. They are predictably formatted as follows:

http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg

Example:
Say link "http://www.youtube.com/watch?v=QdoTdG_VNV4&feature=g-all",
In this youtube link video id is "QdoTdG_VNV4". So if you want to create thumbnail for this videos use this id with the above representation.

http://img.youtube.com/vi/QdoTdG_VNV/0.jpg

Creating thumbnails of Vimeo videos

For Vimeo thumbnails can be generated using simple PHP code. 

<?php

$imgid = <video-id>;

$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$imgid.php"));

echo $hash[0]['thumbnail_medium'];  

?>

If "http://vimeo.com/36519586" is the Vimeo link then <video-id> is "36519586".


Thank You!

Thursday 29 November 2012

Creating 404 page in PHP (.htaccess)

404 is a status shown by your browser when the requested page is not found by your server. In PHP you can design a custom 404 page using .htaccess functionality. Here is a sample code for this:

.htaccess
RewriteEngine on
ErrorDocument 404 [path]404.php

Place this code in your projects root. 404.php can be a custom page designed by you. Try it out.

Thank You!

Wednesday 28 November 2012

Download Link Using PHP


Create a download link using PHP.

It needs two files index.php and download.php, this is just for an representation. Below is the code:

index.php
<a href="download.php?file=conent.zip" title="Download">
       <b>Download file</b>
</a>

download.php

<?php
$file =$_GET['file'];
header("Content-type: application/text");
header("Content-Disposition: attachment; filename=". $file);
readfile($file);
?>

Tuesday 27 November 2012

Print Current Day to End Day of Month in PHP


<?php
$datetime_start = strtotime(date('D Y/m/d'));
$datetime_end   = strtotime(date("D Y/m/d",mktime(0, 0, 0, (date('m') + 1), 0, date('Y'))));

$datetime_temp = $datetime_start;
?>

<select class="input-box" name="">
<?php while ($datetime_temp <= $datetime_end) { ?>
<option><?php echo date('D d/m/Y', $datetime_temp); ?></option>
<?php
$datetime_temp = strtotime('+1 day', $datetime_temp);  
}
?>
</select>

Fetch data from database using php

Fetching Data From Database,

There is mainly two function that can be used to fetch data in php
1. mysql_fetch_array()   : Returns values as arrays.
2. mysql_fetch_object() : Return object
<?php
     $select = "select * from <table_name>";
     $result = mysql_query($select);
?>

1. mysql_fetch_array() 
<?php
   $data=mysql_fetch_array($result);
   $optionField1 = $data['fieldname1'];
   $optionField2 = $data['fieldname2'];
?>

2. mysql_fetch_object()

<?php
   $data=mysql_fetch_object($result);
   $optionField1 = $data->fieldname1;
   $optionField2 = $data->fieldname2;
?>

Thank You!

Monday 26 November 2012

Php code to update values in database

Lets see how we can use php mysql to update values in the database,

Database connection and other related facts are discussed earlier, so let move on to update directly,

Syntax: update <table_name> set <field1>='[update value]' where [condition 1][condition 2]....

See this demo,

id   |  name
1       Rogg
2       Hoggs
3       Brad

In the above that we need to update the name 'Hoggs' with 'Hopes',

<?php
     $update = "update test_table set name='Hopes' where id=2";
     $result   = mysql_query($update);
?>

The statement will result in updation of the record with id is '2'.

Thank You.

Sunday 25 November 2012

Php code to insert values into database

Here it is a sample code to insert elements into database.

Inserting elements into database is a simple task, but before performing this task we should be connected with database and so on.

How to get connected with database using php?

Here in this case with are opting MySQL as the database, world's largest open source database. Connection is like this:

         $con=mysql_connect('[Host]','[username]','[password]') or die ('Connection failed');
         Format is like this.

<?php
        $con=mysql_connect('localhost','root','') or die ('Connection failed');
?>

This will connect you to the database, if not it will prompt you an error message 'Connection failed'. And our task is to insert data on to database.

<?php
        mysql_connect_db('db_name',$con) or die('Connection to database failed');
                                                                //Set database connection.
                                                                //Say 'db_name' as database name.
?>

Insert values to database:

<?php
      $sql_insert="insert into <table_name> values (field1,field2) values ('val1','val2')";
      $result      =mysql_query($sql_insert);
?>

Thank You!


Create Your Own Social Media Buttons

Here are the scripts to create Social Media Buttons. These include Facebook like button, Tweet button & Google's 1+ button.


Google +

<html>
<head>
        <title>+1 demo: Basic page</title>
        <link rel=”canonical” href=”http://www.example.com” />
       <script type=”text/javascript” src=”https://apis.google.com/js/plusone.js”></script>
</head>
<body>
 <g:plusone></g:plusone> or <g:plusone size='medium' count='true' href='YOUR LINK TO +1' ></g:plusone>
</body>
</html>


Facebook

1, <fb:like send="false" href="http://glen-online.webege.com" layout="standard" width="80" show_faces="false" action="like" colorscheme="light"></fb:like>

<div id="fb-root"></div>
<script>
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>

2, IFrame version

   <iframe src="http://www.facebook.com/antony.g.pinheiro" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:px">

Twitter

1, Tweet icon

<div style="position: relative; width: 835px; margin: 0px auto;"><div style="position: absolute; width: 15px; margin: 0 auto; margin-left: 545px; top: 35px; z-index: 999;">
   <a href="http://twitter.com/#!/Mima_Design"><img src="http://twitter-badges.s3.amazonaws.com/t_mini-c.png" alt="Follow Mima_Design on Twitter"></a>
</div></div>