1. Go to this page and download the library: Download melsaka/mediafile 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/ */
// import the MediaFolder Class
use Melsaka\MediaFile\MediaFolder;
// create a MediaFolder instance
$mediafolder = new MediaFolder();
// and finally create the folder
$mediafolder->store($request->name, $request->order);
$mediafolder->update($request, $folder);
$mediafolder->delete($folder);
// import the MediaFile Class
use Melsaka\MediaFile\MediaFile;
// select the folder that you wanna upload images into it.
$folder = Folder::whereSlug($request->folder)->firstOrFail();
// create a MediaFile instance
$mediafile = new MediaFile($folder);
// and finally upload/store the iamge
$mediafile->store($request->file('image'));
namespace App\Livewire;
use Livewire\Component;
use Livewire\WithFileUploads;
class UploadPhoto extends Component
{
use WithFileUploads;
public $photo;
public function save()
{
$uploadedImage = $mediafile->livewireFile($this->photo);
$mediafile->store($uploadedFile);
}
}
$mediafile = new MediaFile($folder);
$mediafile->isFolder($media);
use Melsaka\MediaFile\Models\Media;
$media = Media::first();
// User Instance
$media->user;
// Fodler Instance
$media->folder;
// File name without extension
$media->name;
// File extension
$media->extension;
// The encoder used for this image, ex: webp
$media->encoder;
// The type of the file, ex: Image/png
$media->type;
// The uri of the file, ex: storage/images/2023/08/image.png
$media->uri;
// The width of the image, ex: 1920
$media->width;
// The height of the image, ex: 1080
$media->height;
// The alt of the image file
$media->alt;
// The title of the image file
$media->title;
// The caption of the image file
$media->caption;
// returns the original file url
$media->getFileLink();
// returns the full file name, ex: image.png
$media->getFileName();
// returns file size, ex: 128 kb
$media->getFileSize();
// returns true if file is image
$media->isFileAnImage();
// returns the url of the encoded version of the original image file.
$media->getEncodedImageLink();
// returns the sizes and urls of the image thumbnails when $onlySizes is true,
// when you set $onlySizes to false it will returns the seperator, sizes, and urls.
// The $name param allows to get the url of a single thumbnail, ex: $media->getThumbnail('s')
$media->getThumbnails($name = null, $onlySizes = true);
// returns the srcset of an image file.
$media->getSrcset();
// returns the sizes of an image file.
$media->getSizes();
use Illuminate\Support\Facades\Route;
use Melsaka\MediaFile\MediaFile;
MediaFile::routes();
MediaFile::routes('media');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.