Code Duplication    Length = 17-21 lines in 2 locations

sources/upload/upload.attachments.php 1 location

@@ 229-249 (lines=21) @@
226
}
227
228
// Remove old temp files
229
if ($cleanupTargetDir && is_dir($targetDir) && ($dir = opendir($targetDir))) {
230
    while (($file = readdir($dir)) !== false) {
231
        $tmpfilePath = $targetDir.DIRECTORY_SEPARATOR.$file;
232
233
        // Remove temp file if it is older than the max age and is not the current file
234
        if (preg_match('/\.part$/', $file)
235
            && (filemtime($tmpfilePath) < time() - $maxFileAge)
236
            && ($tmpfilePath != "{$filePath}.part")
237
        ) {
238
            try {
239
                unlink($tmpfilePath);
240
            } catch(Exception $e){
241
                print_r($e);
242
            }
243
        }
244
    }
245
246
    closedir($dir);
247
} else {
248
    die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');
249
}
250
251
// Look for the content type header
252
if (isset($_SERVER["HTTP_CONTENT_TYPE"])) {

sources/upload/upload.files.php 1 location

@@ 184-200 (lines=17) @@
181
}
182
183
// Remove old temp files
184
if ($cleanupTargetDir && is_dir($targetDir) && ($dir = opendir($targetDir))) {
185
    while (($file = readdir($dir)) !== false) {
186
        $tmpfilePath = $targetDir.DIRECTORY_SEPARATOR.$file;
187
188
        // Remove temp file if it is older than the max age and is not the current file
189
        if (preg_match('/\.part$/', $file)
190
            && (filemtime($tmpfilePath) < time() - $maxFileAge)
191
            && ($tmpfilePath != "{$filePath}.part")
192
        ) {
193
            unlink($tmpfilePath);
194
        }
195
    }
196
197
    closedir($dir);
198
} else {
199
    die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');
200
}
201
202
// Look for the content type header
203
if (isset($_SERVER["HTTP_CONTENT_TYPE"])) {