Advertisement
chiabgigi

new folder_name_img

Apr 6th, 2020
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.37 KB | None | 0 0
  1. <?php
  2.  
  3. include_once 'data_config/config_dbTest.php';
  4. $title = 'test_01';
  5.  
  6. $message = '';
  7.  
  8. if(isset($_POST['submit_pic'])){
  9.  
  10.     $uname = $_POST['user_name'];
  11.  
  12.     $imgFile = $_FILES['uPic']['name'];
  13.     $tmp_dir = $_FILES['uPic']['tmp_name'];
  14.     $imgSize = $_FILES['uPic']['size'];
  15.  
  16.     $upload_dir = 'uploads/'.$uname; // upload directory
  17.  
  18.     mkdir($upload_dir, 0777);
  19.  
  20.     $imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension
  21.  
  22.     // valid image extensions
  23.     $valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
  24.  
  25.     // rename uploading image
  26.     $userPic = $imgFile;
  27.     // allow valid image file formats
  28.     if(in_array($imgExt, $valid_extensions)){
  29.         // Check file size '5MB'
  30.         if($imgSize < 5000000)    {
  31.             move_uploaded_file($tmp_dir,$upload_dir.'/'.$userPic);
  32.         }
  33.         else{
  34.             $errMSG = "Sorry, your file is too large.";
  35.         }
  36.     }
  37.     else{
  38.         $errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
  39.     }
  40.     $message = "Image uploaded $userPic";
  41.  
  42. }
  43.  
  44.  
  45. include 'header.php';
  46. include 'topbar.php';
  47. ?>
  48. <div class="container">
  49.     <div class="row">
  50.         <div class="col">
  51.             <form id="send_data" method="post" action="#" enctype="multipart/form-data">
  52.                 <div class="container">
  53.                 <div class="col">
  54.  
  55.                         <div class="form-group">
  56.                             <label for="user_name">User Name</label>
  57.                             <input type="text" name="user_name" id="user_name" class="form-control" pattern="[a-zA-Z ]+" required />
  58.                         </div>
  59.  
  60.                         <div class="form-group">
  61.                             <label for="">Profile Img.</label>
  62.                             <input class="input-group" type="file" name="uPic" accept="image/*" />
  63.                         </div>
  64.  
  65.                         <div class="form-group">
  66.                             <input type="submit" name="submit_pic" class="btn btn-primary" value="New Pic">
  67.                         </div>
  68.  
  69.                 </div>
  70.                 </div>
  71.             </form>
  72.             <?php
  73.             echo '<pre>';
  74.             print_r($_FILES);
  75.             echo '</pre>';
  76.  
  77.             ?>
  78.         </div>
  79.     </div>
  80. </div>
  81. <?php include ('footer.php'); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement