How can I optimize file upload processes in PHP to prevent long wait times for users?

To optimize file upload processes in PHP and prevent long wait times for users, you can increase the maximum execution time and memory limit in your PHP configuration settings. Additionally, you can use AJAX to asynchronously upload files in the background while displaying a progress bar to the user.

// Increase maximum execution time and memory limit
ini_set('max_execution_time', 300); // 5 minutes
ini_set('memory_limit', '256M');

// AJAX file upload handling
if(isset($_FILES['file'])) {
    $targetDir = "uploads/";
    $targetFile = $targetDir . basename($_FILES["file"]["name"]);
    
    if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFile)) {
        echo "File uploaded successfully!";
    } else {
        echo "Error uploading file.";
    }
}