Advertisement
sanjiisan

Untitled

Sep 5th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. <?php
  2. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  3. header("Content-Type: image/png");
  4.  
  5. $currentDit = __DIR__ . DIRECTORY_SEPARATOR;
  6.  
  7. $fileName = basename($_FILES['file']['name']);
  8. $hash = md5($fileName);
  9.  
  10. $firstDir = $currentDit . date('Y-m-d');
  11. $secondDir = $firstDir . DIRECTORY_SEPARATOR . substr($hash, 0, 2);
  12. $thirdDir = $secondDir . DIRECTORY_SEPARATOR . substr($hash, -2, 2);
  13.  
  14. if (!is_dir($thirdDir)) {
  15. mkdir($thirdDir, 0777, true);
  16. }
  17.  
  18.  
  19. $finalDir = $thirdDir . DIRECTORY_SEPARATOR . $fileName;
  20.  
  21. if (move_uploaded_file(
  22. $_FILES['file']['tmp_name'],
  23. $finalDir
  24. )) {
  25.  
  26. echo file_get_contents($finalDir);
  27. die;
  28. } else {
  29. echo 'Jakiś problem?';
  30. }
  31. }
  32. ?>
  33.  
  34. <form enctype="multipart/form-data" method="post">
  35. <input type="file" name="file">
  36.  
  37. <input type="submit" value="Wyślij dziadu">
  38. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement