Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $DB_HOST = 'localhost';
- $DB_USER = 'estgv15577';
- $DB_PASS = '********';
- $DB_NAME = 'estgv15577';
- try{
- $DB_con = new PDO("mysql:host={$DB_HOST};dbname={$DB_NAME}",$DB_USER,$DB_PASS);
- $DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- catch(PDOException $e){
- echo $e->getMessage();
- }
- error_reporting( ~E_NOTICE ); // avoid notice
- if(isset($_POST['btnsave']))
- {
- $imgFile = $_FILES['user_image']['name'];
- $tmp_dir = $_FILES['user_image']['tmp_name'];
- $imgSize = $_FILES['user_image']['size'];
- if(empty($imgFile)){
- $errMSG = "Please Select Image File.";
- }
- else
- {
- $upload_dir = 'http://193.137.7.33/~estgv15577/TrabalhoPI/Fotos/'; // upload directory
- $imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension
- // valid image extensions
- $valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
- // rename uploading image
- $userpic = rand(1000,1000000).".".$imgExt;
- // allow valid image file formats
- if(in_array($imgExt, $valid_extensions)){
- // Check file size '5MB'
- if($imgSize < 5000000) {
- move_uploaded_file($tmp_dir,$upload_dir.$userpic);
- }
- else{
- $errMSG = "Sorry, your file is too large.";
- }
- }
- else{
- $errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
- }
- }
- // if no error occured, continue ....
- if(!isset($errMSG))
- {
- $stmt = $DB_con->prepare('INSERT INTO IMAGEM(URL_IMAGEM) VALUES(:upic)');
- $stmt->bindParam(':upic',$userpic);
- if($stmt->execute())
- {
- $successMSG = "new record succesfully inserted ...";
- }
- else
- {
- $errMSG = "error while inserting....";
- }
- }
- }
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="ISO-8859-1">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, shrink-to-fit=no, initial-scale=1">
- <meta name="description" content="">
- <meta name="author" content="">
- <title>Crtic-Viseu</title>
- <!-- Bootstrap Core CSS -->
- <link href="http://193.137.7.33/~estgv15577/TrabalhoPI/CSS/bootstrap.min.css" rel="stylesheet">
- <!-- Custom CSS -->
- <link href="http://193.137.7.33/~estgv15577/TrabalhoPI/CSS/simple-sidebar.css" rel="stylesheet">
- <script src="http://193.137.7.33/~estgv15577/TrabalhoPI/JS/jquery.min.js"></script>
- <script src="http://193.137.7.33/~estgv15577/TrabalhoPI/JS/bootstrap.min.js"></script>
- </head>
- </head>
- <style>
- </style>
- <body>
- <form method="post" enctype="multipart/form-data" class="form-horizontal">
- <table class="table table-bordered table-responsive">
- <tr>
- <td><label class="control-label">Profile Img.</label></td>
- <td><input class="input-group" type="file" name="user_image" accept="image/*" /></td>
- </tr>
- <tr>
- <td colspan="2"><button type="submit" name="btnsave" class="btn btn-default">
- <span class="glyphicon glyphicon-save"></span> save
- </button>
- </td>
- </tr>
- </table>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement