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.

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

Related posts

Tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

8 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.

  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.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Subscribe without commenting