download_url example

if ( ! preg_match( '!^(http|https|ftp)://!i', $package ) && file_exists( $package ) ) { // Local file or remote?             return $package; // Must be a local file.         }

        if ( empty( $package ) ) {
            return new WP_Error( 'no_package', $this->strings['no_package'] );
        }

        $this->skin->feedback( 'downloading_package', $package );

        $download_file = download_url( $package, 300, $check_signatures );

        if ( is_wp_error( $download_file ) && ! $download_file->get_error_data( 'softfail-filename' ) ) {
            return new WP_Error( 'download_failed', $this->strings['download_failed']$download_file->get_error_message() );
        }

        return $download_file;
    }

    /** * Unpacks a compressed package file. * * @since 2.8.0 * * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. * * @param string $package Full path to the package file. * @param bool $delete_package Optional. Whether to delete the package file after attempting * to unpack it. Default true. * @return string|WP_Error The path to the unpacked contents, or a WP_Error on failure. */
// Set variables for storage, fix file filename for query strings.         preg_match( '/[^\?]+\.(' . implode( '|', $allowed_extensions ) . ')\b/i', $file$matches );

        if ( ! $matches ) {
            return new WP_Error( 'image_sideload_failed', __( 'Invalid image URL.' ) );
        }

        $file_array         = array();
        $file_array['name'] = wp_basename( $matches[0] );

        // Download file to temp location.         $file_array['tmp_name'] = download_url( $file );

        // If error storing temporarily, return the error.         if ( is_wp_error( $file_array['tmp_name'] ) ) {
            return $file_array['tmp_name'];
        }

        // Do the validation and storage stuff.         $id = media_handle_sideload( $file_array$post_id$desc );

        // If error storing permanently, unlink.         if ( is_wp_error( $id ) ) {
            @
Home | Imprint | This part of the site doesn't use cookies.