1. Go to this page and download the library: Download tvanc/files-array-organizer library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tvanc / files-array-organizer example snippets
use tvanc\FilesArrayOrganizer\FilesArrayOrganizer;
if ($_FILES) {
$organizedFiles = FilesArrayOrganizer::organize($_FILES);
if ($organizedFiles === $_FILES) {
echo "Looks like you didn't really need to do that.";
}
}
use tvanc\FilesArrayOrganizer\FilesArrayOrganizer;
if ($_FILES) {
$organizedFiles = FilesArrayOrganizer::organize($_FILES);
$attachments = $organizedFiles['attachments'];
foreach ($attachments as $attachment) {
$attachment_name = $attachment['name'];
$attachment_size = $attachment['size'];
}
}
use tvanc\FilesArrayOrganizer\FilesArrayOrganizer;
// @var Todo[] $todos An array of todos
$todos = fetchTodos();
if ($_FILES) {
$organizedFiles = FilesArrayOrganizer::organize($_FILES);
foreach ($organizedFiles as $index => $postedTodo) {
$attachments = $organizedFiles['todo'][$index];
saveAttachments($index, $attachments);
}
}
use tvanc\FilesArrayOrganizer\FilesArrayOrganizer;
use YourOwn\MadeUpNameSpace\UploadedFile;
// Receive $file by reference to mutate it. You can even replace it entirely.
$callback = function (array & $file) {
$file = new UploadedFile($file);
}
$organizedFilesArray = FilesArrayOrganizer::organize($_FILES, $callback);
// $attachments will be an array of UploadedFile objects
$attachments = $organizedFilesArray['attachments'];