Blog

Upload Janitor WordPress Plugin

This plugin allows you to reclaim disk space and clean up your uploads folder by deleting old uploads you are no longer linking to.

It will identify unused files within your uploads folder, and give you the option of archiving then deleting some or all of these files.

Before any action is taken, Upload Janitor will automatically make a ‘tar’ archive of all files to be erased, including their original paths, so you can restore if necessary.Please note: This plugin is currently not under active development, and has not been extensively tested for recent WordPress versions. Use with caution, and always manually back up your WordPress installation before use.

Download

Download Upload Janitor from the WordPress plugins directory.

If you like Upload Janitor, please consider buying one of my products.

Installation

  1. Unzip the package, and upload upload-janitor to the wp-content/plugins directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress
  3. Visit ‘Upload Janitor’ within the ‘Tools’ menu in WordPress to use

How does it work?

This plugin inspects every file within the uploads folder. For each file, it searches pages or posts that reference the file. That is, the plugin searches for the part of each file’s path that comes after the path to the uploads folder, such as 2010/01/my great but forgotten image.jpg.

The path is searched as-is, as well as URL-encoded with ‘%20′ for spaces, and the same with ‘+’ for spaces - 2010/01/my%20great%20but%20forgotten%20image.jpg and 2010/01/my+great+but+forgotten+image.jpg. HTML entity-encoded forms of all of these are also searched.

If no matches are found, then the file is considered unused.

Note that this plugin plays it safe, and does not distinguish between older post/page revisions and the current version of a post/page. If a revision references a file, the file will be considered still in use.

Restoring

If something goes wrong, you can always restore. If you have shell access to your site, this is easy. Simply log in, navigate to your wp-content/plugins directory, and locate the Upload Janitor archive – it will look like upload_janitor_archive_YYYY-mm-dd.tar.gz. Then, type:

  tar zxf <archive name> .

This will restore all files within the archive.

If you do not have shell access to your server, you will have to download the archive, extract it, then upload the contents back to your server. The archive will be accessible at http://your-blog.com/wp-content/uploads/upload_janitor_archive_YYYY-mm-dd.tar.gz

Changes

0.2

  • Tweak for compatibility with some apparently buggy PHP installations
  • Additional error reporting for ‘tar’ archiver

0.1

  • Initial release
Tagged , . Bookmark the permalink. Both comments and trackbacks are currently closed.

32 Comments

  1. Posted January 19, 2010 at 10:03 pm | Permalink

    I’ve just installed this plugin which looks just what I wanted. I started it from ‘tools’ and it says that it is searching through the uploads folder which takes about a minute. The page then refreshes, and I get a 404. The URL is the same http://www.ifagiolini.com/wp-admin/tools.php?page=upload-janitor/upload-janitor.php but the 404 logger I’m running (part of the plugin ‘redirections’ by John Godley) shows the referrer as the main site.

    Any ideas? It would be so great if I could get this to work as it looks like exactly what I need!

    Best wishes Kieran

    • Posted January 19, 2010 at 10:21 pm | Permalink

      Hi Kieran,

      It sounds to me like there may be a plugin interfering – If you feel up to it, you could try disabling some plugins, and seeing if Upload Janitor starts working for you.

      The other possibility is that perhaps there’s actually a 501 server error happening – if you have a particularly large uploads folder, there’s a chance that the plugin is running out of memory. If you have the means to do so, try checking your error log and seeing if there’s anything telling in there. Or, if you can, try increasing your memory limit, if disabling plugins doesn’t provide any leads.

      • Posted March 19, 2011 at 4:06 pm | Permalink

        I am hosted on a shared server and the query is finished running, it proved necessary changes are not to saturate the server

        • Posted March 22, 2011 at 6:14 pm | Permalink

          I still have the same problem, the SQL query kills the server. there any way to limit the query ?

  2. Posted January 20, 2010 at 10:02 am | Permalink

    Hi,

    Very great plugin but when I try to delete some files I’ve got an error when the plugin make the archive file : Encountered a problem while creating archive: The ‘tar’ utility reported error number 1.

    Best wishes Stéphane

    • Posted January 20, 2010 at 12:14 pm | Permalink

      Hello Stéphane,

      There’s some issue or other with your archive utility (tar) – It’s hard to know exactly what it is, but the easiest way forward is probably to back your uploads folder yourself, if you have the means to do so. You can proceed without making a backup, but I wouldn’t recommend it =)

      I might add some extra reporting in the next version so tar problems are more clear.

  3. Posted February 17, 2010 at 1:34 pm | Permalink

    Tried out this plugin, but had problems creating the tar. Seems proc_open is disabled on my server. Manually backed up the uploads folder and ran the plugin. Finished ok.

    It deleted all my galleries and now I can get them restored. The images are still in the uploads directory (I even restored my backup), but now WordPress won’t pick them up! Do you know how to fix this?

    • Posted February 18, 2010 at 12:37 pm | Permalink

      Hi Adam,

      Ah yes, if your server is in safe mode, it may have trouble.

      If you have a database backup, the simplest thing I can advise is to selectively restore the database entries that correspond to the images (or the whole database).

      Failing that, it should be possible to put together a script to scan the entries in the uploads folder and re-enter the records in the database. It’d take a bit of doing, though. If you’re desperate, I’m happy to give you a quote (if so, give me a bell).

  4. Posted February 17, 2010 at 1:35 pm | Permalink

    Sorry, should have said “can’t get them restored”.

  5. Posted February 23, 2010 at 2:18 pm | Permalink

    Hi, I like your plugin, but had to undo the delete Im affraid. I use extra fields in my posts to show thumbnails on my homepage. Upload Janitor marked them all as unused causing me to delete them all. Luckily I had a backup. The plugin does however have a good function. Ill wait for the next version.

    • Posted October 5, 2011 at 1:26 am | Permalink

      GTK. I have a similar set up and I’m hesitant to install as I don’t know what’s going to happen to those. I am developing the site and i’m early along enough that if I do have to do that, I’d be ok with the small amount of work ensued.

  6. Posted May 28, 2010 at 8:17 am | Permalink

    Im looking for a WP-Plugin, to delete unused images. The space of my upload file is over 400 MB. I startet your plugin in the evening and it works and works over 9 hour, but nothing is hapend. My questions: can I choose a smaller subfolder? I think, 400 MB are too big. Greetings, Jana

    • Posted May 29, 2010 at 2:31 pm | Permalink

      Hi Jana,

      Oh dear – that doesn’t sound right! 400MB shouldn’t be a problem at all (mine’s much larger).

      Specifically, which point does it get stuck at? Did you see the “Select files to delete” page? Or just the start page with “Press Begin below to start”?

      One thought: Do you have any recursive symbolic links within your wp-content folder? There’s a chance it’s getting stuck in a loop (although I would then expect it to die with a memory exhausted error…).

  7. Posted May 29, 2010 at 5:36 pm | Permalink

    I see the start page “Press Begin below to start”, than I click at the button and I can see the searching screen… last time he searched over 9 ours (I let this running over night). No error page, no select file page… only the searching site. No, I haven’t any recursive symbolic in this folder.

    • Posted July 15, 2010 at 7:18 pm | Permalink

      Im running into the same problem as above, only problem is i have 2500 posts, and 2.7 gigs worth of images and Mp3′s.

      I tried to change the upload directory to each specific year and month, and run them one at a time, but it dosent seem to work well.

      and if i use it straight to the Upload directory, i get the same blank screen.

      I increased my max times in php.ini to maybe give me a better shot of not timing out, but no such luck.

      Any help on this would be greatly appreciated !!

      Owen

      • Posted July 19, 2010 at 12:45 pm | Permalink

        Hi Owen,

        Ah yes, I’m not entirely surprised it’s having trouble. Unfortunately at this point there’s not much I can advise. At some point I’ll see if I can alter the plugin’s operation to be able to work with huge data sets like this – stay tuned.

        • Posted July 19, 2010 at 5:18 pm | Permalink

          Right on, Thanks Michael.

          Ive been trying to mess with the timeout limits in the php ini file to give it a fighting chance, but its been to no luck as of lately. Feel free to shoot me an e-mail if you want me to test it on one of my larger blogs.

          Thanks again

  8. Luke Mackenzie
    Posted August 5, 2010 at 2:16 pm | Permalink

    Does this support WordPress MU 2.9.2?

    • Posted August 5, 2010 at 2:30 pm | Permalink

      I honestly have no idea, Luke =)

  9. Andreas
    Posted October 6, 2010 at 9:41 pm | Permalink

    Hi, great plugin, I have one concern though. I’m adding images to the meta data fields of my posts. This however isn’t recognized by the upload janitor plugin. Is it possible to change this in future versions of the plugin so that images added to the metadata fields of posts are left untouched.

    Thanks for your time.

    Andreas

  10. Posted January 12, 2011 at 9:26 am | Permalink

    Hiya– I am running WP 3.1 RC2 and the plugin tried to delete all images (even attached to posts).

    Could you please update the plugin or mention which piece of code to look at to fix it? ;)

    Looking forward to using this plugin for some massive cleanup!

    • Jools
      Posted March 25, 2011 at 7:39 pm | Permalink

      Me too. It tries to delete every single image file in the system when running under wordpress 3.1.

      Thanks so much for your time. J

  11. kkk
    Posted January 14, 2011 at 7:36 am | Permalink

    it doesnt work for me i get ‘white page’ after a hit begin…i even disable all plugins and got same thing…any ideas?

  12. Posted January 26, 2011 at 6:21 pm | Permalink

    It seems to time out – testing it on a site with about 70,000 image files in the upload directory for a total of approximately 250MB.

    Would that be too much for the script to handle?

  13. theMikeD
    Posted March 28, 2011 at 2:34 am | Permalink

    Hi there,

    Great plugin. And now that’s done, I’m after a way to go though the database and delete entries to files that don’t actually exist…sort of the opposite of this plugin. Do you know of a plugin, or an SQL command, that would do that?

    …Mike

  14. LeCrayonVert
    Posted August 15, 2011 at 12:37 pm | Permalink

    It should NOT remove header and background image files …..

  15. Peeter
    Posted August 16, 2011 at 12:18 pm | Permalink

    Hello,

    This plugin seems great, but it’s not working. I start it, but (I’m at Hostgator) after nothing, white screen.

    But I need to run, because there are many posts and images what I have to delete.

    Have you got any suggestion or idea?

    Thanks

  16. Posted September 8, 2011 at 3:29 pm | Permalink

    Since this plug-in is not being actively developed, does anyone know of an alternative plug-in that performs the same function (to help clean-up the upload directory)??

    • Scott
    • Posted January 8, 2012 at 12:23 am | Permalink

      I have the same question, this plugin is so great! but it’s not developed anymore, and it’s not compatible with new version of WordPress

  17. Hil
    Posted January 28, 2012 at 7:58 pm | Permalink

    Hi Michael, You have a great plugin Although when I run the plugin like several others have mentioned, the plugin times out after a little while. One also you have to run the plugin manually.

    Would it be possible to modify the plugin to run automatically and report when it finds orphans. An ideal example is the “Broken Link Checker” plugin. Also I believe the plugin fails after a while because it may be using excessive load. You could probably restrict the server load. You can see the same again in “Broken Link Checker” – Advanced – Server load limit . This way the plugin will use minimal resources and still get orphans

    Thanks

  18. Posted December 3, 2012 at 2:26 am | Permalink

    HELP! I ran your plugin and now my slider images as well as other images are GONE! I cannot get the images to restore. When I copy them manually back into the folders for some reason they still don’t show up in my blog posts! This plugin has caused me a huge mess. Can you please help me restore my images? We’re talking about 3 years of blog posts here and a huge number of images…

    • Posted December 3, 2012 at 3:21 am | Permalink

      Leanna, it could be that your posts are using images sizes generated by wordpress that no longer exist if they were deleted. Make sure you regenerate your thumbnails using one of the several plugins designed for this purpose. Click “Plugins” then “Add New” and in the search box, enter “thumbnail rebuild” HTH!

      To everyone else: this plugin is no longer maintained (hasn’t been updated since early 2010) so use it with caution.