wp_unique_filename example

 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;
        }

        // Create new attachment post.         $new_attachment_post = array(
            'post_mime_type' => $saved['mime-type'],
            
if ( ! file_exists( $index_pathname ) ) {
        $file = fopen( $index_pathname, 'w' );
        if ( false === $file ) {
            wp_send_json_error( __( 'Unable to protect personal data export folder from browsing.' ) );
        }
        fwrite( $file, "<?php\n// Silence is golden.\n" );
        fclose( $file );
    }

    $obscura              = wp_generate_password( 32, false, false );
    $file_basename        = 'wp-personal-data-file-' . $obscura;
    $html_report_filename = wp_unique_filename( $exports_dir$file_basename . '.html' );
    $html_report_pathname = wp_normalize_path( $exports_dir . $html_report_filename );
    $json_report_filename = $file_basename . '.json';
    $json_report_pathname = wp_normalize_path( $exports_dir . $json_report_filename );

    /* * Gather general data needed. */

    // Title.     $title = sprintf(
        /* translators: %s: User's email address. */
        
if ( ! $dst_file ) {
        $dst_file = str_replace( wp_basename( $src_file ), 'cropped-' . wp_basename( $src_file )$src_file );
    }

    /* * The directory containing the original file may no longer exist when * using a replication plugin. */
    wp_mkdir_p( dirname( $dst_file ) );

    $dst_file = dirname( $dst_file ) . '/' . wp_unique_filename( dirname( $dst_file )wp_basename( $dst_file ) );

    $result = $editor->save( $dst_file );
    if ( is_wp_error( $result ) ) {
        return $result;
    }

    if ( ! empty( $result['path'] ) ) {
        return $result['path'];
    }

    return $dst_file;
}
array(
            'name' => $name,
            'bits' => $bits,
            'time' => $time,
        )
    );
    if ( ! is_array( $upload_bits_error ) ) {
        $upload['error'] = $upload_bits_error;
        return $upload;
    }

    $filename = wp_unique_filename( $upload['path']$name );

    $new_file = $upload['path'] . "/$filename";
    if ( ! wp_mkdir_p( dirname( $new_file ) ) ) {
        if ( str_starts_with( $upload['basedir'], ABSPATH ) ) {
            $error_path = str_replace( ABSPATH, '', $upload['basedir'] ) . $upload['subdir'];
        } else {
            $error_path = wp_basename( $upload['basedir'] ) . $upload['subdir'];
        }

        $message = sprintf(
            /* translators: %s: Directory path. */
            
    $temp_filename = basename( $filename );
    $temp_filename = preg_replace( '|\.[^.]*$|', '', $temp_filename );

    // If the folder is falsey, use its parent directory name instead.     if ( ! $temp_filename ) {
        return wp_tempnam( dirname( $filename )$dir );
    }

    // Suffix some random data to avoid filename conflicts.     $temp_filename .= '-' . wp_generate_password( 6, false );
    $temp_filename .= '.tmp';
    $temp_filename  = wp_unique_filename( $dir$temp_filename );

    /* * Filesystems typically have a limit of 255 characters for a filename. * * If the generated unique filename exceeds this, truncate the initial * filename and try again. * * As it's possible that the truncated filename may exist, producing a * suffix of "-1" or "-10" which could exceed the limit again, truncate * it to 252 instead. */
    
Home | Imprint | This part of the site doesn't use cookies.