Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. <?php
  2. /* ===== CONSTANTS ===== */
  3. $ROOT_DIR = 'FILES';
  4. $COMPUTER_NAME = 'compname';
  5. $PROGRAM = 'program';
  6. $FILENAME = 'file';
  7. $CHUNK_SIZE = 1024;
  8. /* ===================== */
  9.  
  10. //=====================================
  11. /**
  12. Function that gets current time and formats it into pretty looking date
  13. */
  14. function makeDate() {
  15. return strftime('%Y-%m-%d, %H.%M');
  16. }
  17. //=====================================
  18. // check here if the parameters are set. If it's not then it's safe to say some one is snooping around...
  19. if (isset($_POST[$COMPUTER_NAME], $_POST[$PROGRAM], $_FILES[$FILENAME])) {
  20. // construct a full path and create it
  21. $fullPath = $ROOT_DIR.'\\'.$_POST[$COMPUTER_NAME].'\\'.$_POST[$PROGRAM].'\\'.makeDate();
  22. mkdir($fullPath, 0777, true);
  23.  
  24. // move the files and rename them as temporary
  25. $filename = $_FILES[$FILENAME]['name'];
  26. move_uploaded_file(($_FILES[$FILENAME]['tmp_name']), $fullPath.'\\'.$filename.'.tmp');
  27.  
  28. // decode received files
  29. $src = fopen($fullPath.'\\'.$filename.'.tmp', 'rb');
  30. $dst = fopen($fullPath.'\\'.$filename, 'wb');
  31. while (!feof($src)) {
  32. fwrite($dst, base64_decode(fread($src, $CHUNK_SIZE)));
  33. }
  34. fclose($dst);
  35. fclose($src);
  36. unlink($fullPath.'\\'.$filename.'.tmp'); // remove the temp file after decoding it
  37.  
  38. echo 'OK!';
  39. } else {
  40. echo 'oh no :(';
  41. }
  42. //=====================================
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement