How can a foreach loop be utilized to process multiple file uploads and their corresponding copyright inputs in a PHP form?
When processing multiple file uploads and their corresponding copyright inputs in a PHP form, a foreach loop can be utilized to iterate through the uploaded files array and handle each file along with its corresponding copyright input. This allows for efficient processing of multiple uploads without the need for repetitive code.
// Assuming the form fields are named 'file[]' for multiple file uploads and 'copyright[]' for corresponding copyright inputs
if(isset($_FILES['file'])){
$files = $_FILES['file'];
$copyrights = $_POST['copyright'];
foreach($files['tmp_name'] as $key => $tmp_name){
$file_name = $files['name'][$key];
$file_tmp = $tmp_name;
$copyright = $copyrights[$key];
// Process each file and its corresponding copyright input here
}
}