What steps can be taken to troubleshoot and resolve issues related to file uploads in PHP, especially when dealing with large file sizes?

Issue: When uploading large files in PHP, you may encounter issues such as exceeding the maximum upload size limit set in php.ini or running out of memory during the upload process. To resolve these issues, you can increase the upload size limit in php.ini, adjust the memory_limit and post_max_size settings, or use chunked file uploads to handle large files more efficiently.

// Increase upload size limit in php.ini
// Set memory limit and post max size
ini_set('upload_max_filesize', '20M');
ini_set('post_max_size', '20M');
ini_set('memory_limit', '128M');

// Handle file upload
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
    $file = $_FILES['file'];
    $uploadPath = 'uploads/' . $file['name'];

    if (move_uploaded_file($file['tmp_name'], $uploadPath)) {
        echo 'File uploaded successfully!';
    } else {
        echo 'Failed to upload file.';
    }
}