$lastChar = substr($sourceFile, -1); if ($lastChar == $ds || $lastChar == '/') { if (!$ftp->mkdir($targetFile)) { $error = "Error creating the directory {$targetFile}"; http_response_code(400); die($error); } continue; } $targetDir = dirname($targetFile); if (!is_dir($targetDir) && !@$ftp->mkdir($targetDir)) { $error = "Error creating the new folder {$targetDir}"; http_response_code(400); die($error); } if (!$ftp->copy($sourceFile, $targetFile)) { $error = "Error copying {$filename} to {$targetFile}"; http_response_code(400); die($error); } } if ($dirCount > 0) { $warning = "Ignoring {$dirCount} folders, which already exist on your server.<br />"; } $zip->close(); $success = "Congratulations, you have successfully updated the plugin."; ob_end_clean(); http_response_code(200); header('Content-Type: application/json'); echo json_encode(array('success' => $success, 'warning' => $warning)); exit;