Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Staring in 5.0.0 PHP's mkdir() adds an option to create directories recursively. I think we should do this by default so I'd be able to replace:
file_check_directory($d = file_directory_path() .'/foo', FILE_CREATE_DIRECTORY);
file_check_directory($d = file_directory_path() .'/foo/bar', FILE_CREATE_DIRECTORY);
file_check_directory($d = file_directory_path() .'/foo/bar/baz', FILE_CREATE_DIRECTORY);
with
file_check_directory($d = file_directory_path() .'/foo/bar/baz', FILE_CREATE_DIRECTORY);
Comment | File | Size | Author |
---|---|---|---|
file_check_directory_recursive.patch | 1.12 KB | drewish | |
Comments
Comment #1
drewish CreditAttribution: drewish commentedadding some tags
Comment #2
jmstacey CreditAttribution: jmstacey commentedsubscribing for notification on commit.
Comment #3
quicksketchThis makes perfect sense to me. If you're curious about the drupal_chmod() right below the changed line, it does seem a little redundant but it serves the purpose of notifying watchdog if permissions are denied while chmoding the directory.
It'll be great to remove some loops in FileField with this enhancement. Currently I'm doing something like this:
In comparison this is a dream. Thanks PHP 5!
This patch makes appropriate changes to our tests and is ready to go.
Comment #4
webchickCommitted with the addition of a small comment from drewish in IRC, since i had to go off and look up what parameters mkdir started taking while I wasn't looking. :)
Thanks! Please document this in the upgrade guide so that other modules can get rid of similarly nasty code.
Comment #5
quicksketchhttp://drupal.org/update/modules/6/7#file_check_directory_recursive
Comment #6
quicksketchComment #8
Alan D. CreditAttribution: Alan D. commentedMarked the following as duplicates.
#470638 - file_check_directory should create directories recursively
#270443: Native recursive create directory function
#215304: file_check_directory() does not created nested directories