It is developed to upload files to local or remote server.
composer require initphp/upload
Returns a normalized Array<\InitPHP\Upload\File>
from the array $_FILES
with the specified $key
.
Loads a specific file into the file object.
use InitPHP\Upload\Upload;
use InitPHP\Upload\File;
$credentials = [
'dir' => __DIR__ . '/uploads/',
'url' => 'https://example.com/uploads/',
];
$options = [
'allowed_extensions' => [],
'allowed_mime_types' => [],
'allowed_max_size' => 0,
];
$adapter = new InitPHP\Upload\Adapters\LocalAdapter($credentials, $options);
$upload = new Upload($adapter);
foreach (File::setPost('files') as $file) {
$upload->setFile($file)
->to();
}
use InitPHP\Upload\Upload;
use InitPHP\Upload\File;
$credentials = [
'host' => 'ftp.example.com',
'port' => 21,
'username' => 'user',
'password' => '123456',
'timeout' => 90,
'url' => 'http://example.com/',
];
$options = [
'allowed_extensions' => [],
'allowed_mime_types' => [],
'allowed_max_size' => 0,
];
$adapter = new InitPHP\Upload\Adapters\FTPAdapter($credentials, $options);
$upload = new Upload($adapter);
foreach (File::setPost('files') as $file) {
$upload->setFile($file)
->to();
}
use InitPHP\Upload\Upload;
use InitPHP\Upload\File;
$credentials = [
'key' => '',
'secret_key' => '',
'region' => '',
'bucket' => '',
'ACL' => 'public-read',
'version' => 'latest',
];
$options = [
'allowed_extensions' => [],
'allowed_mime_types' => [],
'allowed_max_size' => 0,
];
$adapter = new InitPHP\Upload\Adapters\S3Adapter($credentials, $options);
$upload = new Upload($adapter);
foreach (File::setPost('files') as $file) {
$upload->setFile($file)
->to();
}
Copyright © 2023 MIT License