Advertisement
Guest User

Upload.php

a guest
May 13th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. <?php
  2. define("UPLOAD_DIR", "/var/www/lifecycle/tmp");
  3.  
  4. if (!empty($_FILES["usrFile"])) {
  5. $usrFile = $_FILES["usrFile"];
  6.  
  7.  
  8. //check for errors
  9. if ($usrFile["error"] !== UPLOAD_ERR_OK) {
  10. echo "<p>An error occurred.</p>";
  11. exit;
  12. }
  13.  
  14. // ensure a safe filename
  15. $name = preg_replace("/[^A-Z0-9._-]/i", "_", $usrFile["name"]);
  16. print_r($name."<br>");
  17.  
  18.  
  19. // don't overwrite an existing file
  20. $i = 0;
  21. $parts = pathinfo($name);
  22. while (file_exists(UPLOAD_DIR . $name)) {
  23. $i++;
  24. $name = $parts["filename"] . "-" . $i . "." . $parts["extension"];
  25. }
  26. print_r("new name: ".$name."<br>");
  27. lstat(UPLOAD_DIR);
  28.  
  29.  
  30. // preserve file from temporary directory
  31. $success = move_uploaded_file($usrFile["tmp_name"],
  32. UPLOAD_DIR . $name);
  33. if (!$success) {
  34. echo "<p>Unable to save file.</p>";
  35. exit;
  36. }
  37.  
  38. // set proper permissions on the new file
  39. chmod(UPLOAD_DIR . $name, 0644);
  40.  
  41. //check that the file is not executable (doesn't work)
  42. $ftype = array();
  43. //exec("file " . UPLOAD_DIR . $name, ftype); <- returns a 500 error
  44. print_r(ftype);
  45. }
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement