Advertisement
droidus

Untitled

Sep 28th, 2011
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.42 KB | None | 0 0
  1. <html>
  2. <body>
  3.  
  4. <form action="" method="post"
  5. enctype="multipart/form-data">
  6. <label for="file">Filename:</label>
  7. <input type="file" name="file[]" id="file" /><br>
  8. <label for="file">Filename:</label><input type="file" name="file[]" id="file" /><br>
  9. <label for="file">Filename:</label><input type="file" name="file[]" id="file" /><p>
  10. <label for="select"></label>
  11. Please select a folder destination:
  12. <select name="select" id="select">
  13.   <option value="default" selected>Default</option>
  14.   <option value="docs">My Documents</option>
  15.   <option value="music">My Music</option>
  16.   <option value="private">Private</option>
  17.   <option value="public">Public</option>
  18.   <option value="videos">My Videos</option>
  19. </select>
  20. <p>
  21. <input type="submit" name="submit" value="Submit" />
  22. </form>
  23.  
  24. </body>
  25. </html>
  26. <?php
  27. if(isset($_POST['submit'])) {
  28.     $folderDestination = $_POST['select'];
  29.     $ext  = end(explode('.', $_FILES["file"]["name"]));
  30.     $filesCount = count($file);
  31.     for ($i = 0; $i<$filesCount; $i++) {
  32.         if ($ext != "exe") // $_FILES["file"]["size"] < 20000
  33.         {
  34.             if ($_FILES["file"]["error"] > 0)
  35.             {
  36.                 echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
  37.             }
  38.             else
  39.             {
  40.                 echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  41.                 echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  42.             }
  43.         }
  44.     }
  45.    
  46.     // If the folder is not in the default position, we must place it in the right spot
  47.     for ($i = 0; $i<$filesCount; $i++) {
  48.     if($folderDestination!="default") {
  49.         if (file_exists("users/" . $_SESSION['user'] . "/uploads/" . $folderDestination . "/" . $_FILES["file"]["name"][$i]))
  50.         {
  51.             echo $_FILES["file"]["name"][$i] . " already exists.<br>";
  52.         }
  53.         else
  54.         {
  55.             move_uploaded_file($_FILES["file"]["tmp_name"][$i],
  56.             "users/" . $_SESSION['user'] . "/uploads/" . $folderDestination . "/" .  $_FILES["file"]["name"][$i]);
  57.             echo "Your file has been successfully uploaded, and you can now view it right away!";
  58.         }
  59.     } else { // If else, we put it in the uploads folder
  60.         if (file_exists("users/" . $_SESSION['user'] . "/uploads/" . $_FILES["file"]["name"][$i]))
  61.         {
  62.             echo $_FILES["file"]["name"][$i] . " already exists.<br>";
  63.         } else {
  64.       move_uploaded_file($_FILES["file"]["tmp_name"][$i],
  65.       "users/" . $_SESSION['user'] . "/uploads/" . $_FILES["file"]["name"][$i]);
  66.       echo "Your file has been successfully uploaded, and you can now view it right away!";
  67.       }
  68.     }
  69. }
  70. }
  71. ?>
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement