多站点图像文件路径功能?

时间:2016-03-11 13:22:58

标签: php wordpress .htaccess image-uploading image-upload

在多站点环境中,如果用户上传图片,则会将其放在错误的位置,因此找不到http://www.example.com/suppliers/files//home/root/public_html//files/job-manager-uploads/featured_image/2016/03/example-image.jpg

我需要编写一个函数或htaccess重定向或其他内容来将此上传路径更改为http://www.example.com/suppliers/files/2016/03/example-image.jpg

请问任何想法?!

function job_manager_upload_dir( $pathdata ) {
    global $job_manager_upload, $job_manager_uploading_file;

    if ( ! empty( $job_manager_upload ) ) {
        $dir = apply_filters( 'job_manager_upload_dir', 'job-manager-uploads/' . sanitize_key( $job_manager_uploading_file ), sanitize_key( $job_manager_uploading_file ) );

        if ( empty( $pathdata['subdir'] ) ) {
            $pathdata['path']   = $pathdata['path'] . '/' . $dir;
            $pathdata['url']    = $pathdata['url'] . '/' . $dir;
            $pathdata['subdir'] = '/' . $dir;
        } else {
            $new_subdir         = '/' . $dir . $pathdata['subdir'];
            $pathdata['path']   = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['path'] );
            $pathdata['url']    = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['url'] );
            $pathdata['subdir'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['subdir'] );
        }
    }

    return $pathdata;
}
add_filter( 'upload_dir', 'job_manager_upload_dir' );

0 个答案:

没有答案