Пример #1
0
 /**
  * Create a file row from the given file
  * @param  UploadedFile $file
  * @return mixed
  */
 public function createFromFile(UploadedFile $file)
 {
     $fileName = FileHelper::slug($file->getClientOriginalName());
     $exists = $this->model->whereFilename($fileName)->first();
     if ($exists) {
         throw new \InvalidArgumentException('File slug already exists');
     }
     return $this->model->create(['filename' => $fileName, 'path' => "/assets/media/{$fileName}", 'extension' => $file->guessClientExtension(), 'mimetype' => $file->getClientMimeType(), 'filesize' => $file->getFileInfo()->getSize()]);
 }
Пример #2
0
 /**
  * Create a file row from the given file
  * @param  UploadedFile $file
  * @return mixed
  */
 public function createFromFile(UploadedFile $file)
 {
     $fileName = FileHelper::slug($file->getClientOriginalName());
     $exists = $this->model->whereFilename($fileName)->first();
     if ($exists) {
         $fileName = $this->getNewUniqueFilename($fileName);
     }
     return $this->model->create(['filename' => $fileName, 'path' => config('asgard.media.config.files-path') . "{$fileName}", 'extension' => substr(strrchr($fileName, "."), 1), 'mimetype' => $file->getClientMimeType(), 'filesize' => $file->getFileInfo()->getSize(), 'folder_id' => 0]);
 }
Пример #3
0
 /**
  * Create a file row from the given file
  * @param  UploadedFile $file
  * @return mixed
  */
 public function createFromFile(UploadedFile $file)
 {
     $fileName = FileHelper::slug($file->getClientOriginalName());
     $exists = $this->model->whereFilename($fileName)->first();
     if ($exists) {
         $fileName = $this->getNewUniqueFilename($fileName);
     }
     $data = ['filename' => $fileName, 'path' => config('asgard.media.config.files-path') . "{$fileName}", 'extension' => substr(strrchr($fileName, "."), 1), 'mimetype' => $file->getClientMimeType(), 'filesize' => $file->getFileInfo()->getSize(), 'folder_id' => 0];
     if (is_module_enabled('Site')) {
         $siteId = Site::id();
         $data['site_id'] = $siteId;
         $data['path'] = config('asgard.media.config.files-path') . '/' . Site::current()->slug . "/{$fileName}";
     }
     return $this->model->create($data);
 }
Пример #4
0
 /** @test */
 public function it_should_return_slugged_name_when_uppercase_extension_provided()
 {
     $expected = 'file-name.png';
     $name = FileHelper::slug('File Name.PNG');
     $this->assertEquals($expected, $name);
 }
Пример #5
0
 /** @test */
 public function it_should_return_slugged_name_with_extension()
 {
     $expected = 'file-name.png';
     $name = FileHelper::slug('File Name.png');
     $this->assertEquals($expected, $name);
 }