Na de submit lees ik de ingevulde velden in:
$attachments = $_FILES['file'];
Nu wil ik een extra naam toevoegen aan de array(). Hoe doe ik dat?
$attachments = $_FILES['file'];
1:<input type="file" name="file[]" accept=".jpg,.png,.jpeg,.pdf"/><br>
2:<input type="file" name="file[]" accept=".jpg,.png,.jpeg,.pdf"/><br>
3:<input type="file" name="file[]" accept=".jpg,.png,.jpeg,.pdf"/><br>
4:<input type="file" name="file[]" accept=".jpg,.png,.jpeg,.pdf"/>
$attachments = $_FILES['file'];
<?php
if ( $_POST['submit']):
$attachments = [];
echo '<pre>files = ' . print_r($_FILES, TRUE ) . '</pre>';
$attachments = $_FILES['file'];
echo '<pre>a1 = ' . print_r( $attachments, TRUE ) . '</pre>';
$imgsize = filesize( 'logo.jpg' );
$attachments['name'] = $attachments['name'] + ['logo' => 'logo.jpg'];
$attachments['size'] = $attachments['size'] + ['logo' => $imgsize];
echo '<pre>a2 = ' . print_r( $attachments, TRUE ) . '</pre>';
echo '<p>Toegevoegd logo : ' . $attachments['name']['logo'] . '</p>';
foreach ($attachments['name'] as $key => $value):
if ( $value ):
echo $key . ' = ' . $value . ' (' . (int)($attachments['size'][$key]/1000) . 'kB)<br />';
endif;
endforeach;
endif;
?>
<hr />
<form method="post" action="" enctype="multipart/form-data">
1:<input type="file" name="file[]" accept=".jpg,.png,.jpeg,.pdf"/><br />
2:<input type="file" name="file[]" accept=".jpg,.png,.jpeg,.pdf"/><br />
3:<input type="file" name="file[]" accept=".jpg,.png,.jpeg,.pdf"/><br />
4:<input type="file" name="file[]" accept=".jpg,.png,.jpeg,.pdf"/><br />
<input type="submit" name="submit" value="submit" />
</form>