• I found this code in the furum, I modified it slightly to add the hours and minutes. That’s exactly what I want. The problem is: on the server, folders automatically create each minute even if nothing is uploaded. My question is what is the code to stop the automatic creation of empty folders or what code is creating folder only when there is an upload?

    function upload_dir_filter($uploads){
        $day = date('d');
        $hour = date('H');
        $minute = date('i');
        $uploads['path'] .= '/' . $day . '/' . $hour . '/' . $minute;
        $uploads['url']  .= '/' . $day . '/' . $hour . '/' . $minute;
        return $uploads;
    }
    add_filter('upload_dir', 'upload_dir_filter');

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Well, the obvious answer: Don’t use minutes in the upload dir, because that is insane and it will create a folder for each minute.

    Yes, it will create the folder just by checking for it. There’s no “fix” for this except to not make it do crazy things like use minutes for the upload directory. Unless you are uploading constant new things, you don’t need that level of granularity. Even including the day is a bit overboard.

    Thread Starter rodesro

    (@rodesro)

    I agree with you, but I have to find a way to avoid two or more files with the same name in the same folder, eg document.pdf, document-1.pdf, doucument-2.pdf

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Folder name with upload_dir Organize uploads by year, month and day’ is closed to new replies.