Skip to content

Commit

Permalink
fix uploading to cloud storage
Browse files Browse the repository at this point in the history
  • Loading branch information
streamtw committed Dec 29, 2017
1 parent 19cefe9 commit a3dd20e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/Lfm.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public function input($key)
return $this->translateFromUtf8($this->request->input($key));
}

public function config($key)
{
return $this->config->get('lfm.' . $key);
}

/**
* Get only the file name.
*
Expand Down
6 changes: 5 additions & 1 deletion src/LfmFileRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public function move($new_lfm_path)

public function save($file, $new_filename)
{
File::move($file->getRealPath(), $this->path . '/' . $new_filename);
$dest_file_path = $this->path . '/' . $new_filename;

File::move($file->getRealPath(), $dest_file_path);

chmod($dest_file_path, config('lfm.create_file_mode', 0644));
}
}
17 changes: 13 additions & 4 deletions src/LfmPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,6 @@ private function saveFile($file, $new_filename)

$this->setName(null)->thumb(false)->storage->save($file, $new_filename);

chmod($this->setName($new_filename)->thumb(false)->path('absolute'), config('lfm.create_file_mode', 0644));

if ($should_create_thumbnail) {
$this->makeThumbnail($new_filename);
}
Expand All @@ -288,10 +286,21 @@ public function makeThumbnail($filename)
// create folder for thumbnails
$this->setName(null)->thumb(true)->createFolder();

$image_path = $this->thumb(false)->setName($filename)->path('storage');

$image_content = $this->storage->get($image_path);

$thumb_path = $this->thumb(true)->setName($filename)->path('absolute');

// generate cropped thumbnail
Image::make($this->thumb(false)->setName($filename)->path('absolute'))
$image = Image::make($image_content)
->fit(config('lfm.thumb_img_width', 200), config('lfm.thumb_img_height', 200))
->save($this->thumb(true)->setName($filename)->path('absolute'));
->save($thumb_path);

\Log::info($this->storage->rootPath());
\Log::info($thumb_path);

$this->setName(null)->thumb(true)->storage->save(new UploadedFile($thumb_path, $filename), $filename);
}

private function shouldCreateThumb($file)
Expand Down
4 changes: 3 additions & 1 deletion src/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,7 @@
});

if (app('\UniSharp\LaravelFilemanager\Lfm')->shouldSetStorageRoute()) {
Route::get('/' . config('lfm.images_folder_name') . '/{file_path}', $namespace . '\RedirectController@showFile')->where('file_path', '.*');
foreach (config('lfm.folder_categories') as $folder_category) {
Route::get('/' . $folder_category['folder_name'] . '/{file_path}', $namespace . '\RedirectController@showFile')->where('file_path', '.*');
}
}

0 comments on commit a3dd20e

Please sign in to comment.