SHARE
TWEET

Untitled

a guest Dec 29th, 2016 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.      $DB_HOST = 'localhost';
  4.      $DB_USER = 'estgv15577';
  5.      $DB_PASS = '********';
  6.      $DB_NAME = 'estgv15577';
  7.  
  8.      try{
  9.       $DB_con = new PDO("mysql:host={$DB_HOST};dbname={$DB_NAME}",$DB_USER,$DB_PASS);
  10.       $DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  11.      }
  12.      catch(PDOException $e){
  13.       echo $e->getMessage();
  14.      }
  15.       error_reporting( ~E_NOTICE ); // avoid notice
  16.  
  17.      if(isset($_POST['btnsave']))
  18.      {
  19.  
  20.       $imgFile = $_FILES['user_image']['name'];
  21.       $tmp_dir = $_FILES['user_image']['tmp_name'];
  22.       $imgSize = $_FILES['user_image']['size'];
  23.  
  24.  
  25.       if(empty($imgFile)){
  26.        $errMSG = "Please Select Image File.";
  27.       }
  28.       else
  29.       {
  30.        $upload_dir = 'http://193.137.7.33/~estgv15577/TrabalhoPI/Fotos/'; // upload directory
  31.  
  32.        $imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension
  33.  
  34.        // valid image extensions
  35.        $valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
  36.  
  37.        // rename uploading image
  38.        $userpic = rand(1000,1000000).".".$imgExt;
  39.  
  40.        // allow valid image file formats
  41.        if(in_array($imgExt, $valid_extensions)){  
  42.         // Check file size '5MB'
  43.         if($imgSize < 5000000)    {
  44.          move_uploaded_file($tmp_dir,$upload_dir.$userpic);
  45.         }
  46.         else{
  47.          $errMSG = "Sorry, your file is too large.";
  48.         }
  49.        }
  50.        else{
  51.         $errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";  
  52.        }
  53.       }
  54.  
  55.  
  56.       // if no error occured, continue ....
  57.       if(!isset($errMSG))
  58.       {
  59.        $stmt = $DB_con->prepare('INSERT INTO IMAGEM(URL_IMAGEM) VALUES(:upic)');
  60.        $stmt->bindParam(':upic',$userpic);
  61.  
  62.  
  63.        if($stmt->execute())
  64.        {
  65.         $successMSG = "new record succesfully inserted ...";
  66.        }
  67.        else
  68.        {
  69.         $errMSG = "error while inserting....";
  70.        }
  71.       }
  72.      }
  73.     ?>
  74.  
  75.     <!DOCTYPE html>
  76.     <html lang="en">
  77.  
  78.     <head>
  79.  
  80.         <meta charset="ISO-8859-1">
  81.         <meta http-equiv="X-UA-Compatible" content="IE=edge">
  82.         <meta name="viewport" content="width=device-width, shrink-to-fit=no, initial-scale=1">
  83.         <meta name="description" content="">
  84.         <meta name="author" content="">
  85.  
  86.         <title>Crtic-Viseu</title>
  87.  
  88.         <!-- Bootstrap Core CSS -->
  89.         <link href="http://193.137.7.33/~estgv15577/TrabalhoPI/CSS/bootstrap.min.css" rel="stylesheet">
  90.  
  91.         <!-- Custom CSS -->
  92.         <link href="http://193.137.7.33/~estgv15577/TrabalhoPI/CSS/simple-sidebar.css" rel="stylesheet">
  93.  
  94.          <script src="http://193.137.7.33/~estgv15577/TrabalhoPI/JS/jquery.min.js"></script>
  95.           <script src="http://193.137.7.33/~estgv15577/TrabalhoPI/JS/bootstrap.min.js"></script>
  96.  
  97.     </head>
  98.     </head>
  99.      <style>
  100.  
  101.      </style>
  102.     <body>
  103.  
  104.     <form method="post" enctype="multipart/form-data" class="form-horizontal">
  105.  
  106.      <table class="table table-bordered table-responsive">
  107.  
  108.         <tr>
  109.          <td><label class="control-label">Profile Img.</label></td>
  110.             <td><input class="input-group" type="file" name="user_image" accept="image/*" /></td>
  111.         </tr>
  112.  
  113.         <tr>
  114.             <td colspan="2"><button type="submit" name="btnsave" class="btn btn-default">
  115.             <span class="glyphicon glyphicon-save"></span> &nbsp; save
  116.             </button>
  117.             </td>
  118.         </tr>
  119.  
  120.         </table>
  121.  
  122.     </form>
  123.  
  124.  
  125.  
  126.     </body>
  127.     </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top