diff --git a/inc/JpegMeta.php b/inc/JpegMeta.php
index af7d27f9615522f7ad78b49451d4b8605dd55048..eb9ab8627de08ac2971abb88dd3b0bac4bc90fd4 100644
--- a/inc/JpegMeta.php
+++ b/inc/JpegMeta.php
@@ -841,7 +841,7 @@ class JpegMeta
             $tmpName = tempnam(dirname($this->_fileName),'_metatemp_');
             $this->_writeJPEG($tmpName);
             if (@file_exists($tmpName)) {
-                return rename($tmpName, $this->_fileName);
+                return io_rename($tmpName, $this->_fileName);
             }
         } else {
             return $this->_writeJPEG($fileName);
diff --git a/inc/io.php b/inc/io.php
index ff318bd67f24e3bd29455a4ca05357ccb82fa149..9c02e87c6e7c70009bcffde059eb741435751a11 100644
--- a/inc/io.php
+++ b/inc/io.php
@@ -318,6 +318,24 @@ function io_download($url,$file,$useAttachment=false,$defaultName=''){
   return true;
 }
 
+/**
+ * Windows copatible rename
+ *
+ * rename() can not overwrite existing files on Windows
+ * this function will use copy/unlink instead
+ */
+function io_rename($from,$to){
+  if(!@rename($from,$to)){
+    if(@copy($from,$to)){
+      @unlink($from);
+      return true;
+    }
+    return false;
+  }
+  return true;
+}
+
+
 /**
  * Runs an external command and returns it's output as string
  *