$path_info = pathinfo('lib.inc.php');
echo $path_info['extension'];
Sunday, July 25, 2010
Monday, July 19, 2010
Validate Image Using Javascript
function validate_image()
{
frmobj = document.frmRegistration; //Here "frmRegistration" is Form name
var image_file = frmobj.upload_file.value; /*Here "upload_file" is in this tag like input type="file" name="upload_file" */
var image_length = frmobj.upload_file.value.length;
var pos = image_file.lastIndexOf('.') + 1;
var ext = image_file.substring(pos, image_length);
var final_ext = ext.toLowerCase();
if(final_ext != 'jpg' && final_ext != 'jpeg' && final_ext != 'gif' && final_ext != 'png')
{
alert('Upload valid image');
return false;
}
return true;
}
Usage:
if(!validate_image()) return false;
{
frmobj = document.frmRegistration; //Here "frmRegistration" is Form name
var image_file = frmobj.upload_file.value; /*Here "upload_file" is in this tag like input type="file" name="upload_file" */
var image_length = frmobj.upload_file.value.length;
var pos = image_file.lastIndexOf('.') + 1;
var ext = image_file.substring(pos, image_length);
var final_ext = ext.toLowerCase();
if(final_ext != 'jpg' && final_ext != 'jpeg' && final_ext != 'gif' && final_ext != 'png')
{
alert('Upload valid image');
return false;
}
return true;
}
Usage:
if(!validate_image()) return false;
Sunday, July 18, 2010
create dynamic images in php
//Create Image By Url Method - 2
function create_image_by_url2($url)
{
$path_parts = pathinfo($url);
copy($url,$path_parts['basename']);
}
create_image_by_url2($url);
function create_image_by_url2($url)
{
$path_parts = pathinfo($url);
copy($url,$path_parts['basename']);
}
create_image_by_url2($url);
create dynamic images using php
$url = "http://technmarketing.com/wp-content/uploads/2009/03/twitter-wallpaper2.jpg";
//Create Image By Url Method - 1
function create_image_by_url1($url)
{
$target_path = $url;
$imgdir="";
$path_parts = pathinfo($url);
$file_name = $path_parts['basename'];
$imgext = $path_parts['extension'];
if($imgext=='jpg' || $imgext=='JPG')
$src_img=imagecreatefromjpeg($target_path);
if($imgext=='gif' || $imgext=='GIF')
$src_img=imagecreatefromgif($target_path);
if($imgext=='png' || $imgext=='PNG')
$src_img=imagecreatefrompng($target_path);
if($imgext=='jpeg' || $imgext=='jpeg')
$src_img=imagecreatefromjpeg($target_path);
$size = getimagesize($target_path);
$dst_img = imagecreatetruecolor($size[0],$size[1]);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$size[0],$size[1],$size[0],$size[1]);
if(($imgext=='jpg') || ($imgext=='JPG') || ($imgext=='jpeg') || ($imgext=='JPEG'))
{
imagejpeg($dst_img, $imgdir.$file_name,90);
}else if(($imgext=='gif') || ($imgext=='GIF')){
imagegif($dst_img, $imgdir.$file_name,90);
}else if(($imgext=='png') || ($imgext=='PNG')){
imagepng($dst_img, $imgdir.$file_name,5);
}
}
create_image_by_url1($url);
//Create Image By Url Method - 1
function create_image_by_url1($url)
{
$target_path = $url;
$imgdir="";
$path_parts = pathinfo($url);
$file_name = $path_parts['basename'];
$imgext = $path_parts['extension'];
if($imgext=='jpg' || $imgext=='JPG')
$src_img=imagecreatefromjpeg($target_path);
if($imgext=='gif' || $imgext=='GIF')
$src_img=imagecreatefromgif($target_path);
if($imgext=='png' || $imgext=='PNG')
$src_img=imagecreatefrompng($target_path);
if($imgext=='jpeg' || $imgext=='jpeg')
$src_img=imagecreatefromjpeg($target_path);
$size = getimagesize($target_path);
$dst_img = imagecreatetruecolor($size[0],$size[1]);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$size[0],$size[1],$size[0],$size[1]);
if(($imgext=='jpg') || ($imgext=='JPG') || ($imgext=='jpeg') || ($imgext=='JPEG'))
{
imagejpeg($dst_img, $imgdir.$file_name,90);
}else if(($imgext=='gif') || ($imgext=='GIF')){
imagegif($dst_img, $imgdir.$file_name,90);
}else if(($imgext=='png') || ($imgext=='PNG')){
imagepng($dst_img, $imgdir.$file_name,5);
}
}
create_image_by_url1($url);
Sunday, June 13, 2010
Enable Htaccess in localhost AppServ
Open AppSer installed folder in that find conf folder and find httpd.conf file. In that file find below line(LoadModule rewrite_module modules/mod_rewrite.so)
For Example In Windows: D:\AppServ\Apache2.2\conf\
"LoadModule rewrite_module modules/mod_rewrite.so" if hash is there before the line remove that hash("#") and save the file and restart the AppServer to work
For Example In Windows: D:\AppServ\Apache2.2\conf\
"LoadModule rewrite_module modules/mod_rewrite.so" if hash is there before the line remove that hash("#") and save the file and restart the AppServer to work
mysql command line windows
It is working for me like this
Set the path in command line to \mysql\bin i.e (in which directory mysql is installed)
For eg: (I had tried this one in localhost)
C:\AppServ\MySql\bin>
then enter a command mysql -u root -h localhost -p and "Press Enter" then it will ask for a password, then enter your password and "Press Enter" Then you got a message like this "Welcome to mysql moniter............... " like this
For testing type a command "Show databases;" without double Quotes now you can see the databases
Set the path in command line to \mysql\bin i.e (in which directory mysql is installed)
For eg: (I had tried this one in localhost)
C:\AppServ\MySql\bin>
then enter a command mysql -u root -h localhost -p and "Press Enter" then it will ask for a password, then enter your password and "Press Enter" Then you got a message like this "Welcome to mysql moniter............... " like this
For testing type a command "Show databases;" without double Quotes now you can see the databases
Saturday, January 30, 2010
Generate Random Value
function random_code()
{
$string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz0123456789";
$randval = '' ;
for($i = 0;$i <= 10;$i++)
{
$num = rand() % 62;
$tmp = substr($string, $num, 1);
$randval = $randval.$tmp;
}
echo $randval.uniqid();
}
random_code();
{
$string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz0123456789";
$randval = '' ;
for($i = 0;$i <= 10;$i++)
{
$num = rand() % 62;
$tmp = substr($string, $num, 1);
$randval = $randval.$tmp;
}
echo $randval.uniqid();
}
random_code();
Subscribe to:
Posts (Atom)