mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-14 22:56:19 +01:00
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. Built from https://develop.svn.wordpress.org/branches/4.7@40133 git-svn-id: http://core.svn.wordpress.org/branches/4.7@40070 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c2a90ea28d
commit
498f71615f
@ -251,7 +251,15 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
|
||||
$editor = wp_get_image_editor( $file );
|
||||
|
||||
if ( ! is_wp_error( $editor ) ) { // No support for this type of file
|
||||
$uploaded = $editor->save( $file, 'image/jpeg' );
|
||||
/*
|
||||
* PDFs may have the same file filename as JPEGs.
|
||||
* Ensure the PDF preview image does not overwrite any JPEG images that already exist.
|
||||
*/
|
||||
$dirname = dirname( $file ) . '/';
|
||||
$ext = '.' . pathinfo( $file, PATHINFO_EXTENSION );
|
||||
$preview_file = $dirname . wp_unique_filename( $dirname, wp_basename( $file, $ext ) . '-pdf.jpg' );
|
||||
|
||||
$uploaded = $editor->save( $preview_file, 'image/jpeg' );
|
||||
unset( $editor );
|
||||
|
||||
// Resize based on the full size image, rather than the source.
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.7.3-alpha-40132';
|
||||
$wp_version = '4.7.3-alpha-40133';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user