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, derosj, mikeschroder, joemcgill. Fixes #39875. See #31050. Built from https://develop.svn.wordpress.org/trunk@40130 git-svn-id: http://core.svn.wordpress.org/trunk@40067 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
f780259d88
commit
d6bec79fe7
|
@ -251,7 +251,15 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
|
||||||
$editor = wp_get_image_editor( $file );
|
$editor = wp_get_image_editor( $file );
|
||||||
|
|
||||||
if ( ! is_wp_error( $editor ) ) { // No support for this type of 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 );
|
unset( $editor );
|
||||||
|
|
||||||
// Resize based on the full size image, rather than the source.
|
// Resize based on the full size image, rather than the source.
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.8-alpha-40129';
|
$wp_version = '4.8-alpha-40130';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue