Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: droidus on Jun 18th, 2011  |  syntax: PHP  |  size: 1.44 KB  |  views: 106  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. $path_part = pathinfo($_POST['file']);
  3. if (isset($_POST['uploadFile'])) {
  4.         $result = count($file);
  5.         for ($i=0; $i<$result; $i++) {
  6.                 if ((($path_part['extension'] == "php") || ($path_part['extension'] == "txt")) && ($_FILES["file"]["size"] < 100000)) // 20000
  7.                 {
  8.                         if ($_FILES["file"]["error"] > 0)
  9.                 {
  10.                         echo "There was an error uploading your file. <br />";
  11.                 }
  12.                         else
  13.                 {
  14.                         echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  15.                         echo "Type: " . $_FILES["file"]["type"] . "<br />";
  16.                         echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  17.  
  18.                         if (file_exists("users/" . $_SESSION['user'] . "/uploads/" . $_FILES["file"]["name"]))
  19.                         {
  20.                                 echo $_FILES["file"]["name"] . " already exists. ";
  21.                         }
  22.                         else
  23.                         {
  24.                                 move_uploaded_file($_FILES["file"]["tmp_name"],
  25.                                 "users/" . $_SESSION['user'] . "/uploads/" . $_FILES["file"]["name"]);
  26.                                 echo "This file was successfully uploaded.";
  27.                         }
  28.                 }
  29.                 }
  30.                 else
  31.                 {
  32.                         $invalidFile = true;
  33.                 }
  34.         }
  35. }
  36. if (isset($invalidFile)) {echo "<div class='errors'>Invalid file type.</div>"; }
  37. ?>
  38.   <p>Upload your files here:</p>
  39.   <form action="" method="post"
  40. enctype="multipart/form-data">
  41.     <label for="file">Filename:</label>
  42.     <input type="file" name="file" id="file" /><br />
  43.     <br />
  44.     <input type="submit" name="uploadFile" value="Upload my Files" />
  45.   </form>
clone this paste RAW Paste Data