Help with a plugin on MU

Hi, I threw the following code into a .php file with the requisite meta to make it work as a plugin. It’s just code I found a while back and have used on a bunch of site. It’s throwing errors occasionally when the image is over a certain resolution or file size (not sure which). I’m wondering if anyone who’s better at code/MU than myself who can give me some idea of why it’s doing this?

EDIT: sorry I forgot to explain. This code renames the large size image to the same as the original, fullsize, so that it replaces it. This means you can set the large size under Settings>Media and that will become the fullsize image. It’s super helpful in many cases.

Here’s the code:

Plugin Name: Resize Fullsize Image
Plugin URI:
Description: Resizes the full-size image to the "large" size defined under Settings>Media.
Version: 0.1
Author: Unknown
Author URI:
License: GPL2

/* limits image size to large setting */
function replace_uploaded_image($image_data) {

if (!isset($image_data['sizes']['large'])) return $image_data;

// paths to the uploaded image and the large image
$upload_dir = wp_upload_dir();
$uploaded_image_location = $upload_dir['basedir'] . '/' .$image_data['file'];
$large_image_location = $upload_dir['path'] . '/'.$image_data['sizes']['large']['file'];

// delete the uploaded image

// rename the large image

// update image metadata and return them
$image_data['width'] = $image_data['sizes']['large']['width'];
$image_data['height'] = $image_data['sizes']['large']['height'];

return $image_data;


Here’s the error:

Warning: rename(/home/mainsite/public_html/wp-content/blogs.dir/7/files/2012/02/test-name-800x600.jpg,/home/fiddlers/public_html/wp-content/blogs.dir/7/files/2008/10/test-name.jpg) [function.rename]: No such file or directory in /home/fiddlers/public_html/wp-content/plugins/resize-image-plugin.php on line 27

  • Tevya
    • Recruit

    Okay, I looked into this further. It works fine on one of the other sites on this same Multisite install. So I know it’s got to be related to this specific theme/site.

    If you look at the Warning:

    Warning: rename(/home/fiddlers/public_html/wp-content/blogs.dir/7/files/2012/02/DSCF2897-450×600.jpg,/home/fiddlers/public_html/wp-content/blogs.dir/7/files/2008/10/DSCF2897.jpg) [function.rename]: No such file or directory in /home/fiddlers/public_html/wp-content/plugins/resize-image-plugin.php on line 27


    You’ll notice that the file that’s being renamed has a different path than where it’s being renamed to. You’ll notice it’s “/2012/02/” in the first and “/2008/10/” when being renamed.

    EDIT: I checked the file path, and it’s being uploaded to the “2008/10/” folder, which it shouldn’t be. It should be uploaded to the current month “2012/02/”. Then when it goes to rename it in “2012/02/”, it can’t because the file is not there.

    I tried turning off date-based folder organization for that site, and it works just fine, no problems. However, I really prefer to have that organization in place. Any of you WPMUDEV geniuses have any idea how I can make this work? I’d really appreciate it. In fact, I’m surprised that a lot more people don’t use this plugin to limit the file size of image uploads on Multisite.

  • Tevya
    • Recruit

    Okay, one more update. I figured it out. Since I migrated this site from a single-site install, it has old pages/posts. The page I was working on was from 2008/10 so that’s where the image was getting uploaded to. However the plugin assumed it was the current month (I guess). So when it would go to rename the file in 2012/02 it wasn’t there. Simply updating the publish date of the page to the current month, fixed the problem.

    Anyone know if there’s some way I can modify the code to look in the correct folder if it’s an older post/page?

  • aecnu
    • WP Unicorn

    Greetings Tevya Washburn,

    Thank you for being a WPMU Dev member!

    I’ll see if I can get the lead developer in here to assist / give you some advice on your custom code even though this is not a WPMU Dev plugin issue, to see if we can help you get it sorted.

    Cheers, Joe :slight_smile:

  • Tevya
    • Recruit

    That would be great. It’s not a big deal, as I can just update the post date on the page, if needed. But It would be great if it’s just something he can look at real quick and say “yeah just replace this: xxxx with this: xxxx.” Thanks.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.