Tuesday 9 September 2014

multiple file upload php script

In this php tutorial let us check multiple file upload functionality using php script. This multiple file upload php script will help you to upload multiple files to your website very easily. This multiple file upload php script will also help you to restrict upload file type. Eg: you can tell the script to upload pdf file only, or upload pdf,jpg,doc file only ect by simply giving some configuring option. Let us check how you can write the code for uploading multiple file in detail. First of all let us check the html part. In the html we need a file uploading functionality. So The HTML code for multiple file upload is
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="files[]" multiple/>
<input type="submit" value="submit"/>
</form>
In the above html code it will give you an option to select multiple files. In the form for uploading files you need to specify enctype to multipart/form-data. This is an impotent think. if you didn’t give this option your file upload will not work. in the input field i specified name=”upload_files[]“ this is because if it will take care of multiple file upload_files[] will give an array of file names. also don’t forget to give multiple in the input filed. The next is the php section. In this php section we are going to write the php script to upload multiple file. Let us check it in detail.

function
upload_multiple_file($file,$file_dir="user_files") {

$overwrite=0;
$allowed_file_type = array("pdf","ppt","pptx","xls"."xlxs","doc","docx","jpg", "jpeg", "png", "gif");
$max_file_size_check=1;
$max_file_size = 2097152;

foreach($_FILES['files']['name'] as $fkey=> $fname){

$ext = pathinfo($fname, PATHINFO_EXTENSION);
if (!in_array($ext, $allowed_file_type)) {

return "unsupported file format";
break;
}

}

foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){

$file_name = $_FILES['files']['name'][$key];

$file_size =$_FILES['files']['size'][$key];

$file_tmp_name =$_FILES['files']['tmp_name'][$key];

$file_type=$_FILES['files']['type'][$key];

if($max_file_size_check < 1) {
if($file_size > $max_file_size){

$fsize=$max_file_size/1048576;
return    'File size must be less than '.$fsize.' MB';
break;

}
}

if(is_dir($file_dir)==false){

$status =  mkdir("$file_dir", 0700);

if($status < 1){

return "unable to create  diractory $file_dir ";

}

}

if(is_dir($file_dir)){

if($overwrite < 1){

move_uploaded_file($file_tmp_name,"$file_dir/".$file_name);

}

}

//  $file_upload_query="INSERT into user_uploads (`u_id`,`file_name`,`file_type`) VALUES('$user_id','$file_name','$file_size','$file_type'); ";
//mysql_query($file_upload_query);

}

return "Success";

}
In the above code upload_multiple_file is the function which is doing all multiple file upload functionality. The upload_multiple_file function need two parameter. The first one is upload file information, and the second one is the file directory where you need to upload the file. The $overwrite=0; variable is used for checking whether the file having the same name need to be overwrite or not. If you want to overwrite the file make $overwrite to 1. $overwrite=1; The $allowed_file_type array is having the list of allowed file types. If you want to remove or add any file type you can change the $allowed_file_type array accordingly. The $max_file_size_check=1 is for file size checking. If $max_file_size_check=1; the function will check the upload file size. If $max_file_size_check=0; the function will slip the file size check. The $max_file_size = 2097152; is the maximum allowed size of the upload file. In this I also added a mysql insert query $file_upload_query this query will help you to insert the uploaded file information to database. If you want to use the database insert functionality you can uncomment those lines. If you want to store the uploaded file information in database you need to create a database table. You can create sql table by using sql query below. Sql part .

CREATE
TABLE `test`.`user_uploads` (
`id` INT( 11 ) NOT NULL ,
`u_id` INT( 11 ) NOT NULL ,
`file_name` VARCHAR( 255 ) NOT NULL ,
`file_type` VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM ;
[highlight textcolor="#00aae8" bgcolor="#fff"]The usage of the function[/highlight] is below.

if
(isset($_FILES['files'])){

$res =  upload_multiple_file($_FILES['files'],"user_files");
echo $res;

}
So let us put all code together, so that it will easy to understand multiple file upload php script tutorial.

<?php

if(isset($_FILES['files'])){
$res =  upload_multiple_file($_FILES['files'],"user_files");
echo $res;
}

function upload_multiple_file($file,$file_dir="user_files") {

$overwrite=0;
$allowed_file_type= array("pdf","ppt","pptx","xls"."xlxs","doc","docx","jpg", "jpeg", "png", "gif");
$max_file_size = 2097152;

foreach($_FILES['files']['name'] as $fkey=> $fname){

$ext = pathinfo($fname, PATHINFO_EXTENSION);
if (!in_array($ext, $allowed_file_type)) {

return "unsupported file format";
break;
}

}

foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){

$file_name = $_FILES['files']['name'][$key];

$file_size =$_FILES['files']['size'][$key];

$file_tmp_name =$_FILES['files']['tmp_name'][$key];

$file_type=$_FILES['files']['type'][$key];

if($max_file_size_check >0) {
if($file_size > $max_file_size){

$fsize=$max_file_size/1048576;
return    'File size must be less than '.$fsize.' MB';
break;

}
}

if(is_dir($file_dir)==false){

$status =  mkdir("$file_dir", 0700);

if($status < 1){

return "unable to create  diractory $file_dir ";

}

}

if(is_dir($file_dir)){

if($overwrite < 1){

move_uploaded_file($file_tmp_name,"$file_dir/".$file_name);

}

}

//  $file_upload_query="INSERT into user_uploads (`u_id`,`file_name`,`file_type`) VALUES('$user_id','$file_name','$file_size','$file_type'); ";
//mysql_query($file_upload_query);

}

return "Success";

}

?>

<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="files[]" multiple/>
<input type="submit" value="submit"/>
</form>
Download Here

Tuesday 12 August 2014

Indian states list in php array format

I listed the Indian country states in PHP array format. The array contains two digit state code and state name. India has 28 states and seven Union territory, so totally 35 states are listed in the array. I hope it will help someone.



28 Indian States list



$indian_states = array (
 'AP' => 'Andhra Pradesh',
 'AR' => 'Arunachal Pradesh',
 'AS' => 'Assam',
 'BR' => 'Bihar',
 'CT' => 'Chhattisgarh',
 'GA' => 'Goa',
 'GJ' => 'Gujarat',
 'HR' => 'Haryana',
 'HP' => 'Himachal Pradesh',
 'JK' => 'Jammu & Kashmir',
 'JH' => 'Jharkhand',
 'KA' => 'Karnataka',
 'KL' => 'Kerala',
 'MP' => 'Madhya Pradesh',
 'MH' => 'Maharashtra',
 'MN' => 'Manipur',
 'ML' => 'Meghalaya',
 'MZ' => 'Mizoram',
 'NL' => 'Nagaland',
 'OR' => 'Odisha',
 'PB' => 'Punjab',
 'RJ' => 'Rajasthan',
 'SK' => 'Sikkim',
 'TN' => 'Tamil Nadu',
 'TR' => 'Tripura',
 'UK' => 'Uttarakhand',
 'UP' => 'Uttar Pradesh',
 'WB' => 'West Bengal',
);


7 Union Territory



$indian_union_territory  = array (
 'AN' => 'Andaman & Nicobar',
 'CH' => 'Chandigarh',
 'DN' => 'Dadra and Nagar Haveli',
 'DD' => 'Daman & Diu',
 'DL' => 'Delhi',
 'LD' => 'Lakshadweep',
 'PY' => 'Puducherry',
);


All Indian States list



$indian_all_states  = array (
 'AP' => 'Andhra Pradesh',
 'AR' => 'Arunachal Pradesh',
 'AS' => 'Assam',
 'BR' => 'Bihar',
 'CT' => 'Chhattisgarh',
 'GA' => 'Goa',
 'GJ' => 'Gujarat',
 'HR' => 'Haryana',
 'HP' => 'Himachal Pradesh',
 'JK' => 'Jammu & Kashmir',
 'JH' => 'Jharkhand',
 'KA' => 'Karnataka',
 'KL' => 'Kerala',
 'MP' => 'Madhya Pradesh',
 'MH' => 'Maharashtra',
 'MN' => 'Manipur',
 'ML' => 'Meghalaya',
 'MZ' => 'Mizoram',
 'NL' => 'Nagaland',
 'OR' => 'Odisha',
 'PB' => 'Punjab',
 'RJ' => 'Rajasthan',
 'SK' => 'Sikkim',
 'TN' => 'Tamil Nadu',
 'TR' => 'Tripura',
 'UK' => 'Uttarakhand',
 'UP' => 'Uttar Pradesh',
 'WB' => 'West Bengal',
 'AN' => 'Andaman & Nicobar',
 'CH' => 'Chandigarh',
 'DN' => 'Dadra and Nagar Haveli',
 'DD' => 'Daman & Diu',
 'DL' => 'Delhi',
 'LD' => 'Lakshadweep',
 'PY' => 'Puducherry',
);

Saturday 14 June 2014

jQuery Change Opacity of Image on Mouseover

Here I will explain how to use jQuery to change image opacity on mouseover using jQuery or change opacity of image on hover using jQuery.


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Change Image Opacity on Mouse Over</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function() {
$("#logoimage").css("opacity", 0.5);
$("#logoimage").hover(function() {
$(this).animate({ opacity: 1.0 }, 500);
}, function() {
$(this).animate({ opacity: 0.5 }, 500);
});
})
</script>
</head>
<body>
<form id="form1">
<div>
<img id="logoimage" src="FinalLogo.png" />
</div>
</form>
</body>
</html>


jQuery Change Opacity of Image on Mouseover

Tuesday 3 June 2014

Full width image slider for your homepage

In this tutorial i want to show you how easily you can change the way of how homeslider appears in default-bootstrap template in PrestaShop 1.6. As you know default homeslider module is a part of homepage of your shop. It appears right below the main menu. Near the module (on right hand side) you can see two small banners. In this guide i will show you how to remove these banners, and how to change width of slider to 100%.


full-width-slider


Disable to small banners on the right hand side


First step in our modificaiton: we have to remove two small banners on the right hand side of the main slider. These images are a part of “theme configurator” module and to remove these banners we just have to disable this module. But be aware, don’t disable module at all, just disable it in hook named displayTopColumn. In this case go to modules > positions tab in back office. Search there for modules list named displayTopColumn. You will see there two modules (by default there are two modules). Click on edit button near theme configurator and click on “unhook”, exactly as i show on image below.


Unhooking theme configurator module from displayTopColumn position


1-unhook-theme-configurator-from-theme-configurator


After this action two small baners will disappear but they will left blank empty space. So we have to fill this blank space with our slider module. Then it will have full width :)


Change width of the banner


Go to modules > modules tab and search for “image slider for your homepage” addon. Click on configure button near this module and then – you will be redirected to module configuration page. In the main “settings” form change Max width param value from 799px to 1170px (just type 1170 in this field exactly as i show below). Wondering why 1170? 1170 is a width of the main page container.


changing width of the default home slider module from 799 to 1170


2a-image-slider-full-width-prestashop-1-6


Removing banners with width smaller than 1170


Due to the fact that we changed width of the slider window, we have to remove old smaller than 1170px (width) pictures that we uploaded. We have to upload pictures with min-width: 1170px; On screenshot below i show how to remove actual slides. Below the “settings” form (where you changed width of slider) you can manage already uploaded slides. Just hit on delete button like i show:


removing default slides with old small width value (799)


2b-remove-slides-imageslider


Upload images with new sizes


If you removed all old slides with wrong width – now it’s time to upload new pictures. So, you have to prepare own slides for example in photoshop or other desktop software. Create slides with width at least 1170 and upload them to slider. They will appear as a “full” width slides, like i show on effect image at the bottom of this article. After upload new slides – don’t forget to Enable them :)


New slide uploaded to website


2c-upload-new-images-correct-size


effect of our modifications: full width slider in prestashop 1.6


0-slider-full-width-prestashop-1-6


 


 



Full width image slider for your homepage

Thursday 8 May 2014

Disabling Right Mouse Click Using jQuery

If you are to disable right click on your web browser, you can use the following piece of code:



$(document).ready(function(){
$(document).bind("contextmenu",function(e){
return false;
});
});

Determine Browser


Suppose you were to determine the browser type of the browser currently in use. You can use the following piece of code to do this:


$(document).ready(function() {
// If the browser type if Mozilla Firefox
if ($.browser.mozilla && $.browser.version >= "1.8" ){
// some code
}
// If the browser type is Opera
if( $.browser.opera)
{
// some code
}
// If the web browser type is Safari
if( $.browser.safari )
{
// some code
}
// If the web browser type is Chrome
if( $.browser.chrome)
{
// some code
}
// If the web browser type is Internet Explorer
if ($.browser.msie && $.browser.version 6)
{
// some code
}
});


Disabling Right Mouse Click Using jQuery

Tuesday 15 April 2014

save images into database using base64encoding

In this tutorial tip let us check how can we save images into database using base64encoding. Usually we will upload an image into the server and keep the image file name into the database, and use that image file name if we want to use that image right?. Yea but here what I’m going to show is how can we save the image itself into the database.


For that Let us create a database table.



CREATE TABLE `test`.`user_pic` (
`id`
INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`img` LONGTEXT NOT NULL ,
`type` VARCHAR( 10 ) NOT NULL
) ENGINE = MYISAM ;

So we are using this table for saving the image.

the next part is the image upload part.



<?php



$hostname = 'localhost';


$dbname = 'test';


$db_user = 'root';


$db_password = '';


$link = mysql_connect($hostname,$db_user,$db_password);


$connect = mysql_select_db($dbname,$link)or die(mysql_error());



if(isset($_FILES['file'])){



    $allowed_file_type = array("jpg", "jpeg", "png", "gif");


    $max_file_size = 524288;



   $file_dir="uploads";



    $file_name = $_FILES['file']['name'];



    $file_size =$_FILES['file']['size'];



    $file_tmp_name =$_FILES['file']['tmp_name'];



    $file_type=$_FILES['file']['type'];



    $ext = pathinfo($file_name, PATHINFO_EXTENSION);



    if (in_array($ext, $allowed_file_type)) {



          if($file_size > $max_file_size){



                $fsize=$max_file_size/1048576;


                echo 'File size must be less than '.$fsize.' MB';


                break;



            }



            $str = file_get_contents($file_tmp_name);


            $b64img=base64_encode($str);


            $sql="INSERT INTO `user_pic` (`img` ,`type`)VALUES ('$b64img', '$ext')";


            mysql_query($sql);



    }


}


?>


<form action="" enctype="multipart/form-data" method="POST">Choose a file to upload : <input type="file" multiple="multiple" name="file" />


 <input type="submit" /></form>



So by using this code you can easly upload an image into the database.





$str = file_get_contents($file_tmp_name);

$b64img=base64_encode($str);




This code is doing the image encoding part. This line of code first read image file then convert it into base64_encode.

If you don’t want to encode it to base64_encode you can remove this line of code.


if you want to get the image from database use this code.




$hostname = 'localhost';


$dbname = 'test';


$db_user = 'root';


$db_password = '';


$link = mysql_connect($hostname,$db_user,$db_password);


$connect = mysql_select_db($dbname,$link)or die(mysql_error());


$sql="SELECT * FROM `user_pic` WHERE `id`=5";


$res=mysql_query($sql);


$data=mysql_fetch_assoc($res);


$image= $data['img'];


$image_type= $data['type'];


$res=base64_decode($image);


header("Content-type:image/$image_type");



So using this simple technique you can easily save images into database using base64encoding. ;)



save images into database using base64encoding

Monday 24 March 2014

PHP Training in Vadodara

Why PHP ?


php web development due to its increasing advantages, its demand is growing in web development field. It is essential that business developers are aware of PHP development to realize their choices better. Along with Linux and MySQL the technology has appeared as one of the most helpful and free web programming platforms. Whether you need a simple website or a mighty database in the backend, a forum location or a client amicable content administration scheme, PHP offers you everything and that are free, except for charges of PHP developers. If a business unit requests a complete and purposeful website for lesser value then PHP Web development is the eventual choice.


The IT experts at Paceinfonet Web Solution Pvt Ltd have extensive experience and knowledge of LAMP | WAMP technologies and other open source software, and can quickly built web and batch processing applications in the areas of Content Management Systems, e-Commerce, Business Directoies, Forums, Marketing, Sales and Workflow Systems, Transport and many others.


PHP Training in Vadodara


PHP MySql Training in Vadodara


PHP, a opensource powerful tool for making dynamic and interactive Web pages, is the widely-used, free and efficient alternative to competitors such as Microsoft’s ASP .Net


Why PHP Live training at Paceinfonet Web Solution Pvt Ltd – Vadodara ?


The professional PHP training can’t provide by an institute. You can get it by an IT Company only.


Paceinfonet Web Solution Pvt Ltd have many satisfied clients with PHP and MySql web application development. Please check few of our latest websites developed using PHP, MySQL, Prestashop and WordPress.


We have designed special PHP course with practical knowledge of dynamic website creation jobs. Here you will learn about PHP in a very simple way, and how to execute scripts on your server.


PHP & MySQL are two of the most popular open source technologies to emerge during the past decade. PHP is a powerful language for writing server-side Web applications. MySQL is the world’s most popular open source database. Together, these two technologies provide you a powerful platform for building database-driven Web applications.


PHP & MySQL training course in Vadodara by IT Company. Our Expert Developer teach you everything they need to build data-driven Web sites using PHP & MySQL successfully.


WordPress Training in Vadodara


WordPress is web software you can use to create a beautiful website. It’s both free and priceless at the same time.


Ecommerce (Prestashop) Training in Vadodara


Prestashop is web software you can use to create a beautiful Ecommerce website. It’s both free and priceless at the same time. Ecommerce website is most demanded in current time. e.g flipkart.


 For Further Information Please email us on vadodara@paceinfonet.com Or call us on 0265 3006513



PHP Training in Vadodara