bb25ba4e by Jeff Balicki

f

1 parent 0130ec03
...@@ -21,6 +21,7 @@ use Imagick; ...@@ -21,6 +21,7 @@ use Imagick;
21 21
22 22
23 23
24
24 class ApiController extends Controller 25 class ApiController extends Controller
25 { 26 {
26 27
...@@ -43,7 +44,7 @@ class ApiController extends Controller ...@@ -43,7 +44,7 @@ class ApiController extends Controller
43 44
44 45
45 46
46 $storagePath = Storage::disk('local')->getDriver()->getAdapter()->getPathPrefix(); 47 $storagePath = Storage::disk('public')->getDriver()->getAdapter()->getPathPrefix();
47 $folder = str_replace(' ', '-', $json->pdf[0]->name); // Replaces all spaces with hyphens. 48 $folder = str_replace(' ', '-', $json->pdf[0]->name); // Replaces all spaces with hyphens.
48 $folder = preg_replace('/[^A-Za-z0-9\-]/', '', $folder); 49 $folder = preg_replace('/[^A-Za-z0-9\-]/', '', $folder);
49 50
...@@ -57,18 +58,24 @@ class ApiController extends Controller ...@@ -57,18 +58,24 @@ class ApiController extends Controller
57 58
58 $pdfLocation = $json->pdf[0]->pdfLocation; 59 $pdfLocation = $json->pdf[0]->pdfLocation;
59 $file = explode('/', $pdfLocation); 60 $file = explode('/', $pdfLocation);
61 $file = end($file);
60 $curl = new Curl(); 62 $curl = new Curl();
61 $curl->download($pdfLocation, $storagePath . $folder . '/' . end($file)); 63 $curl->download($pdfLocation, $storagePath . $folder . '/' . $file);
62 $curl->close(); 64 $curl->close();
65 $fileEntry = New FileEntryController();
66 // echo $storagePath . $folder . '/' . $file;
67 //$fileEntry->addfile( $folder . '/' . $file);
68
69
63 $im = new Imagick(); 70 $im = new Imagick();
64 $im->setResolution(300, 300); //set the resolution of the resulting jpg 71 $im->setResolution(300, 300); //set the resolution of the resulting jpg
65 if (! is_readable($storagePath . $folder . '/' . end($file))) { 72 if (! is_readable($storagePath . $folder . '/' . $file)) {
66 echo 'file not readable'; 73 echo 'file not readable';
67 exit(); 74 exit();
68 } 75 }
69 $im->readImage($storagePath . $folder . '/' . end($file)); //[0] for the first page 76 $im->readImage($storagePath . $folder . '/' . $file); //[0] for the first page
70 $im->setImageFormat('jpg'); 77 $im->setImageFormat('jpg');
71 $fileName = end($file); 78 $fileName = $file;
72 $fileName = explode('.', $fileName); 79 $fileName = explode('.', $fileName);
73 $im->writeImage($storagePath . $folder . '/' . $fileName[0].'.jpg'); 80 $im->writeImage($storagePath . $folder . '/' . $fileName[0].'.jpg');
74 81
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
3 use App\Http\Controllers\Controller; 3 use App\Http\Controllers\Controller;
4 use App\Fileentry; 4 use App\Fileentry;
5 use Request; 5 use Request;
6 6 use Illuminate\Support\Facades\Input;
7 use Illuminate\Support\Facades\Storage; 7 use Illuminate\Support\Facades\Storage;
8 use Illuminate\Support\Facades\File; 8 use Illuminate\Support\Facades\File;
9 use Illuminate\Http\Response; 9 use Illuminate\Http\Response;
...@@ -37,12 +37,13 @@ class FileEntryController extends Controller { ...@@ -37,12 +37,13 @@ class FileEntryController extends Controller {
37 return redirect('fileentry'); 37 return redirect('fileentry');
38 38
39 } 39 }
40 public function get($filename){
41 40
42 $entry = Fileentry::where('filename', '=', $filename)->firstOrFail(); 41 public function get($folder, $filename){
43 $file = Storage::disk('local')->get($entry->filename); 42
43 //$entry = Fileentry::where('filename', '=', $filename)->firstOrFail();
44 $file = Storage::disk('public')->get($folder.'/'.$filename);
44 45
45 return (new Response($file, 200)) 46 return (new Response($file, 200))
46 ->header('Content-Type', $entry->mime); 47 ->header('Content-Type', 'image/jpeg');
47 } 48 }
48 } 49 }
......
...@@ -30,7 +30,7 @@ Route::group(array('prefix' => 'api/v1'), function($json) ...@@ -30,7 +30,7 @@ Route::group(array('prefix' => 'api/v1'), function($json)
30 }); 30 });
31 31
32 Route::get('fileentry', 'FileEntryController@index'); 32 Route::get('fileentry', 'FileEntryController@index');
33 Route::get('fileentry/get/{filename}', [ 33 Route::get('fileentry/get/{folder}/{filename}', [
34 'as' => 'getentry', 'uses' => 'FileEntryController@get']); 34 'as' => 'getentry', 'uses' => 'FileEntryController@get']);
35 Route::post('fileentry/add',[ 35 Route::post('fileentry/add',[
36 'as' => 'addentry', 'uses' => 'FileEntryController@add']); 36 'as' => 'addentry', 'uses' => 'FileEntryController@add']);
......
...@@ -50,7 +50,7 @@ return [ ...@@ -50,7 +50,7 @@ return [
50 50
51 'public' => [ 51 'public' => [
52 'driver' => 'local', 52 'driver' => 'local',
53 'root' => storage_path('app/public'), 53 'root' => public_path()."/files",
54 'visibility' => 'public', 54 'visibility' => 'public',
55 ], 55 ],
56 56
......
No preview for this file type
No preview for this file type