Author: Sean Fraser (sean@plankdesign.com)
 /**
  * Search through the record list for one matching the provided path.
  * @param  string $path
  * @param  \Illuminate\Database\Eloquent\Collection $existing_media
  * @return \Plank\Mediable\Media|null
  */
 protected function getRecordForFile($path, $existing_media)
 {
     $directory = File::cleanDirname($path);
     $filename = pathinfo($path, PATHINFO_FILENAME);
     $extension = pathinfo($path, PATHINFO_EXTENSION);
     return $existing_media->filter(function (Media $media) use($directory, $filename, $extension) {
         return $media->directory == $directory && $media->filename == $filename && $media->extension == $extension;
     })->first();
 }
Example #2
0
 public function test_it_converts_bytes_to_readable_strings()
 {
     $this->assertEquals('0 B', File::readableSize(0));
     $this->assertEquals('1 KB', File::readableSize(1025, 0));
     $this->assertEquals('1.1 MB', File::readableSize(1024 * 1024 + 1024 * 100, 2));
 }
Example #3
0
 /**
  * Create a `Media` record for a file already on a disk.
  * @param  string $disk
  * @param  string $path Path to file, relative to disk root
  * @return \Plank\Mediable\Media
  */
 public function importPath($disk, $path)
 {
     $directory = File::cleanDirname($path);
     $filename = pathinfo($path, PATHINFO_FILENAME);
     $extension = pathinfo($path, PATHINFO_EXTENSION);
     return $this->import($disk, $directory, $filename, $extension);
 }
Example #4
0
 /**
  * Calculate the file size in human readable byte notation.
  * @param  int $precision (_optional_) Number of decimal places to include.
  * @return string
  */
 public function readableSize($precision = 1)
 {
     return File::readableSize($this->size, $precision);
 }