以下是我对流程的理解:
这个wp_upload_dir() 功能是上载文件夹创建过程和wp_mkdir_p() 功能是有用的助手。
每次wp_upload_dir() 它实际上是在运行file_exists() 通过检查当前上载文件夹wp_mkdir_p() 作用如果文件夹不存在,则使用mkdir(), 但不是$wp_filesystem->mkdir() 正如人们所料。
这个wp_upload_dir() 函数检查uploads_use_yearmonth_folders 选项已设置。在这种情况下,年/月文件夹是由default, 从的当前时间current_time( \'mysql\' ):
// ... cut ...
if ( get_option( \'uploads_use_yearmonth_folders\' ) ) {
// Generate the yearly and monthly dirs
if ( !$time )
$time = current_time( \'mysql\' );
$y = substr( $time, 0, 4 );
$m = substr( $time, 5, 2 );
$subdir = "/$y/$m";
}
$dir .= $subdir;
$url .= $subdir;
// ... cut ...
// Make sure we have an uploads directory.
if ( ! wp_mkdir_p( $uploads[\'path\'] ) ) {
// ... cut ...
在哪里
$uploads[\'path\'] 已分配给
$dir.
这个wp_upload_dir() 函数在_wp_handle_upload() 上载期间隐式应用的函数。我们还注意到media_handle_{upload,sideload}() 函数是wp_handle_{upload,sideload}() 函数的包装器_wp_handle_upload() 作用
因此,我想知道您是否希望加入这些上载过程,例如使用wp_handle_upload 中的筛选器_wp_handle_upload() 功能:
/**
* Hook into the upload/sideload processes and check out the upload path.
*/
add_filter( \'wp_handle_upload\', function( $args, $action )
{
if( isset( $args[\'file\'] ) && file_exists( $args[\'file\'] ) )
{
// Upload path of the new file:
$path = dirname( $args[\'file\'] )
// ... do stuff here ...
}
return $args;
}, 99, 2 );
在哪里
$args[\'file\'] 包含上载文件的本地路径,以及
$action 可以是“上传”或“侧载”。