Skip to content

Commit

Permalink
Display uploaded files
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Feb 7, 2015
1 parent 6d0828b commit 3a9cb9b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
31 changes: 29 additions & 2 deletions app/controllers/admin/LicensesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Supplier;
use Validator;
use View;

use Response;

class LicensesController extends AdminController
{
Expand Down Expand Up @@ -711,7 +711,7 @@ public function postUpload($licenseId = null)


/**
* Upload the file to the server
* Delete the associated file
*
* @param int $assetId
* @return View
Expand Down Expand Up @@ -740,4 +740,31 @@ public function getDeleteFile($licenseId = null, $fileId = null)
return Redirect::route('licenses')->with('error', $error);
}
}



/**
* Display/download the uploaded file
*
* @param int $assetId
* @return View
**/
public function displayFile($licenseId = null, $fileId = null)
{

$license = License::find($licenseId);

// the license is valid
if (isset($license->id)) {
$log = Actionlog::find($fileId);
$file = $log->get_src();
return Response::download($file);
} else {
// Prepare the error message
$error = Lang::get('admin/licenses/message.does_not_exist', compact('id'));

// Redirect to the licence management page
return Redirect::route('licenses')->with('error', $error);
}
}
}
12 changes: 12 additions & 0 deletions app/models/Actionlog.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ public function userlog()
}


/**
* Check if the file exists, and if it does, force a download
**/
public function get_src() {

$file = app_path().'/private_uploads/'.$this->filename;
return $file;

}



/**
* Get the parent category name
*/
Expand Down
1 change: 1 addition & 0 deletions app/models/License.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function uploads()
->orderBy('created_at', 'desc');
}


/**
* Get admin user for this asset
*/
Expand Down
1 change: 1 addition & 0 deletions app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
Route::get('{licenseId}/view', array('as' => 'view/license', 'uses' => 'LicensesController@getView'));
Route::post('{licenseId}/upload', array('as' => 'upload/license', 'uses' => 'LicensesController@postUpload'));
Route::get('{licenseId}/deletefile/{fileId}', array('as' => 'delete/licensefile', 'uses' => 'LicensesController@getDeleteFile'));
Route::get('{licenseId}/showfile/{fileId}', array('as' => 'show/licensefile', 'uses' => 'LicensesController@displayFile'));
Route::get('/', array('as' => 'licenses', 'uses' => 'LicensesController@getIndex'));
});

Expand Down
7 changes: 5 additions & 2 deletions app/views/backend/licenses/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
<th class="col-md-5">@lang('admin/licenses/form.notes')</th>
<th class="col-md-5"><span class="line"></span>@lang('general.file_name')</th>
<th class="col-md-2"></th>
<th class="col-md-2"></th>
</tr>
</thead>
<tbody>
Expand All @@ -174,10 +175,12 @@
@if ($file->note) {{{ $file->note }}}
@endif
</td>

<td>
{{{ $file->filename }}}
</td>
<td>
@if ($file->filename)
<a href="{{{ $file->filename }}}">{{{ $file->filename }}}</a>
<a href="{{ route('show/licensefile', [$license->id, $file->id]) }}" class="btn btn-default">Download</a>
@endif
</td>
<td>
Expand Down

0 comments on commit 3a9cb9b

Please sign in to comment.