file_exists($newPath) || $sftp->is_dir($newPath)) { die("Error: A file or directory with this name already exists."); } if ($sftp->rename($oldPath, $newPath)) { header("Location: index.php?path=" . urlencode($dirPath)); exit; } else { die("Failed to rename the item. Please try again."); } } else { header("Location: index.php"); exit; } ?>