Thursday, 21 March 2013

How to setup a secured browse button for imges in your web page

Following is the code for secured browse button on a web page. Just type this code in your web page and setup a secured browse button on your web page ....
<?php
if (isset($_POST['Upload'])) {

            $target_path = DVWA_WEB_PAGE_TO_ROOT."hackable/uploads/";
            $target_path = $target_path . basename($_FILES['uploaded']
            ['name']);
            $uploaded_name = $_FILES['uploaded']['name'];
            $uploaded_ext = substr($uploaded_name, strrpos($uploaded_name,
            '.') + 1);
            $uploaded_size = $_FILES['uploaded']['size'];

            if (($uploaded_ext == "jpg" || $uploaded_ext == "JPG" ||
            $uploaded_ext == "jpeg" || $uploaded_ext == "JPEG") &&
            ($uploaded_size < 100000)){


                if(!move_uploaded_file($_FILES['uploaded']['tmp_name'],
                $target_path)) {
                  
                    echo '<pre>';
                    echo 'Your image was not uploaded.';
                    echo '</pre>';
              
                  } else {
              
                    echo '<pre>';
                    echo $target_path . ' succesfully uploaded!';
                    echo '</pre>';
                  
                    }
            }
          
            else{
              
                echo '<pre>';
                echo 'Your image was not uploaded.';
                echo '</pre>';

            }
        }
  ?>

No comments:

Post a Comment