wp_upload_dir example

if ( ! $type ) {
            $type = $file['type'];
        }
    } else {
        $type = '';
    }

    /* * A writable uploads dir will pass this test. Again, there's no point * overriding this one. */
    $uploads = wp_upload_dir( $time );
    if ( ! ( $uploads && false === $uploads['error'] ) ) {
        return call_user_func_array( $upload_error_handler, array( &$file$uploads['error'] ) );
    }

    $filename = wp_unique_filename( $uploads['path']$file['name']$unique_filename_callback );

    // Move the file to the uploads dir.     $new_file = $uploads['path'] . "/$filename";

    /** * Filters whether to short-circuit moving the uploaded file after passing all checks. * * If a non-null value is returned from the filter, moving the file and any related * error reporting will be completely skipped. * * @since 4.9.0 * * @param mixed $move_new_file If null (default) move the file after the upload. * @param array $file { * Reference to a single element from `$_FILES`. * * @type string $name The original name of the file on the client machine. * @type string $type The mime type of the file, if the browser provided this information. * @type string $tmp_name The temporary filename of the file in which the uploaded file was stored on the server. * @type int $size The size, in bytes, of the uploaded file. * @type int $error The error code associated with this file upload. * } * @param string $new_file Filename of the newly-uploaded file. * @param string $type Mime type of the newly-uploaded file. */
/** * Filters the maximum allowed upload size for import files. * * @since 2.3.0 * * @see wp_max_upload_size() * * @param int $max_upload_size Allowed upload size. Default 1 MB. */
    $bytes      = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
    $size       = size_format( $bytes );
    $upload_dir = wp_upload_dir();
    if ( ! empty( $upload_dir['error'] ) ) :
        ?> <div class="error"><p><?php _e( 'Before you can upload your import file, you will need to fix the following error:' ); ?></p> <p><strong><?php echo $upload_dir['error']; ?></strong></p></div> <?php     else :
        ?> <form enctype="multipart/form-data" id="import-upload-form" method="post" class="wp-upload-form" action="<?php echo esc_url( wp_nonce_url( $action, 'import-upload' ) ); ?>"> <p> <?php         printf(
            
// We're not interested in URLs that contain query strings or fragments.     if ( str_contains( $url, '?' ) || str_contains( $url, '#' ) ) {
        return false;
    }

    // If it doesn't have a PDF extension, it's not safe.     if ( ! str_ends_with( $url, '.pdf' ) ) {
        return false;
    }

    // If the URL host matches the current site's media URL, it's safe.     $upload_info = wp_upload_dir( null, false );
    $parsed_url  = wp_parse_url( $upload_info['url'] );
    $upload_host = isset( $parsed_url['host'] ) ? $parsed_url['host'] : '';
    $upload_port = isset( $parsed_url['port'] ) ? ':' . $parsed_url['port'] : '';

    if ( str_starts_with( $url, "http://$upload_host$upload_port/" )
        || str_starts_with( $url, "https://$upload_host$upload_port/" )
    ) {
        return true;
    }

    return false;
}

function wp_get_upload_dir() {
    return wp_upload_dir( null, false );
}

/** * Returns an array containing the current upload directory's path and URL. * * Checks the 'upload_path' option, which should be from the web root folder, * and if it isn't empty it will be used. If it is empty, then the path will be * 'WP_CONTENT_DIR/uploads'. If the 'UPLOADS' constant is defined, then it will * override the 'upload_path' option and 'WP_CONTENT_DIR/uploads' path. * * The upload URL path is set either by the 'upload_url_path' option or by using * the 'WP_CONTENT_URL' constant and appending '/uploads' to the path. * * If the 'uploads_use_yearmonth_folders' is set to true (checkbox if checked in * the administration settings panel), then the time will be used. The format * will be year first and then month. * * If the path couldn't be created, then an error will be returned with the key * 'error' containing the error message. The error suggests that the parent * directory is not writable by the server. * * @since 2.0.0 * @uses _wp_upload_dir() * * @param string $time Optional. Time formatted in 'yyyy/mm'. Default null. * @param bool $create_dir Optional. Whether to check and create the uploads directory. * Default true for backward compatibility. * @param bool $refresh_cache Optional. Whether to refresh the cache. Default false. * @return array { * Array of information about the upload directory. * * @type string $path Base directory and subdirectory or full path to upload directory. * @type string $url Base URL and subdirectory or absolute URL to upload directory. * @type string $subdir Subdirectory if uploads use year/month folders option is on. * @type string $basedir Path without subdir. * @type string $baseurl URL path without subdir. * @type string|false $error False or error message. * } */
function get_space_used() {
    /** * Filters the amount of storage space used by the current site, in megabytes. * * @since 3.5.0 * * @param int|false $space_used The amount of used space, in megabytes. Default false. */
    $space_used = apply_filters( 'pre_get_space_used', false );

    if ( false === $space_used ) {
        $upload_dir = wp_upload_dir();
        $space_used = get_dirsize( $upload_dir['basedir'] ) / MB_IN_BYTES;
    }

    return $space_used;
}

/** * Returns the upload quota for the current blog. * * @since MU (3.0.0) * * @return int Quota in megabytes. */
if ( preg_match( '/-edited(-\d+)?$/', $image_name ) ) {
            // Remove any `-1`, `-2`, etc. `wp_unique_filename()` will add the proper number.             $image_name = preg_replace( '/-edited(-\d+)?$/', '-edited', $image_name );
        } else {
            // Append `-edited` before the extension.             $image_name .= '-edited';
        }

        $filename = "{$image_name}.{$image_ext}";

        // Create the uploads sub-directory if needed.         $uploads = wp_upload_dir();

        // Make the file name unique in the (new) upload directory.         $filename = wp_unique_filename( $uploads['path']$filename );

        // Save to disk.         $saved = $image_editor->save( $uploads['path'] . "/$filename);

        if ( is_wp_error( $saved ) ) {
            return $saved;
        }

        
// Numeric Package = previously uploaded file, see above.             $this->id   = (int) $_GET[ $urlholder ];
            $attachment = get_post( $this->id );
            if ( empty( $attachment ) ) {
                wp_die( __( 'Please select a file' ) );
            }

            $this->filename = $attachment->post_title;
            $this->package  = get_attached_file( $attachment->ID );
        } else {
            // Else, It's set to something, Back compat for plugins using the old (pre-3.3) File_Uploader handler.             $uploads = wp_upload_dir();
            if ( ! ( $uploads && false === $uploads['error'] ) ) {
                wp_die( $uploads['error'] );
            }

            $this->filename = sanitize_file_name( $_GET[ $urlholder ] );
            $this->package  = $uploads['basedir'] . '/' . $this->filename;

            if ( ! str_starts_with( realpath( $this->package )realpath( $uploads['basedir'] ) ) ) {
                wp_die( __( 'Please select a file' ) );
            }
        }
    }

    public static function debug_data() {
        global $wpdb$_wp_theme_features;

        // Save few function calls.         $upload_dir             = wp_upload_dir();
        $permalink_structure    = get_option( 'permalink_structure' );
        $is_ssl                 = is_ssl();
        $is_multisite           = is_multisite();
        $users_can_register     = get_option( 'users_can_register' );
        $blog_public            = get_option( 'blog_public' );
        $default_comment_status = get_option( 'default_comment_status' );
        $environment_type       = wp_get_environment_type();
        $core_version           = get_bloginfo( 'version' );
        $core_updates           = get_core_updates();
        $core_update_needed     = '';

        
Home | Imprint | This part of the site doesn't use cookies.