Easy way to start java script

Start java script code just need to follow some simple step. Java Script is basically scripting language. Which is called a client-side scripting language. Because of the all operation of java script occurred in users computer. Today millions of website used java script to make their website more attractive and more professional. It’s help to make very attractive look of your web page.
You can start Java Script with follow some simple step.

Step 1: Create a html file in your editor/IDE (You can write code in html file in body section)

Step 2: Then you need to initialized java script where you need to write code. To do this write/copy this code

<html>
    <head>
        <title>My First Java Script Code</title>
    </head>
    <body>
        <script type="text/javascript">
            // You need to write java script code here
        </script>
    </body>
</html>

 

Step 3:  After the initialization you have to write your code inside the ”<script type=”text/javascript”> Write code here </script>”. I am going to show an simple example .

 

<html>
    <head>
        <title>My First Java Script Code</title>
    </head>
    <body>
        <script type="text/javascript">
           document.write('This is my First Java Script Code');  // This is my first Java Script Code
        </script>
    </body>
</html>

 

 

Those are very basic step to start java script. I am trying to write some post about java script in feature. Hope you guys are enjoy it.

What is PHP Ternary Operator

PHP Ternary Operator is the Shorthand of if/else statement. It’s is important to know “What is it, How to use it ” for php programmer.

It’s simply said that the shorthand of if/else statement. It’s rally easy to use and reduce you code.

Ternary Operator using “(condition) ? (return true value) : (return false value)” for execute the statement.It’s called Ternary Operator because it’s use three operands, one condition, one result for true, one result for false. Hear is an example.

<?php
    $age=10;
    $Status= ($age<18)? “Child”:”Adult”;
    echo $Status;
?>

Output

Child

NB:  The most important thing of using it reduce your code ,save the executing time.Makes maintaining code quicker, easier.

 

Image Uploader Script in PHP

Recently I am developing my component library to make my library rich. Because it’s reduce my production time. For this reason I have developed the image uploading class. Almost every application need image uploading part. So that I have decided to make a class to for image uploading. Which will is very easy to use and no need to extra settings. Just copy the script and use it. I have made it open source so anyone can use it.

<?php
/*
* Image Upload Class
*/
class ImageUpload
{
    /**
     * @param null $Path         Custom path where uploaded image will be stored
     * @param null $MaximumSize  Custom Maximum size in (Bytes) will be passed.
     * @param array $AllowedType Custom extension type (JPG|GIF|PNG)
     * @param null $Option       Extra options as array where we can define 'Image File Name', blah blah blah
     *
     * @return string Here return/output will be a string (Message)
     */
    public function ImgUpload($Path = null, $MaximumSize = null, array $AllowedType = null, $Option = null)
    {
        if (isset($_POST['submit'])) {
            if (!empty($_FILES['ImgName']['name'])) {
                $ImageFile = $_FILES['ImgName'];
                if ($this->CheckSizeLimit($ImageFile, $MaximumSize)) {
                    if ($this->CheckImageType($ImageFile, $AllowedType)) {
                        if ($this->CheckPath($Path)) {
                            if ($this->CheckPermission($Path)) {
                                if (move_uploaded_file($ImageFile['tmp_name'], $Path . $ImageFile['name'])) {
                                    $result = 'Image has been Uploaded';
                                    return $result;
                                } else {
                                    return false;
                                }
                            } else {
                                return "Directory do not have write permission,";
                            }
                        } else {
                            return "Directory could not found,";
                        }
                    } else {
                        if (isset($AllowedType)) {
                            return "Please select " . implode('"/"', $AllowedType) . " Image";
                        } else {
                            return "Please select jpg/png/gif image";
                        }
                    }
                } else {
                    $result = "Image must me less then" . $MaximumSize . " byte";
                    return $result;
                }
            } else {
                $result = 'You do not select any file';
                return $result;
            }
        }
    }

    /**
     * @param $ImageFile        Image File which is image is selected for upload
     * @param null $MaximumSize Custom max image size passed
     *
     * @return bool Return true or false
     */
    function CheckSizeLimit($ImageFile, $MaximumSize = null)
    {
        if (isset($MaximumSize)) {
            if ($ImageFile['size'] < $MaximumSize) {
                return $ImageFile['size'];
            } else {
                return false;
            }
        } else {
            return true;
        }
    }

    /**
     * @param $ImageFile         Image File which is image is selected for upload
     * @param array $AllowedType Custom extension type (JPG|GIF|PNG)
     *
     * @return bool Return true or false
     */
    function CheckImageType($ImageFile, array $AllowedType = null)
    {
        if (isset($AllowedType)) {
            $i = 0;
            while ($i < sizeof($AllowedType)) {
                if ($ImageFile['type'] == "image/" . $AllowedType[$i]) {
                    return true;
                    break;
                }
                $i++;
            }
            return true;
        } else {
            if ($ImageFile['type'] == "image/jpg" || $ImageFile['type'] = "image/png" || $ImageFile['type'] == "image/gif") {
                return true;
            } else {
                return false;
            }
        }
    }

    /**
     * @param null Custom path where uploaded image will be stored
     *
     * @return bool Return true or false
     */
    function CheckPath($Path = null)
    {
        if (isset($Path)) {
            if (is_dir($Path)) {
                return true;
            } else {
                return false;
            }
        } else {
            return true;
        }
    }

    /**
     * @param null Custom path where uploaded image will be stored
     *
     * @return bool Return true or false
     */
    function CheckPermission($Path = null)
    {
        if (isset($Path)) {
            if (is_writable($Path)) {
                return true;
            } else {
                return false;
            }
        } else {
            return true;
        }
    }

    protected function ImgSize($ImgFile = null)
    {
        return "OK";
    }
}

This is the class structure. you can get this code from github. There I have written more details about it. I hope this will be helpful for you development.