Opened 5 years ago
Last modified 4 years ago
#48974 reopened defect (bug)
-1 being added to image uploads since version 5.3.1
Reported by: | neotrope | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 5.3.1 |
Component: | Media | Keywords: | needs-patch |
Focuses: | Cc: |
Description
Hi, as of the Friday update my image uploads are geting '-1' added to each image
e.g.,
19-1216-iskysoft-christmas19-696x522-1.jpg
19-1216-jla-special-needs-696x522-1.jpg
Change History (22)
#2
@
5 years ago
- Keywords close added
Hi @neotrope, welcome to WordPress Trac.
That behavior is indeed new in WP 5.3.1.
You can read more about the reasons behind the change at #42437.
The short explanation is as follows:
- WP has long automatically added -1, -2, -3, etc when you upload a file with the same name multiple times (e.g., suppose you uploaded
my-image.jpg
yesterday, when you upload another file namedmy-image.jpg
tomorrow, WP renames the new file tomy-image-1.jpg
). It does this for any file type, not just images. - when WP creates the various "sub-sizes" of image files, it has long added the dimensions of the sub-size to the filename, e.g., when creating the default "thumbnail" filesize for
my-image.jpg
, WP createsmy-image-150x150.jpg
. - however, because of number 2, prior to the change in WP 5.3.1, if after uploading
my-image.jpg
, you then uploadedmy-image-150x150.jpg
that would overwrite the previously created "thumbnail" formy-image.jpg
. Similarly, if you first uploadedmy-image-150x150.jpg
and then later uploadedmy-image.jpg
the "thumbnail" formy-image.jpg
would overwrite the original imagemy-image-150x150.jpg
.
So, this change is to actually protect uploaded image files and WP-generated sub-size image files from overwriting each other.
#3
@
5 years ago
Hi
well, we need this with a disable option under 'settings . images' or a plugin hook to remove this 'fheature' as it breaks our versioning and also messes with stuff where file names should end with the dimensions for things like pagespeed image rewrites. It makes it problematic on a site with thousands of images when doing backups as now we have local copies without the -1 and then copies with 1. So in a server crash situation or database corruption without backup; we'd be unable to upload our original images to image folder, as all the image links would be permanwntly broken.
So, this is *not* a useful feature for us.
Similarly - as another example, if a customer logo changes, we can upload new image via FTP to over-write; this would not work as our local images will never have -1 added to them.
So, *PLEASE enable some sort of 'turn it off' option, as those of us with large news portals generation large number of images already 'right sized and optimized' -- the -1 causes numerous issued for us.
Thanks.
Filter hook to disable would be fine, if not other option ... I'm sure I'm not the only publisher vs blogger who will have problems with this. :-)
#4
@
5 years ago
The change in behavior in 5.3.1 is simply extending the filename uniqueness checks that WP has always done to include a check for uploads that contain "dimension-like" filenames.
But if you need to override that behavior, since WP 4.5.0 there has been the wp_unique_filename filter which you can use in a custom plugin.
#5
follow-up:
↓ 7
@
5 years ago
Right - but the filename is unique to begin with and should not be rewritten as the base file being used inside a post for a newspaper with internal versioning and backup merges, where now we would have duplicate versions of every image.
So, having to use a plugin simply to keep the original filename is incredibly stupid.
No CMS should change the names of original intellectual property files -- this is contrary to good behavior. -1 on the primary image should only be done if in fact there were a duplicate, which we have not had since using WP since 2004.
Hopefully dev team members will rethink this as it's now causing problems on 20 news portals for us.
Really really bad and intrusive move.
We don't need custom file names, we need our image file names to remain what we name them.
Sheesh.
#6
follow-up:
↓ 8
@
5 years ago
sample code to disable this new 'feature' would be highly appreciated by anyone viewing this.
TIA.
#7
in reply to:
↑ 5
@
5 years ago
Replying to neotrope:
Right - but the filename is unique to begin with and should not be rewritten as the base file being used inside a post for a newspaper with internal versioning and backup merges, where now we would have duplicate versions of every image.
The filename may be unique at the time you upload it (including for the auto-generated sub-sizes that exist at the the time you upload it, but as general purpose software, WP must consider the future...if you were to later change themes to one that defined a sub-size that was 696x522
and then you uploaded an image named 19-1216-iskysoft-christmas19.jpg
WP would overwrite the file you originally uploaded as 19-1216-iskysoft-christmas19-696x522.jpg
. And while your workflow may prevent that from happening, many WP users do change themes (or activate plugins) define different sub-sizes and then regenerate sub-sizes for existing uploads and were having previously uploaded files overwritten.
So, this change was to solve a problem that real users were having.
So, having to use a plugin simply to keep the original filename is incredibly stupid.
No CMS should change the names of original intellectual property files -- this is contrary to good behavior. -1 on the primary image should only be done if in fact there were a duplicate, which we have not had since using WP since 2004.
As I stated before, WP has (since at least version 2.5.0) sometimes changed the names of original files upon upload to prevent previously (or future) uploaded files from being overwritten.
#8
in reply to:
↑ 6
@
5 years ago
Replying to neotrope:
sample code to disable this new 'feature' would be highly appreciated by anyone viewing this.
TIA.
<?php add_filter( 'wp_unique_filename', 'my_ununique_filename', 10, 4 ); function my_ununique_filename( $filename, $ext, $dir, $unique_filename_callback ) { $esc_ext = preg_quote( $ext ); if ( 1 === preg_match( "/\d+x\d+-\d{$esc_ext}\$/", $filename ) ) { if ( ! file_exists( "{$dir}/{$filename}" ) ) { $filename = preg_replace( "/-\d{$esc_ext}\$/", $ext, $filename ); } } return $filename; }
This would mostly return to the pre-5.3.1 behavior. I say "mostly" because, in 5.3, if you were to have the above code in a plugin and uploaded 19-1216-iskysoft-christmas19-696x522.jpg
and then uploaded it again, the code would cause the 2nd file to overwrite the 1st one...which would be different that the 5.3 behavior (since WP <= 5.3 would have added -1 to prevent that overwrite).
#9
follow-up:
↓ 10
@
5 years ago
Fantastic. Thanks so much; we have custom theme, using CMS as news publishing platform, not blog posting; and have syndication to other websites, don't use thumbnails, etc. -- this was huge intrusive problem for us; so hopefully an optional toggle on images settings might be considered. I will try this solution, just making custom plugin for it, which is easy-peezie. THANK YOU SO MUCH for the quick fix, I"m about to go on vacation and was not prepared to have to wrangle this issue on 20+ websites where the -1 thing is huge problem for us. THANK YOU!!! :)
And, doh - the one time I didn't read the full changelog. ;-)
#10
in reply to:
↑ 9
@
5 years ago
- Resolution set to fixed
- Status changed from new to closed
Replying to neotrope:
Fantastic. Thanks so much; we have custom theme, using CMS as news publishing platform, not blog posting; and have syndication to other websites, don't use thumbnails, etc. --
By "(we) don't use thumbnails", do you mean have have a plugin that has "unregistered" all sub-sizes? If not, then WP is still creating sub-size files for the built-in defined sub-sizes, even if your theme/content doesn't display them.
this was huge intrusive problem for us; so hopefully an optional toggle on images settings might be considered. I will try this solution, just making custom plugin for it, which is easy-peezie. THANK YOU SO MUCH for the quick fix, I"m about to go on vacation and was not prepared to have to wrangle this issue on 20+ websites where the -1 thing is huge problem for us. THANK YOU!!! :)
Also, just to be clear, the code sample I gave above comes with the usual disclaimer:
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
If you use that code and it causes additional problems then neither myself nor the WordPress project are responsible :-)
I'm going to close this ticket.
#11
@
5 years ago
Hi, yes; we have been building websites since 1995, using WP since 2004; not newbies. Tons of custom code; not using gutenberg, custom hooks for stuff like 'duplicate post' and custom image usage only "on post" and noplace else. Complex. But this kind of 'out of the blue' thing is kind of bad for our setup. it would be like adding -new-post to end of every post without asking if we needed that. Same idea -actually changing file names we upload is not something one should expect for the original file(s).
THANK YOU. This was a good quick fix for our issue. I'm sure I'm not the only one who will have issue with this, but many likely have not noticed it yet since rolled out Friday. Expect more feedback on this from others on Monday, I'm guessing. But for us, this solved it! #whew :-)
#16
@
4 years ago
- Resolution wontfix deleted
- Status changed from closed to reopened
I stumbled upon this behavior when deploying WP 5.4.2 to the Linux production server. Why "stumbled"? I still develop on XAMPP/Windows (imagick not installed) and this local instance of WP 5.4.2 does not add "-1" and the likes to the name of the uploaded file ... bug or feature?
#17
@
4 years ago
... and then there is this: when does the "-1" get added and when not? I just uploaded a bunch of images to the Linux production server and some get the "-1" and some do not. Bug or feature?
#18
follow-up:
↓ 19
@
4 years ago
- Summary changed from -1 being added to image uploads with Version 5.3.1 to -1 being added to image uploads with Version 5.3.1 (and 5.4.2)
... and then some images are present with a whole set of sizes BOTH with and without "-1". That does not seem right. Let me know if I can do anything to reproduce or investigate this issue.
#19
in reply to:
↑ 18
@
4 years ago
- Keywords needs-patch added
The image filename gets changed if it ends with a numeric value, for example "bag-40x50.jpg" will be renamed "bag-40x50-1.jpg". even if no previous file with such name had been uploaded ever before. Seems like WordPress regards such filename as a 40x50 thumbnail, and not an original file. The only work around is not to use such numeric values at the end, for example I can use "bag-40x50-size.jpg". I hope this gets fixed soon cause is driving me crazy.
Even auto-generated images using an imagemagick script to generate image from first image in post, are doing the same thing for a virgin image file ...
19-1212s2p-EPIC-Mat-Presutti-696x522-1.jpg