renameInDirectory() public static method

* Rename a file.
public static renameInDirectory ( string $fileNameWithDirectory, string $newFileNameWithoutDirectory ) : string
$fileNameWithDirectory string
$newFileNameWithoutDirectory string
return string
コード例 #1
0
 /**
  * Perform the given conversions for the given media.
  *
  * @param \Spatie\MediaLibrary\Conversion\ConversionCollection $conversions
  * @param \Spatie\MediaLibrary\Media                           $media
  */
 public function performConversions(ConversionCollection $conversions, Media $media)
 {
     $tempDirectory = $this->createTempDirectory();
     $copiedOriginalFile = $tempDirectory . '/' . str_random(16) . '.' . $media->extension;
     app(Filesystem::class)->copyFromMediaLibrary($media, $copiedOriginalFile);
     if ($media->type == Media::TYPE_PDF) {
         $copiedOriginalFile = $this->convertToImage($copiedOriginalFile);
     }
     foreach ($conversions as $conversion) {
         $conversionResult = $this->performConversion($media, $conversion, $copiedOriginalFile);
         $renamedFile = MediaLibraryFileHelper::renameInDirectory($conversionResult, $conversion->getName() . '.' . $conversion->getResultExtension(pathinfo($copiedOriginalFile, PATHINFO_EXTENSION)));
         app(Filesystem::class)->copyToMediaLibrary($renamedFile, $media, 'conversions');
     }
     File::deleteDirectory($tempDirectory);
 }
コード例 #2
0
 /**
  * Perform the given conversions for the given media.
  *
  * @param \Spatie\MediaLibrary\Conversion\ConversionCollection $conversions
  * @param \Spatie\MediaLibrary\Media $media
  */
 public function performConversions(ConversionCollection $conversions, Media $media)
 {
     $imageGenerator = $this->determineImageGenerator($media);
     if (!$imageGenerator) {
         return;
     }
     $tempDirectory = $this->createTempDirectory();
     $copiedOriginalFile = $tempDirectory . '/' . str_random(16) . '.' . $media->extension;
     app(Filesystem::class)->copyFromMediaLibrary($media, $copiedOriginalFile);
     foreach ($conversions as $conversion) {
         $copiedOriginalFile = $imageGenerator->convert($copiedOriginalFile, $conversion);
         $conversionResult = $this->performConversion($media, $conversion, $copiedOriginalFile);
         $renamedFile = MediaLibraryFileHelper::renameInDirectory($conversionResult, $conversion->getName() . '.' . $conversion->getResultExtension(pathinfo($copiedOriginalFile, PATHINFO_EXTENSION)));
         app(Filesystem::class)->copyToMediaLibrary($renamedFile, $media, true);
         event(new ConversionHasBeenCompleted($media, $conversion));
     }
     File::deleteDirectory($tempDirectory);
 }