FileEntryController.php
2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Fileentry;
use Request;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\File;
use Illuminate\Http\Response;
class FileEntryController extends Controller {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$entries = Fileentry::all();
return view('fileentries.index', compact('entries'));
}
public function add() {
$file = Request::file('filefield');
$extension = $file->getClientOriginalExtension();
Storage::disk('local')->put($file->getFilename().'.'.$extension, File::get($file));
$entry = new Fileentry();
$entry->mime = $file->getClientMimeType();
$entry->original_filename = $file->getClientOriginalName();
$entry->filename = $file->getFilename().'.'.$extension;
$entry->save();
return redirect('fileentry');
}
public function getImage($folder, $filename){
//$entry = Fileentry::where('filename', '=', $filename)->firstOrFail();
$file = Storage::disk('public')->get($folder.'/'.$filename);
return (new Response($file, 200))
->header('Content-Type', 'image/jpeg');
}
public function getPDF($folder, $filename){
//$entry = Fileentry::where('filename', '=', $filename)->firstOrFail();
$file = Storage::disk('public')->get($folder.'/'.$filename);
return (new Response($file, 200))
->header('Content-Type','application/pdf');
}
public function get($filename){
$entry = Fileentry::where('filename', '=', $filename)->firstOrFail();
$file = Storage::disk('local')->get($entry->filename);
return (new Response($file, 200))
->header('Content-Type', $entry->mime);
}
public function getApi($json)
{
if($json == '1'){
$file = Storage::disk('public')->get('js/interface.js');
}elseif($json == '2'){
$file = Storage::disk('public')->get('js/interfaceGdrive.js');
}
return (new Response($file, 200))
->header('Content-Type', 'application/x-javascript');
}
}