Use Storage methods for asset/license files

This commit is contained in:
snipe 2018-07-25 09:48:50 -07:00
parent 2e92ef7d77
commit 63bf71b071
2 changed files with 11 additions and 6 deletions

View file

@ -8,6 +8,7 @@ use App\Http\Requests\AssetFileRequest;
use App\Models\Actionlog;
use App\Models\Asset;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Storage;
class AssetFilesController extends Controller
{
@ -29,14 +30,13 @@ class AssetFilesController extends Controller
$this->authorize('update', $asset);
$destinationPath = config('app.private_uploads').'/assets';
if ($request->hasFile('file')) {
foreach ($request->file('file') as $file) {
$extension = $file->getClientOriginalExtension();
$filename = 'hardware-'.$asset->id.'-'.str_random(8);
$filename .= '-'.str_slug(basename($file->getClientOriginalName(), '.'.$extension)).'.'.$extension;
$file->move($destinationPath, $filename);
$file->storeAs('storage/private_uploads/assets', $filename);
$asset->logUpload($filename, e($request->get('notes')));
}
return redirect()->back()->with('success', trans('admin/hardware/message.upload.success'));
@ -116,7 +116,9 @@ class AssetFilesController extends Controller
$log = Actionlog::find($fileId);
$full_filename = $destinationPath.'/'.$log->filename;
if (file_exists($full_filename)) {
unlink($destinationPath.'/'.$log->filename);
\Log::debug('Trying to delete '.$full_filename);
Storage::delete($full_filename);
//unlink($destinationPath.'/'.$log->filename);
}
$log->delete();
return redirect()->back()->with('success', trans('admin/hardware/message.deletefile.success'));

View file

@ -9,6 +9,7 @@ use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Illuminate\Support\Facades\Storage;
class LicenseFilesController extends Controller
{
@ -38,7 +39,8 @@ class LicenseFilesController extends Controller
foreach (Input::file('file') as $file) {
$extension = $file->getClientOriginalExtension();
$filename = 'license-'.$license->id.'-'.str_random(8).'-'.str_slug(basename($file->getClientOriginalName(), '.'.$extension)).'.'.$extension;
$upload_success = $file->move($destinationPath, $filename);
$upload_success = $file->storeAs('storage/private_uploads/licenses', $filename);
//Log the upload to the log
$license->logUpload($filename, e($request->input('notes')));
@ -81,7 +83,8 @@ class LicenseFilesController extends Controller
$log = Actionlog::find($fileId);
$full_filename = $destinationPath.'/'.$log->filename;
if (file_exists($full_filename)) {
unlink($destinationPath.'/'.$log->filename);
Storage::delete($full_filename);
// unlink($destinationPath.'/'.$log->filename);
}
$log->delete();
return redirect()->back()->with('success', trans('admin/licenses/message.deletefile.success'));