What are some best practices for allowing users to upload files to a server securely without giving them FTP access?

Allowing users to upload files to a server securely without giving them FTP access can be achieved by creating a file upload form on a webpage and handling the file upload process using PHP. By using PHP to validate and process the uploaded files, you can ensure that only allowed file types and sizes are accepted, and that the files are stored in a secure location on the server.

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
    $uploadDir = 'uploads/';
    $uploadFile = $uploadDir . basename($_FILES['file']['name']);

    if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile)) {
        echo 'File is valid, and was successfully uploaded.';
    } else {
        echo 'Upload failed.';
    }
}
?>

<form action="" method="post" enctype="multipart/form-data">
    Select file to upload:
    <input type="file" name="file">
    <input type="submit" value="Upload File" name="submit">
</form>