How can PHP scripts be used to create and manage a container for PDF files?

To create and manage a container for PDF files using PHP scripts, you can use a combination of PHP functions to upload, store, retrieve, and delete PDF files. One approach is to use a file upload form to allow users to upload PDF files, store them in a designated directory on the server, and then provide functionality to list, download, and delete the files as needed.

<?php
// Handle file upload
if(isset($_FILES['pdf_file'])){
    $target_dir = "pdf_files/";
    $target_file = $target_dir . basename($_FILES['pdf_file']['name']);
    
    if(move_uploaded_file($_FILES['pdf_file']['tmp_name'], $target_file)){
        echo "File uploaded successfully.";
    }else{
        echo "Error uploading file.";
    }
}

// List PDF files in the container
$files = glob("pdf_files/*.pdf");
foreach($files as $file){
    echo "<a href='$file' download>".basename($file)."</a><br>";
}

// Delete a PDF file
if(isset($_GET['delete'])){
    $file_to_delete = $_GET['delete'];
    if(unlink($file_to_delete)){
        echo "File deleted successfully.";
    }else{
        echo "Error deleting file.";
    }
}
?>