Showing posts with label how_to. Show all posts
Showing posts with label how_to. Show all posts

Upload files using Ajax with Progress Bar

Uploading files using some server side languages are not a big deal. But, if we handle file uploads asynchronously, then we will be able to save time as well as some sudden overload to the server. Here is a very short working demo of code that uploads the file through Ajax. Actually, the file is uploaded via the server side code (here PHP), but the user don't have to step upto the next page and it feels like it is happening in client side.


  • 1.   Create an HTML file say, form.html and put the following code.

        <!DOCTYPE html>
        <html>
        <head>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
        <script src="http://malsup.github.com/jquery.form.js"></script>
        </head>
        <body>
        <div class="container">
        <h3 class="page-header">File Upload via Ajax with Progress Bar</h3>
        <div>
        <form action="upload.php" method="post" enctype="multipart/form-data">
        <input type="file" name="myfile"><br/>
        <input type="submit" value="Upload File to Server" class="btn btn-primary">
        </form>
        </div>
        <br/>
        <div class="progress">
        <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
        </div>
        <div class="percent">0%</div >
        </div>
        <p class="alert-info" id="status"></p>
        </div>
    
        <script>
        (function() {
        var bar = $('.progress-bar');
        var percent = $('.percent');
        var status = $('#status');
    
        $('form').ajaxForm({
        beforeSend: function() {
        status.empty();
        var percentVal = '0%';
        bar.width(percentVal);
        percent.html(percentVal);
        },
        uploadProgress: function(event, position, total, percentComplete) {
        var percentVal = percentComplete + '%';
        bar.width(percentVal);
        percent.html(percentVal);
        },
        success: function() {
        var percentVal = '100%';
        bar.width(percentVal);
        percent.html(percentVal);
        },
        complete: function(xhr) {
        status.html(xhr.responseText);
        status.addClass('alert');
        }
        });
    
        })();
        </script>
        </body>
        </html>

    2.  Now, handle the file upload into another file, upload.php as follows.
    <?php
        $uploaddir = 'E:/WebArtisans/';  //Path to a directory on your file system
        $uploadfile = $uploaddir . basename($_FILES['myfile']['name']);
    
        if (move_uploaded_file($_FILES['myfile']['tmp_name'], $uploadfile)) {
            echo "File is successfully uploaded.";
        } else {
            echo "Upload failed.";
        }
    ?>
    


    You can download the complete project from GitHub. Click here.

    Now, run and see. :)

    How to change the colors of folders?

    Creating Folders Having Different Colors In Windows:


    Windows doesn't allow us to create the colored folders by default. Hence we have to install a folder colorizer in our Windows to make it happen.


    1. Download the folder colorizer setup file from here.

    2. Install the downloaded setup file. If it asks to install the Microsoft .Net Framework, then install that too.

    3. After the successful installation, you can now proceed to add colors to the folders of you PC.

    4. Right click any folder to which you want to add color.

    5. Select "Colorize!" option and then select the color you want to add.


    6. Now refresh (F5) your computer to see the instant effect.

    Enjoy! :)

    Like us on Facebook.
    Web Artisans

    How to make own captcha in Joomla?

    The captcha can be used in many places to validate whether the user is real or not. It helps in maintaining the security of the site.
    The following function will make an image that contains a random captcha in Joomla.

    <?php
            public function makeCaptcha()
            {
                $string = JUserHelper::genRandomPassword ('6');
                $session = JFactory::getSession();
                $session->set('value', $string);
                $width      = 100;
                $height     = 25;
                $image      = imagecreatetruecolor ($width , $height);
                $text_color = imagecolorallocate($image, 130, 130, 130);
                $bg_color   = imagecolorallocate($image, 190, 190, 190);
                imagefilledrectangle($image, 0, 0, $width, $height, $bg_color);
                imagestring($image, 5, 16, 4, $string, $text_color);
                ob_start();
                imagejpeg ($image);
                $jpg = ob_get_clean ();
                return "data:image/jpeg;base64," . base64_encode($jpg);
            }
    ?>


    How to Compile a C Program on Ubuntu

    This article will guide you to compile a C program on Ubuntu using the GNU gcc/g++ compiler. Additions were made in order to simplify and clarify the creation of a C program on Ubuntu.

    1. Open up a terminal on Ubuntu and install the build-essential package by typing the following command in the terminal
    • sudo apt-get install build-essential
    • This will install the necessary C development libraries for your Ubuntu system to create C programs.
    2. Create a directory and a sub directory to hold your C programs and your main HelloWorld program.
    • mkdir -p CProgram/HelloWorld
    • We are using CProgram for the main directory to hold our created C programs and we are using the sub directory HelloWorld to hold our main program.
    3. Then we will change into our created directory by issuing the following command
    • cd CProgram/HelloWorld
    4. Next we will use a text editor such as gedit or nano to create our C or C++ source code using the following command.

    • gedit main.c
    • OR
    • nano main.c

    5. Enter the source code of your program. For example: the HelloWorld program is as follows:

    #include<stdio.h>
    #include<stdlib.h>
    int main()
    {
            printf("Hello World,\nThis is my first program compiled on 
    Ubuntu.");

            return 0;
    }

    6. Save the file as main.c and exit.

    7. Compiling your C program
    • Make sure you are in the CProgram/HelloWorld directory before you compile your C programs.
            Now type in the terminal:
    • gcc -Wall -W -Werror main.c -o HelloWorldC
    • The first line will invoke the GNU C compiler to compile the file main.c and output (-o) it to an executable called HelloWorldC.
    • The options -Wall -W and -Werror instruct the compiler to check for warnings.
    9. If you get the permission errors, you need to make the file executable. You can do this by issuing the following commands below
    • chmod +x HelloWorldC
    10. In order to execute your program you will have to type in the following commands.
    • ./HelloWorldC
    [Note: All the sentences that are highlighted are the commands that have to be written in Ubuntu terminal.]


    Hack Facebook Using BiNu App on Mobile.

    Follow following Steps to hack a Facebook account:

    1. At first, download biNu app on mobile phone. Click HERE to download. (Currently biNu is not supported on the iPhone & Windows Phone) 
    2. After finishing the download just install it (automatically installs in android).
    3. After that, Create a biNu's Account.
    4. Now visit biNu's homepage and you will see Facebook icon.
    5. Just click it you see Login screen of Facebook. It opens in the default browser of your phone.
    6. Don't Login into Facebook.
    7. Just copy the link from the address bar of your browser. (For example, the link should be like this:                                                                                                                                   http://m.facebook.com/login.php?app_id=378628085054&skip_api_login=1&cancel=http%3A%2F%2Fm.binu.com%2Ffclient%2Fauth.php%3Ferror_reason%3Duser_denied%26error%3Daccess_denied%26error_description%3DThe%2Buser%2Bdenied%2Byour%2Brequest.%26state%3D335074%257C46567955%257C36.252.21.228&fbconnect=1&next=https%3A%2F%2Fm.facebook.com%2Fdialog%2Fpermissions.request%3F_path%3Dpermissions.request%26app_id%3D378628085054%26client_id%3D378628085054%26redirect_uri%3Dhttp%253A%252F%252Fm.binu.com%252Ffclient%252Fauth.php%26display%3Dtouch%26response_type%3Dcode%26state%3D335074%257C46567955%257C36.252.21.228%26perms%3Duser_about_me%252Cfriends_about_me%252Cuser_status%252Cfriends_status%252Cread_friendlists%252Cread_stream%252Cread_mailbox%252Coffline_access%252Cpublish_stream%252Cxmpp_login%26fbconnect%3D1%26from_login%3D1&rcount=1&_rdr)
    8. After this visit https://bitly.com/ or https://goo.gl/ on your computer browser or mobile browser and get short link. (For example, the link should be like this: http://goo.gl/9HJCHa)
    9. Now send this short link to your friend (the victim) one at a time.
    10. After sending link to victim, refresh the Facebook at biNu's homepage. At this point the victim should have clicked on that link.
    11. Now enjoy. You can read messages, post on wall, see friends list, update status and many more.

    HAPPY HACKING. Do comment if you like.