What are the potential pitfalls of using header('Location: ...') in PHP for redirecting after file upload?

Using header('Location: ...') for redirecting after file upload can potentially cause issues if there is any output sent before the header function is called. To avoid this, you can use output buffering to capture any output before the header function is called, and then redirect the user.

ob_start();

// File upload code here

ob_end_clean();
header('Location: newpage.php');
exit();