if (version_compare(phpversion(), '5.0.0', '>=') !== true) {
exit('This website runs with PHP5... You version is <b>' . phpversion() . '</b>.Please upgrade');
}
Showing posts with label Code. Show all posts
Showing posts with label Code. Show all posts
Wednesday, October 2, 2013
PHP-Version Check code
Sunday, June 9, 2013
PHP-get User Browser
<?php
function get_user_browser()
{
$u_agent = $_SERVER['HTTP_USER_AGENT'];
$ub = '';
if(preg_match('/MSIE/i',$u_agent))
{
$ub = "ie";
}
elseif(preg_match('/Firefox/i',$u_agent))
{
$ub = "firefox";
}
elseif(preg_match('/Safari/i',$u_agent))
{
$ub = "safari";
}
elseif(preg_match('/Chrome/i',$u_agent))
{
$ub = "chrome";
}
elseif(preg_match('/Flock/i',$u_agent))
{
$ub = "flock";
}
elseif(preg_match('/Opera/i',$u_agent))
{
$ub = "opera";
}
return $ub;
}
?>
Monday, May 6, 2013
Social Engine 4-Finding name of widget and Calling/Running a widget by custom code via name
First things first
1. In the backend select layout=>layout editor
Select the page on which your widget is currently placed
Or
If you know the name of your widget find it in concerned module on right hand side
You can use my technique for the same
For example we are looking for the widget "Statistics" Find the plugin text in admin using "find text tool(Ctrl+F)" of your browser and search for the same under "Available Blocks"
2. Once yo know the widget and its module for example for above mentioned widget we find it under "Core Module"
Moving Back to code
under
/application/modules/core/settings (considering our example for Core Module and Statistics Widget)
open file content.php
find the array of widget Statistics there like
1. In the backend select layout=>layout editor
Select the page on which your widget is currently placed
Or
If you know the name of your widget find it in concerned module on right hand side
You can use my technique for the same
For example we are looking for the widget "Statistics" Find the plugin text in admin using "find text tool(Ctrl+F)" of your browser and search for the same under "Available Blocks"
2. Once yo know the widget and its module for example for above mentioned widget we find it under "Core Module"
Moving Back to code
under
/application/modules/core/settings (considering our example for Core Module and Statistics Widget)
open file content.php
find the array of widget Statistics there like
array(
'title'=>'statistics',
'description'=>'',
'category'=>'core',
'type'=>'widget',
'name'=>'core.statistics',
'defaultParams'=>array(
'title'=>'Statistics'
),
'requirements'=>array(
'no-subject',
),
);
Now we need the name attribute to call our widget in code as
<?php
echo $this->content()->renderWidget('core.statistics';)
?>
other examples can be
content()->renderWidget('core.ad-campaign') ?>
content()->renderWidget('user.home-photo') ?>
Sunday, July 8, 2012
Javascript code to get a string sliced till last occurance of a charcter
Javascript code to get a string sliced till last occurrence of a character function
//javascript
getStringTillLastCharcter(str,chr)
{
var flag=0;
var lastpos;
//alert(str.length);
for(i=0;i < str.length; i++ ) {
if(str.charAt(i)==chr)
{
lastpos=i+1;
}
}
//alert(lastpos);
return str.slice(0,lastpos);
}
Here is a code to get the string till the last occurance of a charcter.....
//javascript
getStringTillLastCharcter(str,chr)
{
var flag=0;
var lastpos;
//alert(str.length);
for(i=0;i
if(str.charAt(i)==chr)
{
lastpos=i+1;
}
}
//alert(lastpos);
return str.slice(0,lastpos);
}
Here is a code to get the string till the last occurance of a charcter.....
A file upload helpful php code
if(isset($_POST['sendmail']))
{
//echo "
//$attachment = chunk_split(base64_encode(file_get_contents($_POST['upload'])));
//Get the uploaded file information
$name_of_uploaded_file =
basename($_FILES['upload']['name']);
//echo $name_of_uploaded_file;
//get the file extension of the file
$type_of_uploaded_file =substr($name_of_uploaded_file,strrpos($name_of_uploaded_file, '.') + 1);
//echo $type_of_uploaded_file;
$size_of_uploaded_file =$_FILES["upload"]["size"]/1024;
//echo $size_of_uploaded_file;
$max_allowed_file_size = 100; // size in KB
$allowed_extensions = array("doc", "pdf", "docx","txt"
;
//Validations
if($size_of_uploaded_file > $max_allowed_file_size )
{
$errors .= "\n Size of file should be less than $max_allowed_file_size";
}
//------ Validate the file extension -----
$allowed_ext = false;
for($i=0; $i {
if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0)
{
$allowed_ext = true;
}
}
if(!$allowed_ext)
{
$errors .=
" Only the following file types are supported: ".implode(',',$allowed_extensions);
}
if(!isset($errors))
{
move_uploaded_file($_FILES["upload"]["tmp_name"],WP_CONTENT_DIR.'/uploads/'.basename($_FILES['upload']['name']));
$to= get_option('ugmm_career_email');
$subject=get_option('ugmm_career_upload_field');
$message="File uploaded by".get_option('ugmm_career_upload_field');
$headers = 'From:upload<'.$to.'>';
$attachments = array(WP_CONTENT_DIR ."/uploads/".$_FILES["upload"]["name"]);
wp_mail($to,$subject,$message,$headers,$attachments);
$sentmail=true;
}
else
$sentmail=false;
}
?>
{
//echo "
"; //print_r($_POST); //print_r($_FILES); //echo "";
//$attachment = chunk_split(base64_encode(file_get_contents($_POST['upload'])));
//Get the uploaded file information
$name_of_uploaded_file =
basename($_FILES['upload']['name']);
//echo $name_of_uploaded_file;
//get the file extension of the file
$type_of_uploaded_file =substr($name_of_uploaded_file,strrpos($name_of_uploaded_file, '.') + 1);
//echo $type_of_uploaded_file;
$size_of_uploaded_file =$_FILES["upload"]["size"]/1024;
//echo $size_of_uploaded_file;
$max_allowed_file_size = 100; // size in KB
$allowed_extensions = array("doc", "pdf", "docx","txt"
;//Validations
if($size_of_uploaded_file > $max_allowed_file_size )
{
$errors .= "\n Size of file should be less than $max_allowed_file_size";
}
//------ Validate the file extension -----
$allowed_ext = false;
for($i=0; $i
if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0)
{
$allowed_ext = true;
}
}
if(!$allowed_ext)
{
$errors .=
" Only the following file types are supported: ".implode(',',$allowed_extensions);
}
if(!isset($errors))
{
move_uploaded_file($_FILES["upload"]["tmp_name"],WP_CONTENT_DIR.'/uploads/'.basename($_FILES['upload']['name']));
$to= get_option('ugmm_career_email');
$subject=get_option('ugmm_career_upload_field');
$message="File uploaded by".get_option('ugmm_career_upload_field');
$headers = 'From:upload<'.$to.'>';
$attachments = array(WP_CONTENT_DIR ."/uploads/".$_FILES["upload"]["name"]);
wp_mail($to,$subject,$message,$headers,$attachments);
$sentmail=true;
}
else
$sentmail=false;
}
?>
Tuesday, July 3, 2012
Generate Excel Report with Php and Mysql using code
Step 1. Include phpexcel class file along with your config file and make
its object with excel file name passed parameter in constructor. You can check for error in next line as shown
Step 2. Now time to fetch data from mysql database. Before fetch data, call excel header having columns as values of array.
1 | require_once("excelwriter.class.php"); |
2 |
3 | $excel=new ExcelWriter("report.xls"); |
4 |
5 | if($excel==false) |
6 | echo $excel->error; |
Step 2. Now time to fetch data from mysql database. Before fetch data, call excel header having columns as values of array.
01 | // this will create heading of each column in excel file |
02 |
03 | $myArr=array("S.No.","Company Name","Email","City","Username","Reg. Date"); |
04 | $excel->writeLine($myArr); |
05 |
06 | // now fetch data from database table, there is a new line create each time loop runs |
07 |
08 | $qry=mysql_query("select * from customer"); |
09 | if($qry!=false) |
10 | { |
11 | $i=1; |
12 | while($res=mysql_fetch_array($qry)) |
13 | { |
14 | $myArr=array($i,$res['company_name'],$res['email'],...); |
15 | $excel->writeLine($myArr); |
16 | $i++; |
17 | } |
18 | } |
Step 3. Create link to generate excel file.
1 | <a href="javascript:void(0);" onClick="download();">Download Excel Report |
and here download function pointing to excel file
Subscribe to:
Posts (Atom)