How can PHP scripts be used to manage folder creation, file uploads, and deletions in a way that avoids FTP access issues?

When managing folder creation, file uploads, and deletions in PHP, it is important to use the built-in functions like mkdir() for creating folders, move_uploaded_file() for file uploads, and unlink() for file deletions. By using these functions, you can avoid FTP access issues and ensure that the operations are performed securely within the server environment.

// Create a folder
$folderPath = 'uploads/';
if (!file_exists($folderPath)) {
    mkdir($folderPath, 0777, true);
}

// Upload a file
if ($_FILES['file']['error'] === UPLOAD_ERR_OK) {
    $tempFile = $_FILES['file']['tmp_name'];
    $targetFile = $folderPath . $_FILES['file']['name'];
    move_uploaded_file($tempFile, $targetFile);
}

// Delete a file
$fileToDelete = 'uploads/example.txt';
if (file_exists($fileToDelete)) {
    unlink($fileToDelete);
}