PHP code example of marko / media
1. Go to this page and download the library: Download marko/media 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/ */
marko / media example snippets
use Marko\Media\Contracts\MediaManagerInterface;
use Marko\Media\Value\UploadedFile;
class PostController
{
public function __construct(
private MediaManagerInterface $mediaManager,
) {}
public function uploadAvatar(): void
{
$file = new UploadedFile(
name: $_FILES['avatar']['name'],
tmpPath: $_FILES['avatar']['tmp_name'],
mimeType: $_FILES['avatar']['type'],
size: $_FILES['avatar']['size'],
extension: pathinfo($_FILES['avatar']['name'], PATHINFO_EXTENSION),
);
$media = $this->mediaManager->upload($file);
}
}