/** * Copy a file from the mediaLibrary to the given targetFile. * * @param \Spatie\MediaLibrary\Media $media * @param string $targetFile */ public function copyFromMediaLibrary(Media $media, $targetFile) { $sourceFile = $this->getMediaDirectory($media) . '/' . $media->file_name; touch($targetFile); $stream = $this->disk->getDriver()->readStream($sourceFile); file_put_contents($targetFile, stream_get_contents($stream), FILE_APPEND); fclose($stream); }
/** * @param NewImageEvent $event */ private function transferImageFiles(NewImageEvent $event) { $preProcessed = $this->imagePreProcessor->preProcess($event->image()); /** @var ImagickContract $imagick */ foreach ($preProcessed as $imagick) { $this->publicFilesystem->getDriver()->put("image/{$imagick->getFilename()}", $imagick->getImageBlob(), self::fileConfig()); } }
public function write(string $file) { if (is_null($this->disk)) { throw InvalidBackupDestination::diskNotSet(); } $destination = $this->backupName . '/' . pathinfo($file, PATHINFO_BASENAME); $handle = fopen($file, 'r+'); $this->disk->getDriver()->writeStream($destination, $handle); }
public function allLinks($from) { $files = $this->filesystem->allFiles($this->getBaseDir() . DIRECTORY_SEPARATOR . $from); $links = []; foreach ($files as $key => $file) { $links[$key] = url(env('LOCAL_BASE_DIR') . DIRECTORY_SEPARATOR . $file); $files[$key] = $this->filesystem->getDriver()->getAdapter()->getPathPrefix() . $files[$key]; } return ['files' => $files, 'links' => $links]; }
/** * @param $filepath * @return mixed|void */ public function getUrl($filepath) { switch ($this->diskName) { case 's3': return $this->storage->getDriver()->getAdapter()->getClient()->getObjectUrl(); case 'local_public': $storagepath = str_ireplace(public_path(), '', config('filesystems.disks.local_public.root')); return url($storagepath . '/' . $filepath); } return null; }