Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once 'data_config/config_dbTest.php';
- $title = 'test_01';
- $message = '';
- if(isset($_POST['submit_pic'])){
- $uname = $_POST['user_name'];
- $imgFile = $_FILES['uPic']['name'];
- $tmp_dir = $_FILES['uPic']['tmp_name'];
- $imgSize = $_FILES['uPic']['size'];
- $upload_dir = 'uploads/'.$uname; // upload directory
- mkdir($upload_dir, 0777);
- $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 = $imgFile;
- // 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.";
- }
- $message = "Image uploaded $userPic";
- }
- include 'header.php';
- include 'topbar.php';
- ?>
- <div class="container">
- <div class="row">
- <div class="col">
- <form id="send_data" method="post" action="#" enctype="multipart/form-data">
- <div class="container">
- <div class="col">
- <div class="form-group">
- <label for="user_name">User Name</label>
- <input type="text" name="user_name" id="user_name" class="form-control" pattern="[a-zA-Z ]+" required />
- </div>
- <div class="form-group">
- <label for="">Profile Img.</label>
- <input class="input-group" type="file" name="uPic" accept="image/*" />
- </div>
- <div class="form-group">
- <input type="submit" name="submit_pic" class="btn btn-primary" value="New Pic">
- </div>
- </div>
- </div>
- </form>
- <?php
- echo '<pre>';
- print_r($_FILES);
- echo '</pre>';
- ?>
- </div>
- </div>
- </div>
- <?php include ('footer.php'); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement