Cannot remove/replace a file in Media - help?

I wish to replace a file uploaded through Media and linked in the text with another file that has the same name. I tried the Delete Permanently option, does not work (the file is still there and can be accessed through the URL link. I tried replacing it straight up and by replacing it with updating the names and links etc with the new, corrected file, but the old one remains and the new one does not get into the system.

Is the problem in the fact that the two files, old one and new one, have the same file name? I don’t want to change the file name (the file name is designed to be descriptive and clear to the users once downloaded).

Any thoughts around this problem or why it may be occuring?

Hi @Ana, thanks for flagging this.

I find I’m able to get this to work as intended via Replace media > Upload a new file and choosing the “Just replace the file” option, but only if the new file I’m uploading from my hard drive has the same name as the previously uploaded file.

It seems that if the name of the file-to-be-uploaded is different, this option doesn’t replace the previously uploaded file as it should. I can bring this issue to the tech team at my next bug scrub meeting with them. I’ll bring up the scope of the Delete Permanently option too.

Could you try giving the new file the same name prior to uploading it as the replacement? So far I’ve only used this method to replace a newly uploaded file (one that doesn’t have previous replacement attempts), but it could be worth trying as a possible workaround.

We use the Enable Media Replace plugin to allow this capability for our enterprise hosted Pressbooks installations: Enable Media Replace – WordPress plugin | WordPress.org. I’d look at their instructions for doing this:

Now you’ll be able to replace any uploaded file from the media “edit” view, where it should be. Media replacement can be done in one of two ways:

  1. Just replace the file. This option requires you to upload a file of the same type as the one you are replacing. The name of the attachment will stay the same no matter what the file you upload is called.
  2. Replace the file, use new file name and update all links. If you check this option, the name and type of the file you are about to upload will replace the old file. All links pointing to the current file will be updated to point to the new file name. Additional options for the folder where to place the new file, or the date of the new file are also available on the replace screen.

Thanks for the ideas. I am doing exactly what you say you were able to do, which is to use Replace file. The new file is titled the same way as the file already in the media folder, yet after I select it and click on upload, the url created after the upload of the replacement file links to the old version of the file.

Even if I just try to delete the existing file from the Media folder by clicking on Delete permanently, the file no longer appears in the file list in the folder, yet the url link to the old version of the file is still active.

I just tried it again and I encounter the same issue @Ana describes. @SteelWagstaff, I think what’s happening is that the cache of the website is storing the old version even as the replacement has been uploaded. If I navigate to the URL I’m brought to the old image, but adding ? followed by any string to the end of the URL brings me to the replacement image.

@ThomasWeideman, that thought occurred to me as well. I cleared my cache and now it works! In other words, it shows the new version of the file. Thank you for this correspondence, it has helped me in resolving the issue.

2 Likes