Spatie\MediaLibrary\Filesystem::copyToMediaLibrary PHP Method

copyToMediaLibrary() public method

* Copy a file to the medialibrary for the given $media.
public copyToMediaLibrary ( string $file, Media $media, boolean $conversions = false, string $targetFileName = '' )
$file string
$media Media
$conversions boolean
$targetFileName string
    public function copyToMediaLibrary(string $file, Media $media, bool $conversions = false, string $targetFileName = '')
    {
        $destination = $this->getMediaDirectory($media, $conversions) . ($targetFileName == '' ? pathinfo($file, PATHINFO_BASENAME) : $targetFileName);
        if ($media->getDiskDriverName() === 'local') {
            $this->filesystem->disk($media->disk)->put($destination, fopen($file, 'r+'));
            return;
        }
        $this->filesystem->disk($media->disk)->getDriver()->put($destination, fopen($file, 'r+'), $this->getRemoteHeadersForFile($file));
    }