Advertisement
Dexter2016

Upload-class

Jul 4th, 2014
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.13 KB | None | 0 0
  1. <?php
  2. $uni_id = 123456789;
  3.  
  4.  
  5. if(isset($_FILES['img'])){
  6.     $img = $_FILES['img'];
  7.    
  8.     print_r($img);
  9.     echo "<br />";
  10.     // File Properties
  11.     $img_name  = $img['name'];
  12.     $img_tmp   = $img['tmp_name'];
  13.     $img_size  = $img['size'];
  14.     $img_error = $img['error'];
  15.  
  16.     // Work Out The File extension
  17.     $img_ext     = explode('.', $img_name);   // Java = split to array
  18.     $img_ext     = strtolower(end($img_ext)); // last index the array ( file_ext )
  19.     $allowed_img = array('jpg','jpeg','png');
  20.  
  21.     if (in_array($img_ext, $allowed_img))    {
  22.         if ($img_error === 0) {
  23.  
  24.             if ($img_size <= 4194000) { // max 4 MB
  25.                     echo "3";
  26.  
  27.                 $img_name_new = $uni_id.'.'.$img_ext;  // change this to book name ( Random )
  28.  
  29.                 $path_img     = "../books/".$uni_id.'/';            // Create a folder if it doesn't already exist  (need work)
  30.                 if (!file_exists($path_img)) { mkdir($path_img, 0777, true);        echo "4";
  31. }
  32.  
  33.                 $img_destination = $path_img.$img_name_new;
  34.                 if (move_uploaded_file($img_tmp, $img_destination)) {
  35.                             echo "5";
  36.  
  37.                 }
  38.  
  39.             }
  40.         }
  41.     }
  42.  
  43. }
  44. ?>
  45.  
  46. <?php
  47. if(isset($_FILES['file'])){
  48.     $file = $_FILES['file'];
  49.    
  50.     print_r($file);
  51.         echo "<br />";
  52.  
  53.     // File Properties
  54.     $file_name  = $file['name'];
  55.     $file_tmp   = $file['tmp_name'];
  56.     $file_size  = $file['size'];
  57.     $file_error = $file['error'];
  58.  
  59.     // Work Out The File extension
  60.     $file_ext = explode('.', $file_name);   // Java = split to array
  61.     $file_ext = strtolower(end($file_ext)); // last index the array ( file_ext )
  62.     $allowed  = array('rar','zip','7z');
  63.  
  64.     if (in_array($file_ext, $allowed))   {
  65.         if ($file_error === 0) {   
  66.             if ($file_name <= 268400000 ) { // max 100 MB
  67.                              
  68.                 $file_name_new = $uni_id.'.'.$file_ext;  // change this to book name ( Random )
  69.  
  70.                 $path = "../books/".$uni_id.'/';   // Create a folder if it doesn't already exist  
  71.                 if (!file_exists($path)) { mkdir($path, 0777, true); }
  72.  
  73.                 $file_destination = $path.$file_name_new;
  74.                 if (move_uploaded_file($file_tmp, $file_destination)) {
  75.  
  76.                 }
  77.  
  78.             }
  79.         }
  80.     }
  81.  
  82. }
  83. ?>
  84.  
  85.  
  86.  
  87. <?php
  88. if(isset($_FILES['up_book'])){
  89.     $up_book = $_FILES['up_book'];
  90.    
  91.     print_r($up_book);
  92.         echo "<br />";
  93.  
  94.     // up_book Properties
  95.     $up_book_name  = $up_book['name'];
  96.     $up_book_tmp   = $up_book['tmp_name'];
  97.     $up_book_size  = $up_book['size'];
  98.     $up_book_error = $up_book['error'];
  99.  
  100.     // Work Out The up_book extension
  101.     $up_book_ext = explode('.', $up_book_name);    // Java = split to array
  102.     $up_book_ext = strtolower(end($up_book_ext));  // last index the array ( up_book_ext )
  103.     $allowed_BOOK   = array('pdf','doc','docx','epub','ppt','pptx');
  104.  
  105.     if (in_array($up_book_ext, $allowed_BOOK))   {
  106.         if ($up_book_error === 0) {
  107.             if ($up_book_name <= 104900000) { // max 100 MB
  108.            
  109.                 $up_book_name_new = strtolower($up_book_name).'.'.$up_book_ext;  // change this to book name
  110.  
  111.                 $path_up_book = "../books/".$uni_id.'/';   // Create a folder if it doesn't already exist  
  112.                 if (!file_exists($path_up_book)) { mkdir($path_up_book, 0777, true); }
  113.  
  114.                 $up_book_destination = $path_up_book.$up_book_name_new;
  115.                 if (move_uploaded_file($up_book_tmp, $up_book_destination)) {
  116.                 }
  117.  
  118.             }
  119.         }
  120.     }
  121.  
  122. }
  123. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement