atanasovetr

Image Upload

Jan 26th, 2021
659
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.    if(isset($_FILES['snimka'])){
  3.       $errors= array();
  4.       $file_name = $_FILES['snimka']['name'];
  5.       $file_tmp =$_FILES['snimka']['tmp_name'];
  6.       $file_type=$_FILES['snimka']['type'];
  7.       $file_ext=strtolower(end(explode('.',$_FILES['snimka']['name'])));
  8.      
  9.       $extensions= array("jpeg","jpg","png");
  10.      
  11.       if(in_array($file_ext,$extensions)=== false){
  12.          $errors[]="Extension not allowed, please choose a JPEG or PNG file.";
  13.       }
  14.      
  15.       if(empty($errors)==true){
  16.          move_uploaded_file($file_tmp,"images/".$file_name);
  17.          echo "Success";
  18.       }else{
  19.          print_r($errors);
  20.       }
  21.    }
  22. ?>
  23. <html>
  24.    <body>
  25.      
  26.       <form action="" method="POST" enctype="multipart/form-data">
  27.          <input type="file" name="snimka" />
  28.          <input type="submit"/>
  29.       </form>
  30.      
  31.    </body>
  32. </html>
RAW Paste Data