This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Friday 7 June 2013

how to upload many images at once in php

This tutorial tell you how to upload many images at once  in php.

 Just copy the code bellow and save it as "image.php" then open it in your server e.g. localhost.

<?php
if($_SERVER["REQUEST_METHOD"] == "POST")
 {
 $uploaded_images = count($_FILES['file']['name']);

 for ($i = 0; $i < $uploaded_images; $i++)
 {
 if($_FILES["file"]["error"][$i] > 0)
 {
  // if there is error in file uploading
   echo "Return Code: " . $_FILES["file"]["error"][$i] . "<br />";
 }
 else
 {

   // check if file already exit in "images" folder.
   if (file_exists("images/" . $_FILES["file"]["name"][$i]))
   {
    echo $_FILES["file"]["name"][$i] . " already exists. "."<br />";
   }
   else
   { 
    //move_uploaded_file function will upload your image.  if you want to resize image before uploading see this link http://b2atutorials.blogspot.com/2013/06/how-to-upload-and-resize-image-for.html
    if(move_uploaded_file($_FILES["file"]["tmp_name"][$i], "images/" . $_FILES["file"]["name"][$i]))
    {
     //If you want to stor its name in data base code will go here.
       //file has uploaded successfully, If you want to stor its name in data base. see this link http://b2atutorials.blogspot.com/2012/05/upload-image-into-folder-and-save-its.html
 
     echo $_FILES["file"]["name"][$i] . ' -image uploaded.' .'<br />';
    }
   }
 }
 }
 }
 ?>
<html>
<body>
    <form method="post" enctype="multipart/form-data">
    <input type="file" name="file[]" multiple/>
    <input type="submit" value="submit">
    </form>
</body>
</html>
    

    

how to upload and resize image for thumbnail in php

           

This tutorial tell you how to upload and resize image for thumbnail in php.

Just copy the code bellow and save it as "resize_image.php" then open it in your server e.g. localhost.
<?php
if($_SERVER["REQUEST_METHOD"] == "POST")
 {
 // By using the global PHP $_FILES array you can upload files from a client computer to the remote server.
 $image = $_FILES["file"]["name"];
 //get the name of the temporary copy of the file stored on the server.
 $uploadedfile = $_FILES['file']['tmp_name'];
 //get the type of the uploaded file.
 $image_type =$_FILES["file"]["type"];
 //imagecreatefrompng — Create a new image from file or URL because we are not sure user inputed file is png or with an other extention therefore we will use if else condition.
 if($image_type=='image/png' || $image_type=='image/x-png')
 {
  $src = imagecreatefrompng($uploadedfile);
 }
 elseif($image_type=='image/gif')
 {
  $src = imagecreatefromgif($uploadedfile);
 }
 elseif($image_type=='image/jpeg' || $image_type=='image/jpg' || $image_type == 'image/pjpeg')
 {
  $src = imagecreatefromjpeg($uploadedfile);
 }
 //getimagesize() this function — Get the size of an image which user inputed. we need orignal size for resizing the image in "imagecopyresampled" function.
 list($width,$height)=getimagesize($uploadedfile);
 //We have get orignal height and width by using list($width,$height)=getimagesize($uploadedfile);
 //Now set your own width and height which you want.
 $new_width=100;
 $new_height=100;
 // Bellow function Create a new true color image so that quality of your image don't change.
 $image_p=imagecreatetruecolor($new_width,$new_height);

 // Turn off alpha blending and set alpha flag // otherwise png's images background color will be black.
    imagealphablending($image_p, false);
    imagesavealpha($image_p, true);
 //Fucntion bellow will resize image
 imagecopyresampled($image_p,$src,0,0,0,0,$new_width,$new_height,$width,$height);

 $filename = "images/". $_FILES['file']['name'];

 if(move_uploaded_file($_FILES["file"]["tmp_name"], $filename))
 {
  if($image_type=='image/png' || $image_type=='image/x-png')
   imagepng($image_p,$filename,9) ;
  else
   imagejpeg($image_p,$filename,100);
  echo 'Image uploaded';
  imagedestroy($image_p);
  //file has uploaded successfully, store its name in data base. see this link http://b2atutorials.blogspot.com/2012/05/upload-image-into-folder-and-save-its.html
 }
 }
?>
<html>
<body>
    <form method="post" enctype="multipart/form-data">
    <input type="file" name="file">
    <input type="submit" value="submit">
    </form>
</body>
</html>
    

 

Tuesday 4 June 2013

how to store data into database easily and reset the form after successful submission

           

Code below will guide you how to store data into database easily. Save this as "save.php" and open it in your host e.g. localhost.
<?php
 session_start();
 // Assing value about your server to these variables for database connection
 $hostname_connect= "localhost";
 $database_connect= "olympic"; //"olympic" this is database name you may create your own database.
 $username_connect= "root";
 $password_connect= "";
 $connect_solning = mysql_connect($hostname_connect, $username_connect, $password_connect) or trigger_error(mysql_error(),E_USER_ERROR);
 @mysql_select_db($database_connect) or die (mysql_error());

//if you submit form data submited will be store in database
 if($_POST)
 {
 $key = mt_rand(); // this mt_rand() function genrates randum key for you
 $username = $_POST['username'];
 $email = $_POST['email'];
 $password = $_POST['password'];
 $passconf = $_POST['passconf'];
 $postal_code = $_POST['postal_code'];

 if($_POST['username']=='' || $_POST['email'] =='' || $_POST['password']=='' || $_POST['passconf']=='' || $_POST['postal_code']=='')
 {
  echo "Please fill all fields";
 }
 else
 {
 // save data info database where i have named table as "user" and this is query syntax INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...)
  $query = "INSERT INTO `user`(`username`,`email`,`password`,`postal_code`,`key`,`status`)VALUES('$username','$email','$password','$postal_code','$key','InActive')";
  $result=mysql_query($query);
   if(!$result)
   {
   echo "Not Saved.";
   }
   else
   {
    //store message in session this will display after redirection.
   $_SESSION["msg"] = "Data has been saved.";
   // line below will redirect you to "save.php" and your form will be reset/refreshed.
   header( "Location: save.php" );
   exit;
   }
 }
 }
 ?>
 <html>
 <body>
<?php
// if session has been set it will show message and unset session.
if(isset($_SESSION["msg"]))
{
 echo '<p style="color:#0C9; font-weight:bold; text-align:center;">'.$_SESSION["msg"].'</p>';
 unset($_SESSION["msg"]);
}
   
 ?>
 <form id='registeration' action='' method='post' >
 <fieldset >
 <legend>Register</legend>
 <label for='username' >Username*: </label><br/>
 <input type='text' name='username' id='username' value="<?php if(!empty($username)) echo $username ?>" maxlength="50" /><br/>
 <label for='email' >Email Address*:</label><br/>
 <input type='text' name='email' id='email' value="<?php if(!empty($email)) echo $email ?>" maxlength="50" /><br/>
 <label for='password' >Password*:</label><br/>
 <input type='password' name='password' id='password' maxlength="50" /><br/>
 <label for='passconf' >Confirm Password*:</label><br/>
 <input type='password' name='passconf' id='password' maxlength="50" /><br/>
 <label for='postal_code' >Postal Code*:</label><br/>
 <input type='text' name='postal_code' id='postal_code' value="<?php if(!empty($postal_code)) echo $postal_code ?>" maxlength="50" /><br/>
 <input type='submit' name='Submit' value='Submit' />
 </fieldset>
 </form>
 </body>
 </html>