Advertisement
Guest User

m

a guest
Dec 21st, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. if(isset($_FILES['file'])) {
  4.     $file = $_FILES['file'];
  5.    
  6.     //File Properties
  7.         $file_name = $file['name'];
  8.         $file_tmp = $file['tmp_name'];
  9.         $file_size = $file['size'];
  10.         $file_error = $file['error'];
  11.  
  12.  
  13.     //Word out the file extensions
  14.         $file_ext = explode('.', $file_name);
  15.         $file_ext = strtolower(end($file_ext));
  16.        
  17.         $allowed = array('txt', 'jpg', 'php', 'jpeg');
  18.  
  19.         if(in_array($file_ext, $allowed)) {
  20.             if($file_error === 0) {
  21.                 if($file_size <= 2000000) {
  22.  
  23.                     $file_name_new = uniqid('', true) . '.' . $file_ext;
  24.                     $file_destination = 'zukrain/' . $file_name_new;
  25.  
  26.                     if(move_uploaded_file($file_tmp, $file_destination)) {
  27.                         echo $file_destination;
  28.                     }
  29.                 }
  30.             }
  31.         }
  32.  
  33.         if(file_exists($file_name)) {
  34.             echo 'File already exists.';
  35.         } else{
  36.             echo $file_destination;
  37.  
  38.         }
  39. }
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement