Friday, August 3, 2012

PHP- Upload and convert avi, wmv, mov and mpg videos to FLV


PHP- Upload and convert avi, wmv, mov and mpg videos to FLV

Upload and convert avi, wmv, mov and mpg videos to FLV using PHP
1.First you have to create a page from where the user will upload a videolets
call it uploadvideo.php.

follow the code below..

<form name=”frm” action=”uploadvideopro.php” method
=”post” enctype="multipart/form-data" >

<input name="x_URL" type="file" class="form1"
size="26">

<input type="submit" name="submit" value="upload"
>

</form>



2.Secondly on the process page i.e. uploadvideopro.php . follow the following
code..



/***************Load FFMPEG *********************************/



$extension = "ffmpeg";

$extension_soname = $extension . "." . PHP_SHLIB_SUFFIX;

$extension_fullname = PHP_EXTENSION_DIR . "/" . $extension_soname;





// load extension

if (!extension_loaded($extension)) {

dl($extension_soname) or die("Can't load extension $extension_fullname\n");

}



/***********************************************************/



/*****************Get the path to Extention ****************/



$array_path = explode("/",$_SERVER['SCRIPT_FILENAME']);

$dynamic_path = "";

for ($i=0;$i<sizeof($array_path)-1;$i++)

if($array_path[$i]!="")

$dynamic_path =$dynamic_path."/".$array_path[$i];

/**********************************************************/



/******************set folders*****************************/

$flvpath = "flvfiles/";

$moviepath = "movies/" ;

chmod($moviepath,0777);

chmod($flvpath,0777);

/*********************************************************/


/******************Upload and convert video *****************************/



if(isset($_FILES["x_URL"]))

{

$fileName = $_FILES["x_URL"]["name"];

$fileNameParts = explode( ".", $fileName );

$fileExtension = end( $fileNameParts );

$fileExtension = strtolower( $fileExtension );

if($fileExtension=="avi" || $fileExtension=="wmv" || $fileExtension=="mpeg"
|| $fileExtension=="mpg" || $fileExtension=="mov" )

{

if ( move_uploaded_file($_FILES["x_URL"]["tmp_name"],$ moviepath.$_FILES["x_URL"]["name"])
)

{



if( $fileExtension == "wmv" ) {

exec("ffmpeg -i ".$dynamic_path."/".$ moviepath."".$fileName."
-sameq -acodec mp3 -ar 22050 -ab 32 -f flv -s 320x240 ".$dynamic_path."/".$flvpath."myflv.flv");

}

if( $fileExtension == "avi" || $fileExtension=="mpg" ||
$fileExtension=="mpeg" || $fileExtension=="mov" ) {

exec("ffmpeg -i ".$dynamic_path."/".$ moviepath."".$fileName."
-sameq -acodec mp3 -ar 22050 -ab 32 -f flv -s 320x240 ".$dynamic_path."/".$flvpath."myflv.flv");

}

/******************create thumbnail***************/

exec("ffmpeg -y -i ".$dynamic_path."/".$moviepath."".$fileName."
-vframes 1 -ss 00:00:03 -an -vcodec png -f rawvideo -s 110x90 ".$dynamic_path."/".$flvpath."myflv.png");


}

else

{

die("The file was not uploaded");

}

}



else

{

die("Please upload file only with avi, wmv, mov or mpg extension!");

}

}

else

{

die("File not found");

}

Date Function Formatting


DAYS 
d - day of the month 2 digits (01-31)
j - day of the month (1-31)
D - 3 letter day (Mon - Sun)
l - full name of day (Monday - Sunday)
N - 1=Monday, 2=Tuesday, etc (1-7)
S - suffix for date (st, nd, rd)
w - 0=Sunday, 1=Monday (0-6)
z - day of the year (1=365)
WEEK
W - week of the year (1-52)
MONTH
F - Full name of month (January - December)
m - 2 digit month number (01-12)
n - month number (1-12)
M - 3 letter month (Jan - Dec)
t - Days in the month (28-31)
YEAR
L - leap year (0 no, 1 yes)
o - ISO-8601 year number (Ex. 1979, 2006)
Y - four digit year (Ex. 1979, 2006)
y - two digit year (Ex. 79, 06)
TIME
a - am or pm
A - AM or PM
B - Swatch Internet time (000 - 999)
g - 12 hour (1-12)
G - 24 hour c (0-23)
h - 2 digit 12 hour (01-12)
H - 2 digit 24 hour (00-23)
i - 2 digit minutes (00-59)
s 0 2 digit seconds (00-59)
OTHER e - timezone (Ex: GMT, CST)
I - daylight savings (1=yes, 0=no)
O - offset GMT (Ex: 0200)
Z - offset in seconds (-43200 - 43200)
r - full RFC 2822 formatted date

Give Month number Get month name in PHP


Here’s a quickie for you. 
Ever wanted to convert a month number to a month name in PHP but hated having to do a huge switch statement? Well here is your answer.

<?php
$monthNum = 5;
$monthName = date("F", mktime(0, 0, 0, $monthNum, 10));
echo $monthName; //output: May
?>
Enjoy.

Hackers may bring down India’s power grids :


Hackers may bring down India’s power grids













 It is possible for an adversary or a group of hackers to cripple India's power grids through a cyber-attack, although this is an unlikely reason for the recent power outages that crippled much of north, east and north-eastern India. 

Since the first power trip up on Monday, there have been discussions within the security establishment about the possibility of entities trying to carry out a sophisticated cyber-attack to cripple the grids. 

Officials who carried out an audit of critical information infrastructure admit it is "theoretically possible" to cripple India's power grids through a cyber-attack. 

Despite such a possibility, the shutdown did not seem to have led to a crisis management procedure that aimed at ruling out or confirming a cyber-attack. 

"Given the fact that our grids are vulnerable to a cyber-attack, those responsible for managing grids should have a proactive policy to rule out cyber-attack as part of their crisis management procedures," a senior official said. "But none of it was visible," he added. 

Sources aware of contacts among power ministry, power grid authorities and those in bothCERT-IN (Computer Emergency Response Team-India) and NTRO (National Technical Research Organisation) say there was no proactive effort by those responsible for power grids. 

However, both CERT-IN and NTRO are believed to have established their own procedures to ensure the shutdowns were not a cyber-attack, having been brought on by massive over-the-limit withdrawals by states to supply electricity for pumps tapping groundwater in the absence of rainfall during this monsoon. 

Officials said the government is now discussing possible ways to speed up the setting up of National Critical Information Infrastructure Protection Centre (NCIPC), which would act as the command and control centre for monitoring the critical information infrastructure of the country. NCIPC was recently approved by the National Security Council headed by the Prime Minister. 

Sources said the government is also planning to hold a national consultation of all stakeholders involved in critical information infrastructure. 

The government is already setting up dedicated CERT-INs for various critical sectors such as power and civil aviation. 

Officials point out to breaches reported from power grids in the US, cyber intrusion into the Iranian nuclear network and other such incidents around the world to warn that India needs to have a more robust crisis management procedure that includes proactive ruling out of cyber-attacks.


courtesy : techgig.com

Wednesday, August 1, 2012

Use JQuery to call Ajax and dynamically Load Page



Example 1:
<script type="text/JavaScript">
function getTime(){
var ClassDivision = document.getElementById("Class").value;
var chrType = document.getElementById("Type").value;
$.ajax({
type: "POST",
  url: "ajax/ajax_page.php",
    data: 'Class='+Class+'&Type='+Type,
  cache: false,
  success: function(msg){
$("#Name_ID").html(msg);
},
error: function(){
alert('Server Busy');
}
  });

}
</script>




Example 2:


<script language="JavaScript" type="text/JavaScript">

$(document).ready(function () {

$('#intBuilding').change(function(e){
var classid=$(this).val();
$('#RoomNo').load('ajax/ajax_rooms.php?id='+classid);
  });
 
});
</script>