Support » Plugin: Overwrite Uploads » Plugin has stopped working

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Ian Dunn


    The first thing to try would be to temporarily disable all other plugins, and switch to one of the Core themes (like TwentyTwelve), then test if it works.

    If it does work, then re-activate the plugins one by one and re-test until you find the one that causes it to stop working.

    Keep in mind that the plugin won’t try to overwrite files with the same name if they’re in different directories. See the FAQ for details.

    I’m also having some issues with this plugin, and I think I’ve narrowed it down to a very strange issue with the file_exists() function.

    For me, any filename that has a space in it will not be overwritten, but instead duplicated, because the file_exists()line is returning false.
    I’ve tried replacing the $file['name'] with str_replace(' ', '\\ ', $file['name'] with no luck.

    I have found many reports about this function being buggy, and the only “answer” seems to be “fix the file permissions” (which isn’t the problem for me).

    Any advice on a workaround would be greatly appreciated.

    I finally realized that WordPress has been replacing spaces with dashes in my uploaded filenames, so for me the easy fix was just to use

    $upload_dir = wp_upload_dir();
    	$filename = str_replace(' ', '-', $file['name']);
    	if(file_exists($upload_dir['path'] . '/' . $filename)) {
    		$args = array(
    			'numberposts' => 1,
    			'post_type' => 'attachment',
    			'meta_query' => array(
    					'key' => '_wp_attached_file',
    					'value' => trim($upload_dir['subdir'] . '/' . $filename, '/')
    		$attachment_file = get_posts($args);
    		if(isset($attachment_file[0]->ID)) {
    			if($file['size'] != filesize(get_attached_file($attachment_file[0]->ID)) ) {
    				wp_delete_attachment( $attachment_file[0]->ID, true );
    			}else {
    				$file = array('error'=>'Image ' . $filename . ' already exists.');
    	return $file;

    and now everything works great.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Plugin has stopped working’ is closed to new replies.