Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- header("Content-Type: image/png");
- $currentDit = __DIR__ . DIRECTORY_SEPARATOR;
- $fileName = basename($_FILES['file']['name']);
- $hash = md5($fileName);
- $firstDir = $currentDit . date('Y-m-d');
- $secondDir = $firstDir . DIRECTORY_SEPARATOR . substr($hash, 0, 2);
- $thirdDir = $secondDir . DIRECTORY_SEPARATOR . substr($hash, -2, 2);
- if (!is_dir($thirdDir)) {
- mkdir($thirdDir, 0777, true);
- }
- $finalDir = $thirdDir . DIRECTORY_SEPARATOR . $fileName;
- if (move_uploaded_file(
- $_FILES['file']['tmp_name'],
- $finalDir
- )) {
- echo file_get_contents($finalDir);
- die;
- } else {
- echo 'Jakiś problem?';
- }
- }
- ?>
- <form enctype="multipart/form-data" method="post">
- <input type="file" name="file">
- <input type="submit" value="Wyślij dziadu">
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement