/**
  * Copy a file to the mediaLibrary for the given $media.
  *
  * @param string                     $file
  * @param \Spatie\MediaLibrary\Media $media
  * @param bool                       $conversions
  * @param string                     $targetFileName
  */
 public function copyToMediaLibrary($file, Media $media, $conversions = false, $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+'));
     } else {
         $this->filesystem->disk($media->disk)->getDriver()->put($destination, fopen($file, 'r+'), ['ContentType' => File::getMimeType($file)]);
     }
 }
 /**
  * Get the headers to be used when copying the
  * given file to a remote filesytem.
  *
  * @param string $file
  *
  * @return array
  */
 public function getRemoteHeadersForFile($file)
 {
     $mimeTypeHeader = ['ContentType' => File::getMimeType($file)];
     $extraHeaders = $this->config->get('laravel-medialibrary.remote.extra_headers');
     return array_merge($mimeTypeHeader, $extraHeaders);
 }
Exemplo n.º 3
0
 /**
  * Copy a file to the mediaLibrary for the given $media.
  *
  * @param string                     $file
  * @param \Spatie\MediaLibrary\Media $media
  * @param string                     $subDirectory
  * @param string                     $targetFileName
  */
 public function copyToMediaLibrary($file, Media $media, $subDirectory = '', $targetFileName = '')
 {
     $destination = $this->getMediaDirectory($media) . '/' . ($subDirectory != '' ? $subDirectory . '/' : '') . ($targetFileName == '' ? pathinfo($file, PATHINFO_BASENAME) : $targetFileName);
     $this->filesystems->disk($media->disk)->getDriver()->put($destination, fopen($file, 'r+'), ['ContentType' => File::getMimeType($file)]);
 }