WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/27/2017 07:24:50 PM (3 years ago)
Author:
joemcgill
Message:

Media: Keep PDF previews from overwriting files.

Since support for PDF previews were added in [38949], it's possible
that the generated image file could overwrite an existing image file
with the same name. This uses wp_unique_filename() to avoid this
issue and adds a '-pdf' identifier on the end of filenames.

Props gitlost, desrosj, mikeschroder, joemcgill.
Merges [40130] and [40131] to the 4.7 branch.
Fixes #39875. See #31050.

Location:
branches/4.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

  • branches/4.7/src/wp-admin/includes/image.php

    r39633 r40133  
    252252
    253253            if ( ! is_wp_error( $editor ) ) { // No support for this type of file
    254                 $uploaded = $editor->save( $file, 'image/jpeg' );
     254                /*
     255                 * PDFs may have the same file filename as JPEGs.
     256                 * Ensure the PDF preview image does not overwrite any JPEG images that already exist.
     257                 */
     258                $dirname = dirname( $file ) . '/';
     259                $ext = '.' . pathinfo( $file, PATHINFO_EXTENSION );
     260                $preview_file = $dirname . wp_unique_filename( $dirname, wp_basename( $file, $ext ) . '-pdf.jpg' );
     261
     262                $uploaded = $editor->save( $preview_file, 'image/jpeg' );
    255263                unset( $editor );
    256264
Note: See TracChangeset for help on using the changeset viewer.