1. Go to this page and download the library: Download hizpark/file-uploader 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/ */
hizpark / file-uploader example snippets
use Hizpark\FileUploader\Local\FileUploader;
use Hizpark\FileUploader\Local\UploadContext;
use Hizpark\FileUploader\Local\UploadedFile;
use Hizpark\FileUploader\Validator\UploadedFileValidator;
$file = new UploadedFile('example.png', 'image/png', '/tmp/php123', 102400);
$context = new UploadContext(
basePath: '/var/www/uploads',
validator: new UploadedFileValidator()
);
$uploader = new FileUploader($context);
$result = $uploader->upload($file);
if ($result->isValid()) {
echo "File uploaded successfully: " . $result->getPath();
} else {
echo "Upload failed: " . $result->getError();
}
interface FileUploaderInterface
{
public function upload(UploadedFileInterface $file): UploadedFileResultInterface;
}
class UploadedFileValidator
{
public function __construct(array $allowedExtensions = ['jpg','png','gif','pdf'], int $maxSize = 5_000_000) { ... }
public function validate(UploadedFileInterface $file): ValidationResult { ... }
}